Skip to main content

Cx

Struct Cx 

Source
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

Source

pub fn new(owner: Owner) -> Cx

A context that creates everything under owner, with no services yet.

Source

pub fn owner(&self) -> Owner

The owner that signals, memos and effects created through this context belong to.

Source

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.

Source

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.

Source

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

The service of type T, if one was provided.

Source

pub fn signal<T: 'static>(&self, value: T) -> Signal<T>

Creates a Signal holding value. See Owner::signal.

Source

pub fn memo<T: PartialEq + 'static>( &self, f: impl FnMut() -> T + 'static, ) -> Memo<T>

Creates a Memo that derives its value with f. See Owner::memo.

Source

pub fn effect(&self, f: impl FnMut() + 'static) -> Effect

Creates an Effect that reruns f when something it read changes. See Owner::effect.

Source§

impl Cx

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Cx

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cx

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Cx

§

impl !Send for Cx

§

impl !Sync for Cx

§

impl !UnwindSafe for Cx

§

impl Forget for Cx

§

impl Freeze for Cx

§

impl Move for Cx

§

impl Unpin for Cx

§

impl UnsafeUnpin for Cx

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, !>

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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