Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime {
    pub app_states: HashMap<TypeId, Box<dyn GlobalState>>,
    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 editing_convention: TextEditingConvention,
    pub pending_effects: Vec<EffectEnvelope>,
    pub next_req_id: u64,
    /* private fields */
}
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 GlobalState, 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_global_state(Box::new(MyState::default()))?;
3. loop {
       let mut ctx = BuildCtx::new();
       let tree = fission_core::build::enter(&mut ctx, &view, || MyRoot.into());
       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_global_state(Box::new(Counter { count: 0 }))?;
runtime.tick(16)?;

Fields§

§app_states: HashMap<TypeId, Box<dyn GlobalState>>

Type-indexed application state store.

§runtime_state: RuntimeState

Mutable runtime state (interaction, scroll, text editing, motions).

§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.

§editing_convention: TextEditingConvention

Text-editing conventions for the host that owns this runtime.

§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 reconcile_focus(&mut self, ir: &CoreIR) -> Result<bool>

Reconciles keyboard focus with the focus barriers in a newly lowered IR.

New barriers capture focus, nested barriers retain a restoration chain, and closing barriers restores the most recent valid target.

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: GlobalState + 'static>( &mut self, action_id: ActionId, reducer_fn: Reducer<S>, ) -> Result<()>

Source

pub fn register_base_reducers(&mut self)

Source

pub fn clear_reducers(&mut self)

Source

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

Source

pub fn absorb_persistent_registry<S: GlobalState>( &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_global_state<S: GlobalState + 'static>(&self) -> Option<&S>

Source

pub fn get_global_state_mut<S: GlobalState + 'static>( &mut self, ) -> Option<&mut S>

Source

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

Source

pub fn with_global_state<S: GlobalState + 'static>(self, state: S) -> Self

Source

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

Source

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

Source

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

Source

pub fn sync_motion_declarations( &mut self, declarations: &[MotionDeclaration], layout: Option<&LayoutSnapshot>, ) -> Vec<(WidgetId, MotionPropertyId)>

Source

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

Source

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

Source

pub fn queue_runtime_effect(&mut self, effect: RuntimeEffect) -> bool

Queues a runtime effect that must be resolved by the core runtime.

Shells call this for effects that require runtime-owned state or a post-layout pass instead of a host capability executor.

Source

pub fn queue_scroll_into_view(&mut self, request: ScrollIntoViewRequest)

Queues a post-layout request to reveal a widget in a scroll container.

Source

pub fn reconcile_ir(&mut self, ir: &CoreIR)

Reconciles runtime-owned widget state against the current lowered tree.

Shells must call this after replacing the IR and before computing layout so an unmounted widget’s state cannot affect the replacement tree’s first frame.

Source

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

Runs runtime work that depends on a freshly computed layout snapshot.

Returns true when the hook changed runtime state and the shell should schedule another frame.

Source

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

Source

pub fn clear_hover_state( &mut self, ir: &CoreIR, point: Option<LayoutPoint>, ) -> Result<bool>

Source

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

Source

pub fn reconcile_resources( &mut self, declarations: Vec<RuntimeResourceDeclaration>, ) -> Result<()>

Source

pub fn resource_generation(&self, key: &str) -> Option<u64>

Source

pub fn is_resource_current(&self, resource: &ResourceExecutionContext) -> bool

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 = !

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.