pub trait Widget<M>: Any {
// Required methods
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
// Provided methods
fn set_attribute(&mut self, name: &str, value: &str) -> bool { ... }
fn axis(&self) -> Option<Axis> { ... }
fn measure(&self, fonts: &dyn Fonts, style: &ComputedStyle) -> Size { ... }
fn state(&self) -> ElementState { ... }
fn focusable(&self) -> bool { ... }
fn event(&mut self, cx: &mut EventCx<'_, M>, event: &Event) -> bool { ... }
fn paint(
&self,
renderer: &mut dyn Renderer,
cx: &PaintCx<'_>,
content: Rect,
) { ... }
}Expand description
What an element does: how it measures, reacts to input and paints.
Composition is declarative (the ui! macro builds a tree of
elements) but behaviour is imperative: a widget is a plain struct with
methods, and you can reach it through
Ui::widget_mut to change it.
The framework draws backgrounds and borders from the computed style and
lays children out; a widget only paints its own content and handles
events aimed at it. Every method has a default, so a container is an
empty impl plus axis.
Required Methods§
Provided Methods§
Sourcefn set_attribute(&mut self, name: &str, value: &str) -> bool
fn set_attribute(&mut self, name: &str, value: &str) -> bool
Takes an attribute from the element description, returning false
for one the widget does not know. id, class, style, grow,
align, disabled, shortcut and state never reach here.
Sourcefn axis(&self) -> Option<Axis>
fn axis(&self) -> Option<Axis>
Some for a container: the direction it lays its children out in.
Sourcefn measure(&self, fonts: &dyn Fonts, style: &ComputedStyle) -> Size
fn measure(&self, fonts: &dyn Fonts, style: &ComputedStyle) -> Size
The natural size of the widget’s own content, without padding or border. Containers are measured from their children instead.
Sourcefn state(&self) -> ElementState
fn state(&self) -> ElementState
State the widget owns, such as CHECKED, merged into the element’s
state for styling.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".