Crates.io | eg-seven-segment |
lib.rs | eg-seven-segment |
version | 0.2.0 |
source | src |
created_at | 2022-03-27 17:25:32.154884 |
updated_at | 2023-09-28 16:03:13.323388 |
description | Seven-segment displays for embedded-graphics |
homepage | |
repository | https://github.com/embedded-graphics/eg-seven-segment |
max_upload_size | |
id | 557350 |
size | 117,126 |
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.
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)?;
Licensed under either of
at your option.
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.