[][src]Trait orbtk::prelude::Template

pub trait Template {
    fn template(self, _id: Entity, _context: &mut BuildContext<'_>) -> Self { ... }
fn render_object(&self) -> Box<dyn RenderObject + 'static> { ... }
fn layout(&self) -> Box<dyn Layout + 'static> { ... } }

The Template trait defines the template of a particular type of a widget.

A widget's Template consists three type of objects:

  • default values of its properties, children, handlers
  • a render object
  • a layout object

Provided methods

fn template(self, _id: Entity, _context: &mut BuildContext<'_>) -> Self

Builds the template of the widget and returns it.

Arguments

  • _id: The id (Entity) of the instantiated widget in the Entity Store
  • _context: The BuildContext used to build and instantiate new widgets

Example

Define a widget called MyWidget with min, max and val properties with type of usize, and then set default values and add a TextBlock child.

widget!(MyWidget {
    min: usize,
    max: usize,
    val: usize
});

impl Template for MyWidget {
    fn template(self, _id: Entity, context: &mut BuildContext) -> Self {
        self.name("MyWidget")
            .min(100)
            .max(1000)
            .val(500)
            .child(TextBlock::new().text("Set a value!").build(context))
    }

    fn render_object(&self) -> Box<dyn RenderObject> {
        Box::new(RectangleRenderObject)
    }

    fn layout(&self) -> Box<dyn Layout> {
       Box::new(AbsoluteLayout)
    }
}

fn render_object(&self) -> Box<dyn RenderObject + 'static>

Returns a pointer to a heap allocated object which specifies how the widget should be drawn on the canvas. For the list of available render objects, see the [render_object] module.

fn layout(&self) -> Box<dyn Layout + 'static>

Returns a pointer to a heap allocated object which specifies the way in which the widget are arranged or laid out on the canvas. For the list of available layout objects, see the [layout] module.

Loading content...

Implementors

impl Template for FocusBehavior[src]

impl Template for MouseBehavior[src]

impl Template for SelectionBehavior[src]

impl Template for TextBehavior[src]

impl Template for Button[src]

impl Template for Canvas[src]

impl Template for CheckBox[src]

impl Template for ComboBox[src]

impl Template for ComboBoxItem[src]

impl Template for Container[src]

impl Template for Cursor[src]

impl Template for FontIconBlock[src]

impl Template for Grid[src]

impl Template for ImageWidget[src]

impl Template for ItemsWidget[src]

impl Template for ListView[src]

impl Template for ListViewItem[src]

impl Template for NumericBox[src]

impl Template for Overlay[src]

impl Template for Popup[src]

impl Template for ProgressBar[src]

impl Template for ScrollBar[src]

impl Template for ScrollIndicator[src]

impl Template for ScrollViewer[src]

impl Template for Slider[src]

impl Template for Stack[src]

impl Template for Switch[src]

impl Template for TabHeader[src]

impl Template for TabWidget[src]

impl Template for TextBlock[src]

impl Template for TextBox[src]

impl Template for ToggleButton[src]

impl Template for Window[src]

Loading content...