pub struct Ui<'a, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,{ /* private fields */ }Expand description
Main UI context for managing widgets, drawing, and interactions.
This struct is the central hub for all UI operations. It manages the draw target, widget states, styling, interactions, and focus management. All widgets are rendered through this context.
§Type Parameters
'a- Lifetime of the borrowed resourcesDRAW- The draw target type implementingDrawTargetCOL- The pixel color type implementingPixelColor
§Example
use matrix_gui::prelude::*;
use embedded_graphics::primitives::Rectangle;
// Create UI context with custom bounds
let bounds = Rectangle::new(Point::new(0, 0), Size::new(320, 240));
let mut ui = Ui::new(&mut display, bounds, &widget_states, &style);
// Or create fullscreen UI
let mut ui = Ui::new_fullscreen(&mut display, &widget_states, &style);Implementations§
Source§impl<DRAW, COL> Ui<'_, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
impl<DRAW, COL> Ui<'_, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
Sourcepub const fn get_screen_width(&self) -> u32
pub const fn get_screen_width(&self) -> u32
Sourcepub const fn get_screen_height(&self) -> u32
pub const fn get_screen_height(&self) -> u32
Sourcepub const fn get_screen_bounds(&self) -> Rectangle
pub const fn get_screen_bounds(&self) -> Rectangle
Source§impl<'a, COL, DRAW> Ui<'a, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
impl<'a, COL, DRAW> Ui<'a, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
Sourcepub fn new(
drawable: &'a mut DRAW,
bounds: Rectangle,
widget_states: &'a WidgetStates<'a>,
style: &'a Style<COL>,
) -> Self
pub fn new( drawable: &'a mut DRAW, bounds: Rectangle, widget_states: &'a WidgetStates<'a>, style: &'a Style<COL>, ) -> Self
Sourcepub fn new_fullscreen(
drawable: &'a mut DRAW,
widget_states: &'a WidgetStates<'a>,
style: &'a Style<COL>,
) -> Self
pub fn new_fullscreen( drawable: &'a mut DRAW, widget_states: &'a WidgetStates<'a>, style: &'a Style<COL>, ) -> Self
Creates a new UI context covering the entire draw target.
This is a convenience method that automatically determines the bounds from the draw target’s bounding box.
§Arguments
drawable- Mutable reference to the draw target.widget_states- Reference to the widget state storage.style- Reference to the styling configuration.
§Returns
A new Ui instance with bounds covering the entire draw target.
Sourcepub fn lazy_draw<F, ID: WidgetId>(&mut self, id: ID, f: F) -> Response
pub fn lazy_draw<F, ID: WidgetId>(&mut self, id: ID, f: F) -> Response
Conditionally draws a widget based on its redraw state.
This method only calls the drawing closure if the widget needs to be redrawn (based on its state). This is useful for optimizing rendering performance by avoiding unnecessary redraws.
§Type Parameters
ID- The widget ID type implementingWidgetIdF- The closure type that performs the drawing
§Arguments
id- The widget’s identifier.f- A closure that performs the drawing operation.
§Returns
The response from the drawing closure, or Response::Idle if no redraw was needed.
Source§impl<COL, DRAW> Ui<'_, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
impl<COL, DRAW> Ui<'_, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
Sourcepub const fn cleared(&self) -> bool
pub const fn cleared(&self) -> bool
Returns whether the background has been cleared.
§Returns
true if the background has been cleared, false otherwise.
Sourcepub fn clear_area(&mut self, area: &Rectangle) -> GuiResult<()>
pub fn clear_area(&mut self, area: &Rectangle) -> GuiResult<()>
Clears the specified area with the background color.
This method fills the given rectangle with the background color from the current style. If the background has already been cleared and the debug-color feature is not enabled, this method returns early.
§Arguments
area- The rectangle to clear.
§Returns
Ok(()) if clearing succeeds, Err(GuiError) otherwise.
Sourcepub fn clear_area_raw(&mut self, area: &Rectangle, color: COL) -> GuiResult<()>
pub fn clear_area_raw(&mut self, area: &Rectangle, color: COL) -> GuiResult<()>
Clears the specified area with a custom color.
This method fills the given rectangle with the specified color.
It uses either the standard StyledDrawable trait or the optimized
fill-rect feature if enabled.
§Arguments
area- The rectangle to clear.color- The color to fill the area with.
§Returns
Ok(()) if clearing succeeds, Err(GuiError::DrawError) otherwise.
Sourcepub fn clear_background(&mut self) -> GuiResult<()>
pub fn clear_background(&mut self) -> GuiResult<()>
Clears the entire background area.
This method fills the entire UI bounds with the background color
from the current style and sets the cleared flag to true.
§Returns
Ok(()) if clearing succeeds, Err(GuiError) otherwise.
Source§impl<'a, COL, DRAW> Ui<'a, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
impl<'a, COL, DRAW> Ui<'a, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
Source§impl<'a, COL, DRAW> Ui<'a, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
impl<'a, COL, DRAW> Ui<'a, DRAW, COL>where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
Sourcepub fn get_widget_state<ID: WidgetId>(
&self,
widget_id: ID,
) -> GuiResult<&RenderState>
pub fn get_widget_state<ID: WidgetId>( &self, widget_id: ID, ) -> GuiResult<&RenderState>
Retrieves the render state for a widget.
This method returns a reference to the render state for the widget with the specified ID. The render state contains information about whether the widget needs to be redrawn.
§Type Parameters
ID- The widget ID type implementingWidgetId
§Arguments
widget_id- The identifier of the widget.
§Returns
A reference to the RenderState if the widget exists,
Err(GuiError::InvalidWidgetId) otherwise.
Sourcepub fn force_redraw<ID: WidgetId>(&self, widget_id: ID)
pub fn force_redraw<ID: WidgetId>(&self, widget_id: ID)
Sourcepub fn force_redraw_all(&self)
pub fn force_redraw_all(&self)
Forces all widgets to be redrawn on the next frame.
This method marks all widgets as needing to be redrawn, regardless of their current state. This is useful for refreshing the entire UI.