Skip to main content

Runtime

Struct Runtime 

Source
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: RuntimeState

Mutable 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: u64

Monotonically increasing counter for deterministic request id generation.

Implementations§

Source§

impl Runtime

Source

pub fn with_measurer(self, measurer: Arc<dyn TextMeasurer>) -> Self

Source

pub fn with_clipboard(self, backend: Arc<dyn Clipboard>) -> Self

Source

pub fn with_ime_handler(self, handler: Arc<dyn ImeHandler>) -> Self

Source

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

Source

pub fn register_reducer<S: AppState + 'static>( &mut self, action_id: ActionId, reducer_fn: fn(&mut S, &ActionEnvelope, NodeId) -> Result<()>, ) -> Result<()>

Source

pub fn register_base_reducers(&mut self)

Source

pub fn clear_reducers(&mut self)

Source

pub fn absorb_registry<S: AppState>(&mut self, registry: ActionRegistry<S>)

Source

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.

Source

pub fn clock(&self) -> &Clock

Source

pub fn get_app_state<S: AppState + 'static>(&self) -> Option<&S>

Source

pub fn get_app_state_mut<S: AppState + 'static>(&mut self) -> Option<&mut S>

Source

pub fn add_app_state<S: AppState + 'static>( &mut self, state: Box<S>, ) -> Result<()>

Source

pub fn dispatch(&mut self, action: ActionEnvelope, target: NodeId) -> Result<()>

Source

pub fn dispatch_with_input( &mut self, action: ActionEnvelope, target: NodeId, input: &ActionInput, ) -> Result<()>

Source

pub fn tick(&mut self, dt: CurrentTime) -> Result<()>

Source

pub fn enqueue_animation( &mut self, target: WidgetNodeId, request: AnimationRequest, )

Source

pub fn sync_video_nodes(&mut self, registrations: &[VideoRegistration])

Source

pub fn sync_web_nodes(&mut self, registrations: &[WebRegistration])

Source

pub fn post_layout_hook(&mut self, ir: &CoreIR, layout: &LayoutSnapshot)

Source

pub fn handle_input( &mut self, event: InputEvent, ir: &CoreIR, layout: &LayoutSnapshot, ) -> Result<()>

Source

pub fn hit_test( &self, point: LayoutPoint, ir: &CoreIR, snapshot: &LayoutSnapshot, ) -> Option<NodeId>

Trait Implementations§

Source§

impl Default for Runtime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.