use embedded_graphics::text::renderer::{CharacterStyle, TextRenderer};
use embedded_text::{TextBox, style::TextBoxStyle};
use crate::geometry::Rect;
pub fn text_box<'a, S>(content: &'a str, area: Rect, character_style: S) -> TextBox<'a, S>
where
S: TextRenderer + CharacterStyle,
{
TextBox::new(content, area.into(), character_style)
}
pub fn text_box_with_style<'a, S>(
content: &'a str,
area: Rect,
character_style: S,
style: TextBoxStyle,
) -> TextBox<'a, S>
where
S: TextRenderer + CharacterStyle,
{
TextBox::with_textbox_style(content, area.into(), character_style, style)
}
#[cfg(test)]
mod tests {
use super::*;
use embedded_graphics::{
mono_font::{MonoTextStyle, ascii::FONT_6X10},
pixelcolor::{Rgb565, RgbColor},
};
#[test]
fn builds_text_box_over_rect() {
let character_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
let area = Rect::new(2, 3, 96, 32);
let text_box = text_box("Hello", area, character_style);
assert_eq!(text_box.bounds.top_left.x, 2);
assert_eq!(text_box.bounds.top_left.y, 3);
assert_eq!(text_box.bounds.size.width, 96);
assert_eq!(text_box.bounds.size.height, 32);
}
}