pub trait Widget<C, M>where
C: PixelColor,
M: Clone,{
Show 16 methods
// Required methods
fn measure(&mut self, constraints: Constraints) -> Size;
fn arrange(&mut self, rect: Rectangle);
fn rect(&self) -> Rectangle;
fn handle_touch(&mut self, point: Point, phase: TouchPhase) -> Option<M>;
fn draw<'t>(
&self,
renderer: &mut dyn Renderer<C>,
theme: &Theme<'t, C>,
) -> Result<(), RenderError>;
// Provided methods
fn preferred_size(&self) -> (Length, Length) { ... }
fn mark_pressed(&mut self, point: Point) { ... }
fn widget_id(&self) -> Option<WidgetId> { ... }
fn is_focusable(&self) -> bool { ... }
fn collect_focusable(&self, out: &mut Vec<WidgetId>) { ... }
fn sync_focus(&mut self, focused: Option<WidgetId>) { ... }
fn handle_action(&mut self, action: UiAction) -> Option<M> { ... }
fn route_action(&mut self, target: WidgetId, action: UiAction) -> Option<M> { ... }
fn navigate_focus(
&self,
target: WidgetId,
action: UiAction,
) -> Option<WidgetId> { ... }
fn focus_rect(&self, target: WidgetId) -> Option<Rectangle> { ... }
fn focus_at(&self, point: Point) -> Option<WidgetId> { ... }
}Expand description
Object-safe widget contract.
Required Methods§
Sourcefn measure(&mut self, constraints: Constraints) -> Size
fn measure(&mut self, constraints: Constraints) -> Size
Report the size this widget wants within constraints.
Sourcefn arrange(&mut self, rect: Rectangle)
fn arrange(&mut self, rect: Rectangle)
Commit the final rectangle, recursively arranging any children.
Sourcefn handle_touch(&mut self, point: Point, phase: TouchPhase) -> Option<M>
fn handle_touch(&mut self, point: Point, phase: TouchPhase) -> Option<M>
Dispatch a touch event. Returns a message if consumed.
Provided Methods§
Sourcefn preferred_size(&self) -> (Length, Length)
fn preferred_size(&self) -> (Length, Length)
Per-axis sizing intent set via .width(...) / .height(...).
Containers consult this during layout to allocate fixed slots,
query intrinsic sizes, and split residual space among
Fill / FillPortion children. Default is Length::Fill on
both axes.
Sourcefn mark_pressed(&mut self, point: Point)
fn mark_pressed(&mut self, point: Point)
Set this widget’s pressed flag if point hits. No message emit.
Containers forward to children. Default no-op.
Sourcefn is_focusable(&self) -> bool
fn is_focusable(&self) -> bool
True if this widget should appear in focus traversal.
Sourcefn collect_focusable(&self, out: &mut Vec<WidgetId>)
fn collect_focusable(&self, out: &mut Vec<WidgetId>)
Append focusable widget ids in traversal order.
Sourcefn sync_focus(&mut self, focused: Option<WidgetId>)
fn sync_focus(&mut self, focused: Option<WidgetId>)
Synchronize focused state against the runtime’s currently-focused id.
Sourcefn handle_action(&mut self, action: UiAction) -> Option<M>
fn handle_action(&mut self, action: UiAction) -> Option<M>
Handle a semantic action directed at this widget.
Sourcefn route_action(&mut self, target: WidgetId, action: UiAction) -> Option<M>
fn route_action(&mut self, target: WidgetId, action: UiAction) -> Option<M>
Route a semantic action to the widget with id target.
Request a focus movement relative to target for directional actions.
Sourcefn focus_rect(&self, target: WidgetId) -> Option<Rectangle>
fn focus_rect(&self, target: WidgetId) -> Option<Rectangle>
Rectangle currently occupied by the focusable target, if any.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".