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
Application definition bundling all callbacks.
view returns a list of top-level window nodes. An empty list
renders an empty tree (loading, transition, or error screens where
the app has nothing to display yet). A single-element list renders
that window; a multi-element list renders peer windows. Matches the
shape used by the Elixir, Python, TypeScript, and Ruby SDKs.
pub opaque type App(model, msg)
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),
validate_props: Bool,
widget_config: dict.Dict(String, node.PropValue),
required_widgets: List(String),
)
}
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), validate_props: Bool, widget_config: dict.Dict(String, node.PropValue), required_widgets: List(String), )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.
- validate_props
-
Enable prop validation warnings from the renderer (default: False). When enabled, the renderer emits PropValidation events for invalid or unexpected widget properties.
- widget_config
-
Configuration passed to custom (native Rust) widgets. Keys are widget type names; values are widget-specific config.
- required_widgets
-
Native widget type names this app requires the renderer to have registered. The renderer emits a
required_widgets_missingdiagnostic during the handshake for any names it does not recognize. Non-fatal.
Values
pub fn application(
init: fn() -> #(model, command.Command(msg)),
update: fn(model, msg) -> #(model, command.Command(msg)),
view: fn(model) -> List(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.
view(model) returns a list of top-level window(...) nodes.
Return [] for an empty tree, [window(...)] for a single window,
or [a, b, ...] for peer windows.
pub fn application_with_opts(
init: fn(dynamic.Dynamic) -> #(model, command.Command(msg)),
update: fn(model, msg) -> #(model, command.Command(msg)),
view: fn(model) -> List(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.
view(model) returns a list of top-level window(...) nodes.
Return [] for an empty tree, [window(...)] for a single window,
or [a, b, ...] for peer windows.
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, renderer_exit.RendererExit) -> 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) -> List(node.Node)
Returns the app’s view function, called after every update to produce the list of top-level windows. An empty list renders an empty tree, a single-element list renders that window, and a multi-element list renders peer windows.
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) -> List(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.
view(model) returns a list of top-level window(...) nodes.
Return [] for an empty tree, [window(...)] for a single window,
or [a, b, ...] for peer windows.
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) -> List(node.Node),
) -> App(model, event.Event)
Create a simple app with app_opts passed to init.
view(model) returns a list of top-level window(...) nodes.
Return [] for an empty tree, [window(...)] for a single window,
or [a, b, ...] for peer windows.
pub fn with_on_renderer_exit(
app: App(model, msg),
handler: fn(model, renderer_exit.RendererExit) -> 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_subscribe(
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).