plushie/subscription
Subscription types for ongoing event sources.
Return subscriptions from the subscribe callback. The runtime
diffs the list each cycle using key/1: subscriptions with the
same key are considered identical and kept alive; new keys trigger
a subscribe message to the renderer, and removed keys trigger an
unsubscribe. This means a subscription’s identity is its
(kind, tag) pair – changing max_rate on an existing key updates
the rate without re-subscribing.
Renderer subscriptions accept an optional max_rate that tells the
renderer to coalesce events beyond the given rate (events per second).
Types
pub type Subscription {
Every(interval_ms: Int, tag: String)
OnKeyPress(tag: String, max_rate: option.Option(Int))
OnKeyRelease(tag: String, max_rate: option.Option(Int))
OnModifiersChanged(tag: String, max_rate: option.Option(Int))
OnWindowClose(tag: String, max_rate: option.Option(Int))
OnWindowEvent(tag: String, max_rate: option.Option(Int))
OnWindowOpen(tag: String, max_rate: option.Option(Int))
OnWindowResize(tag: String, max_rate: option.Option(Int))
OnWindowFocus(tag: String, max_rate: option.Option(Int))
OnWindowUnfocus(tag: String, max_rate: option.Option(Int))
OnWindowMove(tag: String, max_rate: option.Option(Int))
OnMouseMove(tag: String, max_rate: option.Option(Int))
OnMouseButton(tag: String, max_rate: option.Option(Int))
OnMouseScroll(tag: String, max_rate: option.Option(Int))
OnTouch(tag: String, max_rate: option.Option(Int))
OnIme(tag: String, max_rate: option.Option(Int))
OnThemeChange(tag: String, max_rate: option.Option(Int))
OnAnimationFrame(tag: String, max_rate: option.Option(Int))
OnFileDrop(tag: String, max_rate: option.Option(Int))
OnEvent(tag: String, max_rate: option.Option(Int))
}
Constructors
-
Every(interval_ms: Int, tag: String) -
OnKeyPress(tag: String, max_rate: option.Option(Int)) -
OnKeyRelease(tag: String, max_rate: option.Option(Int)) -
OnModifiersChanged(tag: String, max_rate: option.Option(Int)) -
OnWindowClose(tag: String, max_rate: option.Option(Int)) -
OnWindowEvent(tag: String, max_rate: option.Option(Int)) -
OnWindowOpen(tag: String, max_rate: option.Option(Int)) -
OnWindowResize(tag: String, max_rate: option.Option(Int)) -
OnWindowFocus(tag: String, max_rate: option.Option(Int)) -
OnWindowUnfocus(tag: String, max_rate: option.Option(Int)) -
OnWindowMove(tag: String, max_rate: option.Option(Int)) -
OnMouseMove(tag: String, max_rate: option.Option(Int)) -
OnMouseButton(tag: String, max_rate: option.Option(Int)) -
OnMouseScroll(tag: String, max_rate: option.Option(Int)) -
OnTouch(tag: String, max_rate: option.Option(Int)) -
OnIme(tag: String, max_rate: option.Option(Int)) -
OnThemeChange(tag: String, max_rate: option.Option(Int)) -
OnAnimationFrame(tag: String, max_rate: option.Option(Int)) -
OnFileDrop(tag: String, max_rate: option.Option(Int)) -
OnEvent(tag: String, max_rate: option.Option(Int))
Unique identity for subscription diffing.
pub type SubscriptionKey {
TimerKey(interval_ms: Int, tag: String)
RendererKey(kind: String, tag: String)
}
Constructors
-
TimerKey(interval_ms: Int, tag: String) -
RendererKey(kind: String, tag: String)
Values
pub fn every(interval_ms: Int, tag: String) -> Subscription
Timer that fires every interval_ms milliseconds. Delivers a
Timer event with the given tag to update.
pub fn get_max_rate(sub: Subscription) -> option.Option(Int)
Get the max_rate from any subscription. Returns None for timer subscriptions and renderer subs without a rate.
pub fn key(sub: Subscription) -> SubscriptionKey
Compute the unique key for a subscription (used for diffing).
pub fn on_animation_frame(tag: String) -> Subscription
Subscribe to animation frame events (vsync ticks). The tag is for subscription management only.
pub fn on_event(tag: String) -> Subscription
Subscribe to all renderer events (catch-all). The tag is for subscription management only.
pub fn on_file_drop(tag: String) -> Subscription
Subscribe to file drop events. Also delivers file hovered and hover-left events. The tag is for subscription management only.
pub fn on_ime(tag: String) -> Subscription
Subscribe to IME (Input Method Editor) events for international text input. The tag is for subscription management only.
pub fn on_key_press(tag: String) -> Subscription
Subscribe to key press events. Delivers KeyPress events to update. The tag is for subscription management only.
pub fn on_key_release(tag: String) -> Subscription
Subscribe to key release events. Delivers KeyRelease events to update. The tag is for subscription management only.
pub fn on_modifiers_changed(tag: String) -> Subscription
Subscribe to keyboard modifier state changes (shift, ctrl, alt, etc.). The tag is for subscription management only.
pub fn on_mouse_button(tag: String) -> Subscription
Subscribe to mouse button press and release events. The tag is for subscription management only.
pub fn on_mouse_move(tag: String) -> Subscription
Subscribe to mouse movement events. Also delivers mouse entered and mouse left events. The tag is for subscription management only.
pub fn on_mouse_scroll(tag: String) -> Subscription
Subscribe to mouse scroll (wheel) events. The tag is for subscription management only.
pub fn on_theme_change(tag: String) -> Subscription
Subscribe to system theme changes (light/dark mode). The tag is for subscription management only.
pub fn on_touch(tag: String) -> Subscription
Subscribe to touch events (pressed, moved, lifted, lost). The tag is for subscription management only.
pub fn on_window_close(tag: String) -> Subscription
Subscribe to window close request events. The tag is for subscription management only.
pub fn on_window_event(tag: String) -> Subscription
Subscribe to all window events (resize, move, focus, etc.). If both this and a specific subscription (e.g. on_window_resize) are active, matching events are delivered twice. The tag is for subscription management only.
pub fn on_window_focus(tag: String) -> Subscription
Subscribe to window focus gained events. The tag is for subscription management only.
pub fn on_window_move(tag: String) -> Subscription
Subscribe to window move events. The tag is for subscription management only.
pub fn on_window_open(tag: String) -> Subscription
Subscribe to window open events. The tag is for subscription management only.
pub fn on_window_resize(tag: String) -> Subscription
Subscribe to window resize events. The tag is for subscription management only.
pub fn on_window_unfocus(tag: String) -> Subscription
Subscribe to window focus lost events. The tag is for subscription management only.
pub fn set_max_rate(sub: Subscription, rate: Int) -> Subscription
Set the max_rate on a renderer subscription. The renderer coalesces events beyond this rate. A rate of 0 means subscribe but never emit. Has no effect on timer subscriptions.
pub fn wire_kind(sub: Subscription) -> String
Wire format kind string for a subscription.