An open API service indexing awesome lists of open source software.

https://github.com/embedded-graphics/eg-seven-segment

Seven segment font for embedded-graphics
https://github.com/embedded-graphics/eg-seven-segment

Last synced: 10 months ago
JSON representation

Seven segment font for embedded-graphics

Awesome Lists containing this project

README

          

# eg-seven-segment

[![CI](https://github.com/embedded-graphics/eg-seven-segment/actions/workflows/rust.yml/badge.svg)](https://github.com/embedded-graphics/eg-seven-segment/actions/workflows/rust.yml)
[![Crates.io](https://img.shields.io/crates/v/eg-seven-segment.svg)](https://crates.io/crates/eg-seven-segment)
[![Docs.rs](https://docs.rs/eg-seven-segment/badge.svg)](https://docs.rs/eg-seven-segment)
[![embedded-graphics on Matrix](https://img.shields.io/matrix/rust-embedded-graphics:matrix.org)](https://matrix.to/#/#rust-embedded-graphics:matrix.org)

`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][img1]

## Examples

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

```rust
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:

```rust
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)?;
```

[`embedded-graphics`]: https://docs.rs/embedded-graphics
[`Text`]: https://docs.rs/embedded-graphics/latest/embeddded_graphics/text/struct.Text.html
[`DrawTarget`]: https://docs.rs/embedded-graphics/latest/embeddded_graphics/draw_target/struct.DrawTarget.html
[`SevenSegmentStyle`]: https://docs.rs/eg-seven-segment/latest/eg_seven_segment/struct.SevenSegmentStyle.html
[`Digit`]: https://docs.rs/eg-seven-segment/latest/eg_seven_segment/struct.Digit.html
[img1]: assets/styles.png

[`embedded-graphics`]: embedded_graphics
[`Text`]: embedded_graphics::text::Text
[`DrawTarget`]: embedded_graphics::draw_target::DrawTarget

## License

Licensed under either of

- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

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.