Module raui_core::data_binding[][src]

Expand description

Mechanism for integrating external data into the UI

DataBindings are a way to take data external to the RAUI UI and make sure that the UI is updated every time that data changes. DataBindings can be created and then added as Props to widgets.

The specifics of how to create DataBindings will probably vary depending on the RAUI renderer and integration crate you are using, but below we show an example of using the lower-level mechanisms to create a DataBinding directly.

Example

/// This is our external data type we want to bind into our RAUI UI
#[derive(Debug, Clone, Default)]
struct MyGlobalData {
    /// A simple counter value
    counter: i32,
}

// Our external data
let data = MyGlobalData {
    counter: 0,
};

// Create our application
let mut app = Application::new();

// Get the change notifier of the application
let change_notifier = app.change_notifier();

// Create a data binding for our global data bound to our app's change
// notifier.
let data_binding = DataBinding::new_bound(data, change_notifier);

// Create our app properties and add our data binding to it
let app_props = Props::new(data_binding);

// Create our widget tree, including our app component and it's props
let tree = widget! {
    (app_component: {app_props})
};

Structs

DataBinding

Wraps internal data and optionally notifies an Application of changes to it