Skip to content

Seven segment font for embedded-graphics

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

embedded-graphics/eg-seven-segment

Repository files navigation

eg-seven-segment

CI Crates.io Docs.rs embedded-graphics on Matrix

eg-seven-segment is a seven-segment display text renderer for use with embedded-graphics. It can be used to display virtual seven-segment displays on any embedded-graphics DrawTarget. The appearance of the drawn digits can be configured to achieve a wide variety of styles.

eg-seven-segment example

Examples

The most convenient way to use this crate is by using the SevenSegmentStyle as a character style for an embedded-graphics Text:

use embedded_graphics::{prelude::*, text::Text, pixelcolor::Rgb888};
use eg_seven_segment::SevenSegmentStyleBuilder;

// Define a new style.
let style = SevenSegmentStyleBuilder::new()
    .digit_size(Size::new(10, 20)) // digits are 10x20 pixels
    .digit_spacing(5)              // 5px spacing between digits
    .segment_width(5)              // 5px wide segments
    .segment_color(Rgb888::GREEN)  // active segments are green
    .build();

// Use the style to draw text to a embedded-graphics `DrawTarget`.
Text::new("12:42", Point::new(5, 25), style).draw(&mut display)?;

Individual digits can also be drawn by using the Digit drawable:

use embedded_graphics::{prelude::*, text::Text, pixelcolor::Rgb888};
use eg_seven_segment::{SevenSegmentStyleBuilder, Digit, Segments};

// Define a new style.
let style = SevenSegmentStyleBuilder::new()
    .digit_size(Size::new(10, 20)) // digits are 10x20 pixels
    .digit_spacing(5)              // 5px spacing between digits
    .segment_width(5)              // 5px wide segments
    .segment_color(Rgb888::GREEN)  // active segments are green
    .build();

// Draw digit with active segment A at the origin.
let next = Digit::new(Segments::A, Point::zero())
    .into_styled(style)
    .draw(&mut display)?;

// Draw `0` digit the the right of the previous digit.
Digit::new('0'.try_into().unwrap(), next)
    .into_styled(style)
    .draw(&mut display)?;

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Seven segment font for embedded-graphics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published