Struct TesseraRuntime

Source
pub struct TesseraRuntime {
    pub component_tree: ComponentTree,
    pub window_size: [u32; 2],
    pub cursor_icon_request: Option<CursorIcon>,
    /* private fields */
}
Expand description

Central runtime state container for the Tessera UI framework.

The TesseraRuntime holds all global state and side effects that need to be shared across the entire application. This includes the component tree structure, window properties, and user interface state that persists across frame updates.

§Design Philosophy

The runtime follows these key principles:

  • Single Source of Truth: All shared state is centralized in one location
  • Thread Safety: Safe concurrent access through read-write locks
  • Lazy Initialization: Runtime is created only when first accessed
  • Minimal Overhead: Optimized for frequent reads and occasional writes

§Lifecycle

The runtime is automatically initialized on first access and persists for the entire application lifetime. It cannot be manually destroyed or recreated.

§Fields

All fields are public to allow direct access after acquiring the appropriate lock. However, consider using higher-level APIs when available to maintain consistency.

Fields§

§component_tree: ComponentTree

The hierarchical structure of all UI components in the application.

This tree represents the current state of the UI hierarchy, including component relationships, layout information, and rendering data. The component tree is rebuilt or updated each frame during the UI update cycle.

§Thread Safety

While the runtime itself is thread-safe, individual operations on the component tree may require coordination to maintain consistency during parallel processing phases.

§window_size: [u32; 2]

Current window dimensions in physical pixels.

This array contains [width, height] representing the current size of the application window. These values are updated automatically when the window is resized and are used for layout calculations and rendering.

§Coordinate System

  • Values are in physical pixels (not density-independent pixels)
  • Origin is at the top-left corner of the window
  • Both dimensions are guaranteed to be non-negative
§cursor_icon_request: Option<CursorIcon>

Cursor icon change request from UI components.

Components can request cursor icon changes by setting this field during their update cycle. The windowing system will apply the requested cursor icon if present, or use the default cursor if None.

§Lifecycle

This field is typically:

  1. Reset to None at the beginning of each frame
  2. Set by components during event handling or state updates
  3. Applied by the windowing system at the end of the frame

§Priority

If multiple components request different cursor icons in the same frame, the last request takes precedence. Components should coordinate cursor changes or use a priority system if needed.

Implementations§

Source§

impl TesseraRuntime

Source

pub fn read() -> RwLockReadGuard<'static, Self>

Acquires shared read access to the runtime state.

This method returns a read guard that allows concurrent access to the runtime data from multiple threads. Multiple readers can access the runtime simultaneously, but no writers can modify the state while any read guards exist.

§Blocking Behavior

This method will block the current thread if a write lock is currently held. It will return immediately if no write locks are active, even if other read locks exist.

§Usage
use tessera_ui::TesseraRuntime;

// Access runtime data for reading
let runtime = TesseraRuntime::read();
let [width, height] = runtime.window_size;
println!("Window size: {}x{}", width, height);
// Lock is automatically released when `runtime` goes out of scope
§Performance

Read locks are optimized for high-frequency access and have minimal overhead when no write contention exists. Prefer read locks over write locks whenever possible to maximize parallelism.

§Deadlock Prevention

To prevent deadlocks:

  • Always acquire locks in a consistent order
  • Keep lock scopes as narrow as possible
  • Avoid calling other locking functions while holding a lock
§Returns

A [RwLockReadGuard] that provides read-only access to the runtime state. The guard automatically releases the lock when dropped.

Source

pub fn write() -> RwLockWriteGuard<'static, Self>

Acquires exclusive write access to the runtime state.

This method returns a write guard that provides exclusive access to modify the runtime data. Only one writer can access the runtime at a time, and no readers can access the state while a write lock is held.

§Blocking Behavior

This method will block the current thread until all existing read and write locks are released. It guarantees exclusive access once acquired.

§Usage
use tessera_ui::TesseraRuntime;

// Modify runtime state
{
    let mut runtime = TesseraRuntime::write();
    runtime.window_size = [1920, 1080];
    runtime.cursor_icon_request = Some(winit::window::CursorIcon::Pointer);
} // Lock is automatically released
§Performance Considerations

Write locks are more expensive than read locks and should be used sparingly:

  • Batch multiple modifications into a single write lock scope
  • Release write locks as quickly as possible
  • Consider if the operation truly requires exclusive access
§Deadlock Prevention

The same deadlock prevention guidelines apply as with read():

  • Acquire locks in consistent order
  • Minimize lock scope duration
  • Avoid nested locking operations
§Returns

A [RwLockWriteGuard] that provides exclusive read-write access to the runtime state. The guard automatically releases the lock when dropped.

Source

pub fn on_minimize(&mut self, callback: impl Fn(bool) + Send + Sync + 'static)

Registers a per-frame callback for minimize state changes. Components should call this every frame they wish to be notified.

Source

pub fn on_close(&mut self, callback: impl Fn() + Send + Sync + 'static)

Registers a per-frame callback for window close event. Components should call this every frame they wish to be notified.

Source

pub fn clear_frame_callbacks(&mut self)

Clears all per-frame registered callbacks. Must be called by the event loop at the beginning of each frame.

Source

pub fn trigger_minimize_callbacks(&self, minimized: bool)

Triggers all registered callbacks (global and per-frame). Called by the event loop when a minimize event is detected.

Source

pub fn trigger_close_callbacks(&self)

Triggers all registered callbacks (global and per-frame) for window close event. Called by the event loop when a close event is detected.

Trait Implementations§

Source§

impl Default for TesseraRuntime

Source§

fn default() -> TesseraRuntime

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns a reference to the concrete type as &dyn Any.
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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

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

§

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

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

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

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

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

§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,