pub struct Cx { /* private fields */ }Expand description
The context widget code runs in.
A Cx wraps the reactive Owner of one part of the shell: a window,
a widget or one item of a keyed list. Signals, memos and effects created
through it belong to that owner, so they are freed when that part of the
shell goes away. Event handlers receive the Cx of their button, and
children_keyed views receive the Cx of
their item.
A context also carries the shell’s services, keyed by type: the platform, and later the clock, Sway, audio and the tray. Every context made from it shares the same map, so a service provided once at the root reaches every widget and handler.
Implementations§
Source§impl Cx
impl Cx
Sourcepub fn new(owner: Owner) -> Cx
pub fn new(owner: Owner) -> Cx
A context that creates everything under owner, with no services
yet.
Sourcepub fn owner(&self) -> Owner
pub fn owner(&self) -> Owner
The owner that signals, memos and effects created through this context belong to.
Sourcepub fn child(&self) -> Cx
pub fn child(&self) -> Cx
A context for a part of the shell inside this one: what it creates is freed when this context’s owner is. The services are shared with the child.
Sourcepub fn provide<T: 'static>(&self, service: T) -> Rc<T>
pub fn provide<T: 'static>(&self, service: T) -> Rc<T>
Makes service reachable from every context of this shell, through
service, and returns it shared. A service of the
same type provided before is replaced; whoever holds it keeps it.
Sourcepub fn signal<T: 'static>(&self, value: T) -> Signal<T>
pub fn signal<T: 'static>(&self, value: T) -> Signal<T>
Creates a Signal holding value. See Owner::signal.
Source§impl Cx
impl Cx
Sourcepub fn open_popup(&self, build: impl FnOnce(&Cx) -> PopupWindow)
pub fn open_popup(&self, build: impl FnOnce(&Cx) -> PopupWindow)
Opens a popup next to the widget this context belongs to, such as the
button whose handler got it. build describes the popup and gets its
context: what it creates there goes when the popup does.
The popup belongs to the widget, so it closes when the widget goes,
as well as on close_popup and when the user
clicks outside it. If build panics, that is logged with the
widget’s path and nothing opens. A context of no widget, such as the
one per_output gives, logs that and opens nothing.
Sourcepub fn close_popup(&self)
pub fn close_popup(&self)
Closes the popup this context’s widget is in, with every popup it opened and every popup that opened it, as a menu does once one of its entries is clicked. Outside a popup it logs that and does nothing.