Skip to main content
Version: Next

A element is a very important part of a UI library, It's what makes it possible.

Element is a type alias of Box<dyn ElementWidget>. It makes the code look cleaner.

ElementWidget

ElementWidget is a trait that defines the Elements and it's rendering / event updates.

Methods

render(&self, focused: bool) -> Option<RenderResult>

  • required
  • This function renders the element

event(&mut self, event: Event, document: &Document)

  • optional
  • This function updates the element when there is a event

event(&mut self, document: &mut Document)

  • optional
  • This function runs when the app first runs. It helps with element initialization after the rsx! stage.

ElementCore

ElementCore is a trait that will automatically be implemented by the osui_element::element proc-macro. All of it's functions are used by OSUI.

element proc-macro

This macro adds the essential fields and functions for a ElementCore structure.

use osui_element::element;
#[element]
#[derive(Default, Debug)]
struct MyElement {}

elem_fn proc-macro

This macro makes a function that returns a Box<T> of which T is the default of MyElement

use osui_element::{element, elem_fn};
#[element]
#[elem_fn]
#[derive(Default, Debug)]
struct MyElement {}
info

You can also define a function for the element manually:

pub fn my_element() -> Box<MyElement> {
Box::new(MyElement::default())
}