pub trait Component<S: State> {
// Required methods
fn get_widget(&mut self) -> &mut impl Widget<S>;
fn get_widget_id(&self) -> WidgetId;
// Provided method
fn build(self) -> ComponentAdapter<S, Self>
where Self: Sized { ... }
}Expand description
The core trait for all components.
A Component is composed out of an already existing Widget.
The advantage of using a component is that you can easily create your own widgets
with your own logic without handling rendering, updating and other things.
In order to make it usable, you’ll need to call Component::build on it,
to convert it into a real widget (more specifically the ComponentAdapter).
This is required to not confuse the compiler with overlapping traits.
Required Methods§
Sourcefn get_widget(&mut self) -> &mut impl Widget<S>
fn get_widget(&mut self) -> &mut impl Widget<S>
Returns a mutable reference to the inner Widget.
Sourcefn get_widget_id(&self) -> WidgetId
fn get_widget_id(&self) -> WidgetId
Get the ID of your component as a WidgetId.
Provided Methods§
Sourcefn build(self) -> ComponentAdapter<S, Self>where
Self: Sized,
fn build(self) -> ComponentAdapter<S, Self>where
Self: Sized,
Converts the component into a widget by wrapping it in a ComponentAdapter.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.