Skip to main content

AppData

Trait AppData 

Source
pub trait AppData: 'static {
    // Required method
    fn handle_message(&mut self, messages: &mut impl ReadMessage);

    // Provided methods
    fn resumed(&mut self) { ... }
    fn suspended(&mut self) { ... }
    fn memory_warning(&mut self) { ... }
}
Expand description

Application state

Kas allows application state to be stored both in the widget tree (in Adapt nodes and user-defined widgets) and by the application root (shared across windows). This trait must be implemented by the latter.

When no top-level data is required, use () which implements this trait.

TODO: should we pass some type of interface to the runner to these methods? We could pass a &mut dyn RunnerT easily, but that trait is not public.

Required Methods§

Source

fn handle_message(&mut self, messages: &mut impl ReadMessage)

Handle a message

This is the last message handler. If, traversing the widget tree (see kas::event module doc), the message stack is not empty, this method is called repeatedly until either the message stack is empty or the last call did not remove a message from the stack.

If any message is pushed or popped, widgets will be updated on all windows.

Unhandled messages will result in warnings in the log.

Provided Methods§

Source

fn resumed(&mut self)

Application is being resumed

This method is called on application start on all platforms. It is also called when an application is made active again after being suspended.

Source

fn suspended(&mut self)

Application is being suspended

The application should ensure any important state is saved.

This method is called when the application has been suspended or is about to exit (on Android/iOS/Web platforms, the application may resume after this method is called; on other platforms this probably indicates imminent closure). Widget state may still exist, but is not live (widgets will not process events or messages).

Source

fn memory_warning(&mut self)

Memory warning

Some platforms warn applications when available memory is low. Applies to: Android, iOS.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl AppData for ()

Source§

fn handle_message(&mut self, _: &mut impl ReadMessage)

Source§

fn suspended(&mut self)

Implementors§