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
impl TreeAppContext
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Empty context — no event source, no proxy poster. Used by tests
and by WidgetTree::new().
Sourcepub fn with_source_and_poster(
event_source: EventSourceAdapter,
poster: Arc<dyn AppEventPoster>,
) -> Self
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.
Sourcepub fn with_app_state(self, registry: HashMap<TypeId, Box<dyn Any>>) -> Self
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.
Sourcepub fn with_poster(self, poster: Arc<dyn AppEventPoster>) -> Self
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.
Sourcepub fn poster(&self) -> Option<&Arc<dyn AppEventPoster>>
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).
Sourcepub fn app_state<T: 'static>(&self) -> Option<&T>
pub fn app_state<T: 'static>(&self) -> Option<&T>
Look up an app-state value of type T previously registered via
TeksiloAppBuilder::app_state.
Sourcepub fn dispatch_subscription_event(
&self,
sub_id: SubscriptionId,
event: &dyn Any,
) -> bool
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.
The Rc handle is cloned and the map borrow released before the call, for
the same reason dispatch_subscription_event_with_ctx
does it: the callback may re-enter this map. It re-enters on two paths that both
exist today — a widget built from inside a handler registers its own
subscription (borrow_mut to insert), and a window closed from inside one is
purged by purge_subscriptions_for_window
(borrow_mut to retain). Holding the borrow across the call turns either into a
BorrowMutError panic; hence Rc, not Box.
Sourcepub fn ctx_subscription_window(
&self,
sub_id: SubscriptionId,
) -> Option<TeksiloWindowId>
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.
Sourcepub fn dispatch_subscription_event_with_ctx(
&self,
sub_id: SubscriptionId,
event: &dyn Any,
ctx: &mut EventContext<'_>,
) -> bool
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.)
Sourcepub fn ctx_subscription_count(&self) -> usize
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.
Sourcepub fn purge_ctx_subscriptions_for_window(&self, window_id: TeksiloWindowId)
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.
Sourcepub fn purge_subscriptions_for_window(&self, window_id: TeksiloWindowId)
pub fn purge_subscriptions_for_window(&self, window_id: TeksiloWindowId)
Drop every plain (context-free) subscription callback registered from
window_id. Called by teksilo-app when a window closes, beside
purge_ctx_subscriptions_for_window.
The two maps need two purges for the same reason they need two dispatch
functions: a given SubscriptionId lives in exactly one of them. Without this
one, every callback the closed window’s widgets installed stays in the shared map
for the life of the process, holding strong references to whatever it captured
(view-models, document stores, context handles), because a closing window’s tree
is dropped wholesale and nothing runs the per-widget removal in
WidgetTree::destroy_subtree_inner.
A registration made from a windowless tree records None and is never purged
here; only the per-widget teardown reaches it, which an application drives
through BuildContext::destroy_subtree.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Number of UI-side subscription callbacks currently installed. Used by lifecycle tests to assert cleanup ran correctly.