This repository has been archived on 2026-08-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
donglora/vendor/embedded-graphics/tests/text_renderer_generic.rs
T
swaitsandClaude Opus 4.6 3102fc747a feat: add display UI with splash screen, dashboard, and RSSI sparkline
Implement full SSD1306 OLED display support:
- Splash screen on boot (1.5s) with project name, version, board
- Dashboard showing radio state, config, counters, RSSI/SNR
- RSSI history sparkline (64-sample ring buffer, 2px-wide bars)
- DisplayOn/DisplayOff host commands routed via dedicated channel
- Pure render functions against generic DrawTarget (no hardware coupling)
- Display on/off control bypasses radio task entirely

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:54 -06:00

84 lines
1.8 KiB
Rust

use embedded_graphics::{
mock_display::MockDisplay,
pixelcolor::Rgb888,
prelude::*,
primitives::Rectangle,
text::{
renderer::{TextMetrics, TextRenderer},
Baseline, Text,
},
};
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct GenericTextStyle<C>(C);
impl<C: PixelColor> TextRenderer for GenericTextStyle<C> {
type Color = C;
fn draw_string<D>(
&self,
text: &str,
position: Point,
baseline: Baseline,
target: &mut D,
) -> Result<Point, D::Error>
where
D: DrawTarget<Color = Self::Color>,
{
let metrics = self.measure_string(text, position, baseline);
target.fill_solid(&metrics.bounding_box, self.0)?;
Ok(metrics.next_position)
}
fn draw_whitespace<D>(
&self,
_width: u32,
_position: Point,
_baseline: Baseline,
_target: &mut D,
) -> Result<Point, D::Error>
where
D: DrawTarget<Color = Self::Color>,
{
todo!()
}
fn measure_string(&self, text: &str, position: Point, _baseline: Baseline) -> TextMetrics {
// TODO: use baseline
let width = text.len() as u32 * 4;
TextMetrics {
bounding_box: Rectangle::new(position, Size::new(width, 4)),
next_position: position + Size::new(width, 0),
}
}
fn line_height(&self) -> u32 {
5
}
}
#[test]
fn generic_text_renderer() {
let mut target = MockDisplay::new();
Text::new("ab\nc", Point::zero(), GenericTextStyle(Rgb888::RED))
.draw(&mut target)
.unwrap();
target.assert_pattern(&[
"RRRRRRRR", //
"RRRRRRRR", //
"RRRRRRRR", //
"RRRRRRRR", //
" ", //
"RRRR ", //
"RRRR ", //
"RRRR ", //
"RRRR ", //
]);
}