eg-seven-segment

Crates.ioeg-seven-segment
lib.rseg-seven-segment
version0.2.0
sourcesrc
created_at2022-03-27 17:25:32.154884
updated_at2023-09-28 16:03:13.323388
descriptionSeven-segment displays for embedded-graphics
homepage
repositoryhttps://github.com/embedded-graphics/eg-seven-segment
max_upload_size
id557350
size117,126
Ralf Fuest (rfuest)

documentation

README

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.

Commit count: 16

cargo fmt