logo
pub trait Sandbox {
    type Message: Debug + Send;

    fn new() -> Self;
    fn title(&self) -> String;
    fn update(&mut self, message: Self::Message);
    fn view(&self) -> Element<'_, Self::Message>;

    fn background_color(&self) -> Color { ... }
    fn scale_factor(&self) -> f64 { ... }
    fn should_exit(&self) -> bool { ... }
    fn run(settings: Settings<()>) -> Result<(), Error>
    where
        Self: 'static + Sized
, { ... } }
Available on crate feature pure only.
Expand description

A pure version of Sandbox.

Unlike the impure version, the view method of this trait takes an immutable reference to self and returns a pure Element.

Required Associated Types

The type of messages your Sandbox will produce.

Required Methods

Initializes the Sandbox.

Here is where you should return the initial state of your app.

Returns the current title of the Sandbox.

This title can be dynamic! The runtime will automatically update the title of your application when necessary.

Handles a message and updates the state of the Sandbox.

This is where you define your update logic. All the messages, produced by user interactions, will be handled by this method.

Returns the widgets to display in the Sandbox.

These widgets can produce messages based on user interaction.

Provided Methods

Returns the background color of the Sandbox.

By default, it returns Color::WHITE.

Returns the scale factor of the Sandbox.

It can be used to dynamically control the size of the UI at runtime (i.e. zooming).

For instance, a scale factor of 2.0 will make widgets twice as big, while a scale factor of 0.5 will shrink them to half their size.

By default, it returns 1.0.

Returns whether the Sandbox should be terminated.

By default, it returns false.

Runs the Sandbox.

On native platforms, this method will take control of the current thread and will NOT return.

It should probably be that last thing you call in your main function.

Implementors