Trait Component

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

Source

fn get_widget(&mut self) -> &mut impl Widget<S>

Returns a mutable reference to the inner Widget.

Source

fn get_widget_id(&self) -> WidgetId

Get the ID of your component as a WidgetId.

Provided Methods§

Source

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.

Implementors§