rlvgl_core/
widget.rs

1use crate::event::Event;
2use crate::renderer::Renderer;
3
4/// Rectangle bounds of a widget.
5///
6/// Coordinates are relative to the parent widget. Width and height are signed
7/// integers to simplify layout calculations.
8#[derive(Debug, Clone, Copy)]
9pub struct Rect {
10    pub x: i32,
11    pub y: i32,
12    pub width: i32,
13    pub height: i32,
14}
15
16/// RGB color used by the renderer.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub struct Color(pub u8, pub u8, pub u8);
19
20/// Base trait implemented by all widgets.
21///
22/// A widget is expected to provide its bounds, draw itself using a
23/// [`Renderer`], and optionally handle input [`Event`]s.
24pub trait Widget {
25    fn bounds(&self) -> Rect;
26    fn draw(&self, renderer: &mut dyn Renderer);
27    /// Handle an event and return `true` if it was consumed.
28    ///
29    /// The default implementation for most widgets will simply ignore the
30    /// event and return `false`.
31    fn handle_event(&mut self, event: &Event) -> bool;
32}