Skip to main content

Module context_state

Module context_state 

Source
Expand description

Global context state singleton

BlincContextState provides a global singleton for accessing reactive state management and other context-level resources without requiring explicit context parameters.

This enables components to create internal state without leaking implementation details:

// Before: user must manage internal component state
let fruit_open = ctx.use_state_keyed("fruit_open", || false);
cn::select(&fruit, &fruit_open)

// After: component manages internal state via singleton
cn::select(&fruit)  // open_state is internal to the component

§Initialization

The singleton must be initialized by the app layer before use:

// In WindowedApp::run()
BlincContextState::init(reactive, hooks, dirty_flag);

§Usage

Components can access state management via free functions:

use blinc_core::context_state::{use_state_keyed, use_signal_keyed};

// In a component:
let open_state = use_state_keyed("my_component_open", || false);

Structs§

BlincContextState
Global context state singleton
Bounds
Simple bounds representation for element queries Used by BlincContextState to avoid circular dependencies with blinc_layout
HookState
Stores keyed state across rebuilds
StateKey
Key for identifying a signal in the keyed state system

Enums§

MotionAnimationState
Motion animation state for query API
UpdateCategory
Update category for element change tracking

Functions§

query
Query an element by ID
query_motion
Query motion animation state by stable key
request_rebuild
Request a UI rebuild
use_signal_keyed
Create a persistent signal that survives across UI rebuilds (keyed)
use_state_keyed
Create a persistent state value that survives across UI rebuilds (keyed)

Type Aliases§

AnyElementRegistry
Type-erased element registry storage This allows blinc_core to store the registry without depending on blinc_layout
BoundsCallback
Callback for getting element bounds by string ID
DirtyFlag
Shared dirty flag for triggering UI rebuilds
FocusCallback
Callback for focus management Called with Some(id) to focus an element, None to clear focus
MotionCancelExitCallback
Callback for canceling a motion’s exit animation
MotionStateCallback
Callback for querying motion animation state by stable key
QueryCallback
Callback for querying elements by ID Returns the raw node ID (u64) if found, None otherwise
RecordedEventAny
Type-erased recorded event for recorder callbacks This avoids circular dependencies by using a boxed Any type
RecorderEventCallback
Callback for recording events (mouse, keyboard, scroll, etc.) Events are passed as type-erased Any to avoid circular dependencies
RecorderSnapshotCallback
Callback for capturing tree snapshots after each frame
RecorderUpdateCallback
Callback for tracking element updates with category
ScrollCallback
Callback for scrolling an element into view
SharedHookState
Shared hook state for the application
SharedReactiveGraph
Shared reactive graph for thread-safe access
StatefulCallback
Callback for notifying stateful elements of signal changes
TreeSnapshotAny
Type-erased tree snapshot for recorder callbacks