use alloc::string::String;
use rlvgl_core::draw::draw_widget_bg;
use rlvgl_core::event::Event;
use rlvgl_core::renderer::Renderer;
use rlvgl_core::style::Style;
use rlvgl_core::widget::{Color, Rect, Widget};
pub struct Label {
bounds: Rect,
text: String,
pub style: Style,
pub text_color: Color,
}
impl Label {
pub fn new(text: impl Into<String>, bounds: Rect) -> Self {
Self {
bounds,
text: text.into(),
style: Style::default(),
text_color: Color(0, 0, 0, 255),
}
}
pub fn set_text(&mut self, text: impl Into<String>) {
self.text = text.into();
}
pub fn text(&self) -> &str {
&self.text
}
}
impl Widget for Label {
fn bounds(&self) -> Rect {
self.bounds
}
fn draw(&self, renderer: &mut dyn Renderer) {
draw_widget_bg(renderer, self.bounds, &self.style);
renderer.draw_text(
(self.bounds.x, self.bounds.y + self.bounds.height),
&self.text,
self.text_color.with_alpha(self.style.alpha),
);
}
fn handle_event(&mut self, _event: &Event) -> bool {
false
}
}