1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! Pixel based fonts

mod font12x16;
mod font6x12;
mod font6x8;
mod font8x16;

pub use self::font12x16::Font12x16;
pub use self::font6x12::Font6x12;
pub use self::font6x8::Font6x8;
pub use self::font8x16::Font8x16;

/// Common methods for all fonts
pub trait Font<'a> {
    /// Render a string in the implementing font's typeface.
    ///
    /// ```rust
    /// # use embedded_graphics::fonts::{Font, Font6x8};
    /// # use embedded_graphics::transform::Transform;
    /// # use embedded_graphics::drawable::Pixel;
    /// #
    /// # struct Display {}
    /// # impl Display {
    /// #     pub fn draw<T>(&self, item_pixels: T) -> Result<(), ()>
    /// #     where
    /// #         T: Iterator<Item = Pixel>,
    /// #     {
    /// #         Ok(())
    /// #     }
    /// # }
    ///
    /// fn main() {
    ///     let disp = Display {};
    ///     // Render a string with a 8bit color
    ///     let text = Font6x8::render_str("Hello world", 1);  
    ///
    ///     disp.draw(text.into_iter());
    /// }
    /// ```
    fn render_str(chars: &'a str, color: u8) -> Self;
}