pub struct Application {
    pub view_models: ViewModelCollection,
    pub animations_delta_time: f32,
    /* private fields */
}
Expand description

Contains and orchestrates application layout, animations, interactions, etc.

See the application module for more information and examples.

Fields§

§view_models: ViewModelCollection§animations_delta_time: f32

The amount of time between the last update, used when calculating animation progress

Implementations§

source§

impl Application

source

pub fn setup<F>(&mut self, f: F)
where F: FnMut(&mut Application),

Setup the application with a given a setup function

We need to run the setup function for the application to register components and properties if we want to support serialization of the UI. We pass it a function that will do the actual registration.

Note: RAUI will work fine without running any setup if UI serialization is not required.

§Example
application.setup(setup /* the core setup function from the RAUI prelude */);

If you use crates like the raui_material crate you will want to call it’s setup function as well.

application.setup(raui_material::setup);
source

pub fn notifier(&self) -> ChangeNotifier

source

pub fn register_component(&mut self, type_name: &str, processor: FnWidget)

Register’s a component under a string name used when serializing the UI

This function is often used in setup functions for registering batches of components.

§Example
fn my_widget(ctx: WidgetContext) -> WidgetNode {
    todo!("make awesome widget");
}

fn setup_widgets(app: &mut Application) {
    app.register_component("my_widget", FnWidget::pointer(my_widget));
}

let mut application = Application::default();

application.setup(setup_widgets);
source

pub fn unregister_component(&mut self, type_name: &str)

Unregisters a component

See register_component

source

pub fn register_props<T>(&mut self, name: &str)
where T: 'static + Prefab + PropsData,

Register’s a property type under a string name used when serializing the UI

This function is often used in setup functions for registering batches of properties.

§Example
#[derive(PropsData, Debug, Default, Copy, Clone, Serialize, Deserialize)]
struct MyProp {
    awesome: bool,
}

fn setup_properties(app: &mut Application) {
    app.register_props::<MyProp>("MyProp");
}

let mut application = Application::default();

application.setup(setup_properties);
source

pub fn unregister_props(&mut self, name: &str)

Unregisters a property type

See register_props

source

pub fn serialize_props(&self, props: &Props) -> Result<Value, PrefabError>

Serialize the given Props to a PrefabValue

source

pub fn deserialize_props(&self, data: Value) -> Result<Props, PrefabError>

Deserialize Props from a PrefabValue

source

pub fn serialize_node( &self, data: &WidgetNode ) -> Result<Value, ApplicationError>

Serialize a WidgetNode to a PrefabValue

source

pub fn deserialize_node( &self, data: Value ) -> Result<WidgetNode, ApplicationError>

Deserialize a WidgetNode from a PrefabValue

source

pub fn last_invalidation_cause(&self) -> &InvalidationCause

Get the reason that the application state was last invalidated and caused to re-process

source

pub fn dirty(&self) -> &WidgetIdCommon

Return’s common root widget ID of widgets that has to be to be re-processed

source

pub fn mark_dirty(&mut self)

Force mark the application as needing to re-process its root

source

pub fn does_render_changed(&self) -> bool

source

pub fn tree(&self) -> &WidgetNode

Get the WidgetNode for the application tree

source

pub fn rendered_tree(&self) -> &WidgetUnit

Get the application widget tree rendered to raw WidgetUnit’s

source

pub fn layout_data(&self) -> &Layout

Get the application Layout data

source

pub fn has_layout_widget(&self, id: &WidgetId) -> bool

source

pub fn apply(&mut self, tree: impl Into<WidgetNode>)

Update the application widget tree

source

pub fn render<R, T, E>( &self, mapping: &CoordsMapping, renderer: &mut R ) -> Result<T, E>
where R: Renderer<T, E>,

Render the application

source

pub fn render_change<R, T, E>( &mut self, mapping: &CoordsMapping, renderer: &mut R ) -> Result<Option<T>, E>
where R: Renderer<T, E>,

Render the application, but only if something effecting the rendering has changed and it needs to be re-rendered

source

pub fn layout<L, E>( &mut self, mapping: &CoordsMapping, layout_engine: &mut L ) -> Result<(), E>
where L: LayoutEngine<E>,

Calculate application layout

source

pub fn layout_change<L, E>( &mut self, mapping: &CoordsMapping, layout_engine: &mut L ) -> Result<bool, E>
where L: LayoutEngine<E>,

Calculate application layout, but only if something effecting application layout has changed and the layout needs to be re-done

source

pub fn interact<I, R, E>(&mut self, interactions_engine: &mut I) -> Result<R, E>
where I: InteractionsEngine<R, E>,

Perform interactions on the application using the given interaction engine

source

pub fn send_message<T>(&mut self, id: &WidgetId, data: T)
where T: 'static + MessageData,

Send a message to the given widget

source

pub fn send_message_raw(&mut self, id: &WidgetId, data: Box<dyn MessageData>)

Send raw message data to the given widget

source

pub fn signals(&self) -> &[(WidgetId, Box<dyn MessageData>)]

Get the list of signals that have been sent by widgets

source

pub fn consume_signals(&mut self) -> Vec<(WidgetId, Box<dyn MessageData>)>

Get the list of signals that have been sent by widgets, consuming the current list so that further calls will not include previously sent signals

source

pub fn forced_process(&mut self) -> bool

process() application, even if no changes have been detected

source

pub fn process(&mut self) -> bool

Process the application.

§Example
const APP_DATA: &str = "app-data";
const COUNTER: &str = "counter";

/// Some sort of application data.
struct AppData {
    counter: ViewModelValue<i32>,
}

// Make view-model of that data.
let mut view_model = ViewModel::produce(|properties| {
    AppData {
        counter: ViewModelValue::new(0, properties.notifier(COUNTER)),
    }
});

// Get handle to view-model data for access on host side.
// This handle is valid as long as it's view-model is alive.
let mut app_data = view_model.lazy::<AppData>().unwrap();

let mut app = Application::default();
app.view_models.insert(APP_DATA.to_owned(), view_model);
// Do application stuff like interactions, layout, etc...

// Now we call `process` with our process context
app.process();

Now, in our components we can access the AppData from view-model through the widget’s WidgetContext.

fn my_component(mut ctx: WidgetContext) -> WidgetNode {
    let mut data = ctx
        .view_models
        .view_model_mut(APP_DATA)
        .unwrap()
        .write::<AppData>()
        .unwrap();
    *data.counter += 1;

    // widget stuff...
}

Trait Implementations§

source§

impl Default for Application

source§

fn default() -> Application

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Finalize for T

§

unsafe fn finalize_raw(data: *mut ())

Safety Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Initialize for T
where T: Default,

§

fn initialize(&mut self)

§

unsafe fn initialize_raw(data: *mut ())

Safety Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.