Skip to main content

TreeAppContext

Struct TreeAppContext 

Source
pub struct TreeAppContext { /* private fields */ }
Expand description

Per-tree app-level subscription state.

Held by WidgetTree as Rc<TreeAppContext> so that BuildContext can reach the event source adapter, allocate subscription ids, and post the UI-side callback into the lookup map. Fields are RefCell/Cell because the tree borrows itself mutably during build() and we need shared interior access.

Implementations§

Source§

impl TreeAppContext

Source

pub fn empty() -> Self

Empty context — no event source, no proxy poster. Used by tests and by WidgetTree::new().

Source

pub fn with_source_and_poster( event_source: EventSourceAdapter, poster: Arc<dyn AppEventPoster>, ) -> Self

Build a context with both a registered event source and a proxy poster. Called by teksilo-app when constructing a window for an application that registered an event source on the builder.

Source

pub fn with_app_state(self, registry: HashMap<TypeId, Box<dyn Any>>) -> Self

Install an app-state registry. Consumes self and returns a new context with the registry attached; the builder calls this after constructing the context and before wrapping it in Rc.

Source

pub fn with_poster(self, poster: Arc<dyn AppEventPoster>) -> Self

Install an AppEventPoster so background work (file dialogs, future async-result features) can post typed payloads back to the UI loop via AppEvent::External. The builder calls this unconditionally during TeksiloAppBuilder::run — the poster is cheap (a thin wrapper around the event-loop proxy) and being reachable means widgets do not have to depend on the event-source feature for unrelated async-result delivery.

Source

pub fn poster(&self) -> Option<&Arc<dyn AppEventPoster>>

Borrow the registered AppEventPoster if one was installed. Used by integrations that need to post typed payloads back to the UI loop from an external thread (e.g. file-dialog backends).

Source

pub fn app_state<T: 'static>(&self) -> Option<&T>

Look up an app-state value of type T previously registered via TeksiloAppBuilder::app_state.

Source

pub fn dispatch_subscription_event( &self, sub_id: SubscriptionId, event: &dyn Any, ) -> bool

Look up and invoke the UI-side callback for a posted subscription event. Returns true if a callback was found and invoked.

Source

pub fn ctx_subscription_window( &self, sub_id: SubscriptionId, ) -> Option<TeksiloWindowId>

The window a context-bearing subscription targets, if sub_id names one and it was registered from a window (always true in a real app). teksilo-app peeks this to know which window’s tree to mint the EventContext from before dispatching.

Source

pub fn dispatch_subscription_event_with_ctx( &self, sub_id: SubscriptionId, event: &dyn Any, ctx: &mut EventContext<'_>, ) -> bool

Invoke the context-bearing UI-side callback for a posted subscription event, passing the freshly-minted EventContext. Returns true if a callback was found and invoked. Called by teksilo-app from inside WidgetTree::run_with_event_context.

The Rc handle is cloned and the map borrow released before the call, so the callback may freely re-enter this map — e.g. ctx.open_window(...) synchronously builds a new tree whose widgets register their own context-bearing subscriptions. (Holding the borrow across the call would panic there; hence Rc, not Box.)

Source

pub fn ctx_subscription_count(&self) -> usize

Number of context-bearing subscription callbacks currently installed. Companion to subscription_count; used by lifecycle tests to assert the ctx-map teardown ran.

Source

pub fn purge_ctx_subscriptions_for_window(&self, window_id: TeksiloWindowId)

Drop every context-bearing subscription targeting window_id. Called by teksilo-app when a window closes, so the shared, longer-lived TreeAppContext map doesn’t retain inert callbacks for a torn-down tree (a window’s tree is dropped without a per-widget destroy_subtree pass). Mirrors AsyncCompletionHandle::purge_window.

Source

pub fn subscription_count(&self) -> usize

Number of UI-side subscription callbacks currently installed. Used by lifecycle tests to assert cleanup ran correctly.

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