Trait pixel_widgets::component::Component[][src]

pub trait Component {
    type State: 'static + Any + Send + Sync;
    type Message: 'static;
    type Output: 'static;
    fn mount(&self) -> Self::State;
fn view<'a>(&'a self, state: &'a Self::State) -> Node<'a, Self::Message>; fn update(
        &self,
        _message: Self::Message,
        _state: State<'_, Self::State>,
        _context: Context<'_, Self::Message, Self::Output>
    ) { ... }
fn style() -> StyleBuilder { ... }
fn into_node<'a>(self) -> Node<'a, Self::Output>
    where
        Self: 'a + Sized
, { ... }
fn class<'a>(self, class: &'a str) -> Node<'a, Self::Output>
    where
        Self: 'a + Sized
, { ... }
fn key<'a, K>(self, key: K) -> Node<'a, Self::Output>
    where
        Self: 'a + Sized,
        K: Hash
, { ... } }
Expand description

A re-usable component for defining a fragment of a user interface. Components are the main building block for user interfaces in pixel-widgets.

The examples in this repository all implement some kind of Component, check them out if you just want to read some code.

Associated Types

Mutable state associated with this Component.

The message type this Component will receive from it’s view.

The message type this Component submits to its parent.

Required methods

Create a new State for the Component. This will be called only once when the Component is first created.

Generate the view for the Component. This will be called just in time before ui rendering. When the Component is updated, the view will be invalidated and the runtime will have to call this function again.

Provided methods

Update the Component state in response to the message. Asynchronous operations can be submitted to the context, which will result in more update calls in the future. Messages for the parent Component or root can also be submitted through the context.

Returns a StyleBuilder with styling information scoped to this component. This method will be called when you call StyleBuilder::component() when building your style.

Converts the component into a Node. This is used by the library to instantiate the component in a user interface.

Converts the component into a Node and sets a style class to it.

Converts the component into a Node and sets a custom key to it.

Implementors