pub trait Widget: Any {
fn draw(
&self,
target: &mut Frame,
context: &DrawContext<'_>
) -> Result<NextUpdate, WidgetError>;
fn layout(&self, available_space: LogicalRect);
fn handle_event(&self, event: &Event);
fn children(&self, children: &mut Vec<Rc<dyn Widget>>);
fn placement(&self) -> WidgetPlacement;
fn visible(&self) -> bool;
fn set_valid_ref(&self, rendered_valid: RenderValidity);
fn before_draw(&self, _window: &Window) -> NextUpdate { ... }
}
Required Methods
sourcefn draw(
&self,
target: &mut Frame,
context: &DrawContext<'_>
) -> Result<NextUpdate, WidgetError>
fn draw(
&self,
target: &mut Frame,
context: &DrawContext<'_>
) -> Result<NextUpdate, WidgetError>
This function is called when the window is being re-rendered.
WARNING: The window may not be modified from this function. See the before_draw
function
to do that.
The widget is responsible for setting the correct transformation.
A widget should get information for finding a proper
transformation from its own drawn_bounds
field.
On success this furnction may return an instant indicating the time when it would like to be redrawn. Otherwise it can return Ok(None) to indicate that it should only be redrawn when a window event causes a change.
fn layout(&self, available_space: LogicalRect)
fn handle_event(&self, event: &Event)
sourcefn children(&self, children: &mut Vec<Rc<dyn Widget>>)
fn children(&self, children: &mut Vec<Rc<dyn Widget>>)
The implementer is expected to push
its children into the provided vector.
fn placement(&self) -> WidgetPlacement
fn visible(&self) -> bool
sourcefn set_valid_ref(&self, rendered_valid: RenderValidity)
fn set_valid_ref(&self, rendered_valid: RenderValidity)
Implementer of this trait must store the provided object
and call invalidate
on it whenever a change happens on them
that requires a re-draw.
Containers must call this function for all of their children immediately and pass a clone of the provided object.
Provided Methods
sourcefn before_draw(&self, _window: &Window) -> NextUpdate
fn before_draw(&self, _window: &Window) -> NextUpdate
This function is called before calling the draw function.
Widgets may use this function to mutate the window. This is however not allowed in the
draw
method.
Note that the Window
uses inner mutability so all window related functions take a
reference to a seemingly immutable window.