plushie/app
App type definition and constructors.
An App bundles the init/update/view functions that define application
behavior. Use simple for most apps or application when you need
a custom message type.
Types
App-level settings sent to the Rust binary on startup.
pub type Settings {
Settings(
antialiasing: Bool,
default_text_size: Float,
theme: option.Option(theme.Theme),
fonts: List(String),
vsync: Bool,
scale_factor: Float,
default_font: option.Option(node.PropValue),
default_event_rate: option.Option(Int),
)
}
Constructors
-
Settings( antialiasing: Bool, default_text_size: Float, theme: option.Option(theme.Theme), fonts: List(String), vsync: Bool, scale_factor: Float, default_font: option.Option(node.PropValue), default_event_rate: option.Option(Int), )Arguments
- antialiasing
-
Enable anti-aliasing for rendered content. Default: True.
- default_text_size
-
Base text size in logical pixels. Default: 16.0.
- theme
-
Override the application theme. None uses the system theme.
- fonts
-
Paths to custom font files to load at startup.
- vsync
-
Enable vertical sync. Default: True.
- scale_factor
-
Global UI scale factor (1.0 = 100%). Default: 1.0.
- default_font
-
Override the default font family. None uses the built-in default.
- default_event_rate
-
Maximum events per second for coalescable event sources (mouse moves, sensor resizes, etc.). None uses the renderer’s built-in default. A value of 0 subscribes but never emits.
Values
pub fn application(
init: fn() -> #(model, command.Command(msg)),
update: fn(model, msg) -> #(model, command.Command(msg)),
view: fn(model) -> node.Node,
on_event: fn(event.Event) -> msg,
) -> App(model, msg)
Create an app with a custom message type.
The on_event function maps wire Events to the app’s msg type.
pub fn application_with_opts(
init: fn(dynamic.Dynamic) -> #(model, command.Command(msg)),
update: fn(model, msg) -> #(model, command.Command(msg)),
view: fn(model) -> node.Node,
on_event: fn(event.Event) -> msg,
) -> App(model, msg)
Create an app with a custom message type and app_opts passed to init.
pub fn get_init(
app: App(model, msg),
) -> fn(dynamic.Dynamic) -> #(model, command.Command(msg))
Returns the app’s init function, called once at startup with app_opts.
pub fn get_on_event(
app: App(model, msg),
) -> option.Option(fn(event.Event) -> msg)
Returns the optional event mapper. When set (via application),
the runtime passes wire Events through this function to produce
the app’s custom msg type before calling update.
pub fn get_on_renderer_exit(
app: App(model, msg),
) -> option.Option(fn(model, dynamic.Dynamic) -> model)
Returns the optional renderer exit handler. Called when the renderer process exits unexpectedly, allowing the app to adjust the model before the renderer restarts.
pub fn get_settings(app: App(model, msg)) -> fn() -> Settings
Returns the app’s settings function, called once at startup to configure the renderer (theme, fonts, antialiasing, etc.).
pub fn get_subscribe(
app: App(model, msg),
) -> fn(model) -> List(subscription.Subscription)
Returns the app’s subscribe function. The runtime calls this after every update and diffs the result to manage subscription lifecycle.
pub fn get_update(
app: App(model, msg),
) -> fn(model, msg) -> #(model, command.Command(msg))
Returns the app’s update function, called on every event with the current model and message.
pub fn get_view(app: App(model, msg)) -> fn(model) -> node.Node
Returns the app’s view function, called after every update to produce the UI tree.
pub fn get_window_config(
app: App(model, msg),
) -> fn(model) -> dict.Dict(String, node.PropValue)
Returns the app’s window config function, called at startup and on renderer restart to provide default window properties.
pub fn simple(
init: fn() -> #(model, command.Command(event.Event)),
update: fn(model, event.Event) -> #(
model,
command.Command(event.Event),
),
view: fn(model) -> node.Node,
) -> App(model, event.Event)
Create a simple app where msg = Event.
This covers the common case where update receives plushie Events directly.
The init function ignores the Dynamic app_opts argument. Use
simple_with_opts if you need to receive app_opts.
pub fn simple_with_opts(
init: fn(dynamic.Dynamic) -> #(
model,
command.Command(event.Event),
),
update: fn(model, event.Event) -> #(
model,
command.Command(event.Event),
),
view: fn(model) -> node.Node,
) -> App(model, event.Event)
Create a simple app with app_opts passed to init.
pub fn with_on_renderer_exit(
app: App(model, msg),
handler: fn(model, dynamic.Dynamic) -> model,
) -> App(model, msg)
Set the renderer exit handler.
pub fn with_settings(
app: App(model, msg),
settings: fn() -> Settings,
) -> App(model, msg)
Set the settings callback.
pub fn with_subscriptions(
app: App(model, msg),
subscribe: fn(model) -> List(subscription.Subscription),
) -> App(model, msg)
Set the subscribe callback (returns subscriptions based on model).
pub fn with_window_config(
app: App(model, msg),
window_config: fn(model) -> dict.Dict(String, node.PropValue),
) -> App(model, msg)
Set the window_config callback (per-window default settings).