pub trait Widget<DRAW: DrawTarget<Color = COL>, COL: PixelColor> {
// Required method
fn draw(&mut self, ui: &mut Ui<'_, DRAW, COL>) -> GuiResult<Response>;
}Expand description
Trait for drawable UI widgets.
This trait defines the interface that all widgets must implement to be rendered within the UI system. Widgets are responsible for their own rendering and can return responses to indicate the result of operations.
§Type Parameters
DRAW- The draw target type that implementsDrawTargetCOL- The pixel color type that implementsPixelColor
§Example
use matrix_gui::prelude::*;
struct MyWidget;
impl<DRAW, COL> Widget<DRAW, COL> for MyWidget
where
DRAW: DrawTarget<Color = COL>,
COL: PixelColor,
{
fn draw(&mut self, ui: &mut Ui<DRAW, COL>) -> GuiResult<Response> {
// Widget rendering logic here
Ok(Response::Idle)
}
}Required Methods§
Sourcefn draw(&mut self, ui: &mut Ui<'_, DRAW, COL>) -> GuiResult<Response>
fn draw(&mut self, ui: &mut Ui<'_, DRAW, COL>) -> GuiResult<Response>
Draws the widget to the UI context.
This method is called by the UI system to render the widget. The widget can use the provided UI context to access drawing primitives, style information, and handle interactions.
§Arguments
ui- Mutable reference to the UI context.
§Returns
A GuiResult<Response> indicating the result of the draw operation.
§Errors
Returns GuiError::DrawError if drawing fails.