pub struct Runtime {
pub reducers: HashMap<ActionId, Vec<BoxedReducer>>,
pub persistent_reducers: HashMap<ActionId, Vec<BoxedReducer>>,
pub app_states: HashMap<TypeId, Box<dyn AppState>>,
pub runtime_state: RuntimeState,
pub measurer: Option<Arc<dyn TextMeasurer>>,
pub clipboard_backend: Option<Arc<dyn Clipboard>>,
pub ime_handler: Option<Arc<dyn ImeHandler>>,
pub pending_effects: Vec<EffectEnvelope>,
pub next_req_id: u64,
}Expand description
The core runtime that owns application state, reducers, and the effect queue.
Runtime is the single entry point for the action/reducer pipeline. Platform
shells create one Runtime, register their AppState, build the widget tree
each frame, absorb the resulting ActionRegistry, and call
Runtime::handle_input to process user events.
§Lifecycle
1. runtime = Runtime::default()
.with_measurer(measurer)
.with_clipboard(clipboard);
2. runtime.add_app_state(Box::new(MyState::default()))?;
3. loop {
let mut ctx = BuildCtx::new();
let tree = my_widget.build(&mut ctx, &view);
runtime.clear_reducers();
runtime.absorb_registry(ctx.registry);
// lower tree -> IR -> layout -> render
runtime.handle_input(event, &ir, &layout)?;
runtime.tick(dt)?;
}§Example
let mut runtime = Runtime::default();
runtime.add_app_state(Box::new(Counter { count: 0 }))?;
runtime.tick(16)?;Fields§
§reducers: HashMap<ActionId, Vec<BoxedReducer>>Per-frame reducers, cleared and re-populated every frame via
absorb_registry.
persistent_reducers: HashMap<ActionId, Vec<BoxedReducer>>Persistent reducers that survive clear_reducers
calls, installed once at app startup.
app_states: HashMap<TypeId, Box<dyn AppState>>Type-indexed application state store.
runtime_state: RuntimeStateMutable runtime state (interaction, scroll, text editing, animations).
measurer: Option<Arc<dyn TextMeasurer>>Platform-provided text measurer for layout.
clipboard_backend: Option<Arc<dyn Clipboard>>Platform-provided clipboard backend.
ime_handler: Option<Arc<dyn ImeHandler>>Platform-provided IME (Input Method Editor) handler.
pending_effects: Vec<EffectEnvelope>Effects emitted by reducers, awaiting platform execution.
next_req_id: u64Monotonically increasing counter for deterministic request id generation.
Implementations§
Source§impl Runtime
impl Runtime
pub fn with_measurer(self, measurer: Arc<dyn TextMeasurer>) -> Self
pub fn with_clipboard(self, backend: Arc<dyn Clipboard>) -> Self
pub fn with_ime_handler(self, handler: Arc<dyn ImeHandler>) -> Self
pub fn caret_from_point_in_text( &self, value: &str, font_size: f32, viewport_x: f32, viewport_w: f32, content_w: f32, scroll_offset: f32, point_x: f32, ) -> usize
pub fn register_reducer<S: AppState + 'static>( &mut self, action_id: ActionId, reducer_fn: fn(&mut S, &ActionEnvelope, NodeId) -> Result<()>, ) -> Result<()>
pub fn register_base_reducers(&mut self)
pub fn clear_reducers(&mut self)
pub fn absorb_registry<S: AppState>(&mut self, registry: ActionRegistry<S>)
Sourcepub fn absorb_persistent_registry<S: AppState>(
&mut self,
registry: ActionRegistry<S>,
)
pub fn absorb_persistent_registry<S: AppState>( &mut self, registry: ActionRegistry<S>, )
Registers reducers that should survive clear_reducers() calls.
This is intended for app-level “global” handlers (e.g. system effects) that
are installed once at app startup, while per-frame widget handlers are
regenerated every frame via BuildCtx and absorb_registry.
pub fn clock(&self) -> &Clock
pub fn get_app_state<S: AppState + 'static>(&self) -> Option<&S>
pub fn get_app_state_mut<S: AppState + 'static>(&mut self) -> Option<&mut S>
pub fn add_app_state<S: AppState + 'static>( &mut self, state: Box<S>, ) -> Result<()>
pub fn dispatch(&mut self, action: ActionEnvelope, target: NodeId) -> Result<()>
pub fn dispatch_with_input( &mut self, action: ActionEnvelope, target: NodeId, input: &ActionInput, ) -> Result<()>
pub fn tick(&mut self, dt: CurrentTime) -> Result<()>
pub fn enqueue_animation( &mut self, target: WidgetNodeId, request: AnimationRequest, )
pub fn sync_video_nodes(&mut self, registrations: &[VideoRegistration])
pub fn sync_web_nodes(&mut self, registrations: &[WebRegistration])
pub fn post_layout_hook(&mut self, ir: &CoreIR, layout: &LayoutSnapshot)
pub fn handle_input( &mut self, event: InputEvent, ir: &CoreIR, layout: &LayoutSnapshot, ) -> Result<()>
pub fn hit_test( &self, point: LayoutPoint, ir: &CoreIR, snapshot: &LayoutSnapshot, ) -> Option<NodeId>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Runtime
impl !RefUnwindSafe for Runtime
impl Send for Runtime
impl Sync for Runtime
impl Unpin for Runtime
impl UnsafeUnpin for Runtime
impl !UnwindSafe for Runtime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.