Skip to main content

Widget

Trait Widget 

Source
pub trait Widget: 'static {
    // Required method
    fn into_element(self: Box<Self>) -> Element;
}
Expand description

Something that can be placed in a window: one of this crate’s widgets, or a type of your own that is made of them.

To make your own, return another widget’s element. Calling into_element on a container describes everything inside it too, so the result is plain data:

use crabshell_ui::{Element, Row, Text, Widget};

struct Greeting;

impl Widget for Greeting {
    fn into_element(self: Box<Self>) -> Element {
        Box::new(Row::new().gap(4).child(Text::new("hello")).child(Text::new("world")))
            .into_element()
    }
}

Required Methods§

Source

fn into_element(self: Box<Self>) -> Element

Turns the description, and everything inside it, into the element the window builds nodes from. It runs when the window is created or a list item first appears, before the window’s tree is touched and without recording what it reads, so it only describes.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§