Skip to main content

Widget

Trait Widget 

Source
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 implements DrawTarget
  • COL - The pixel color type that implements PixelColor

§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§

Source

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.

Implementors§

Source§

impl<'a, DRAW, ID: WidgetId, T, COL> Widget<DRAW, COL> for StaticImage<'a, ID, T>
where COL: PixelColor, DRAW: DrawTarget<Color = COL>, T: ImageDrawable<Color = COL>,

Source§

impl<'a, DRAW: DrawTarget<Color = COL>, ID: WidgetId, COL: PixelColor> Widget<DRAW, COL> for StaticLine<'a, ID, COL, OriHorizontal>

Source§

impl<'a, DRAW: DrawTarget<Color = COL>, ID: WidgetId, COL: PixelColor> Widget<DRAW, COL> for StaticLine<'a, ID, COL, OriVertical>

Source§

impl<DRAW: DrawTarget<Color = COL>, ID: WidgetId, COL: PixelColor> Widget<DRAW, COL> for Background<ID>

Source§

impl<DRAW: DrawTarget<Color = COL>, ID: WidgetId, COL: PixelColor> Widget<DRAW, COL> for Bar<'_, ID, COL>

Source§

impl<DRAW: DrawTarget<Color = COL>, ID: WidgetId, COL: PixelColor> Widget<DRAW, COL> for Label<'_, ID, COL>

Source§

impl<DRAW: DrawTarget<Color = COL>, ID: WidgetId, COL: PixelColor> Widget<DRAW, COL> for ListBox<'_, ID, COL>

Source§

impl<DRAW: DrawTarget<Color = COL>, ID: WidgetId, COL: PixelColor> Widget<DRAW, COL> for PlainText<'_, ID, COL>