Struct zng_app::widget::WIDGET

source ·
pub struct WIDGET;
Expand description

Current context widget.

§Panics

Most of the methods on this service panic if not called inside a widget context.

Implementations§

source§

impl WIDGET

source

pub fn is_in_widget(&self) -> bool

Returns true if called inside a widget.

source

pub fn try_id(&self) -> Option<WidgetId>

Get the widget ID, if called inside a widget.

source

pub fn trace_path(&self) -> Txt

Gets a text with detailed path to the current widget.

This can be used to quickly identify the current widget during debug, the path printout will contain the widget types if the inspector metadata is found for the widget.

This method does not panic if called outside of a widget.

source

pub fn trace_id(&self) -> Txt

Gets a text with a detailed widget id.

This can be used to quickly identify the current widget during debug, the printout will contain the widget type if the inspector metadata is found for the widget.

This method does not panic if called outside of a widget.

source

pub fn id(&self) -> WidgetId

Get the widget ID.

source

pub fn info(&self) -> WidgetInfo

Gets the widget info.

source

pub fn bounds(&self) -> WidgetBoundsInfo

Widget bounds, updated every layout.

source

pub fn border(&self) -> WidgetBorderInfo

Widget border, updated every layout.

source

pub fn parent_id(&self) -> Option<WidgetId>

Gets the parent widget or None if is root.

Panics if not called inside a widget.

source

pub fn update_op(&self, op: UpdateOp) -> &Self

Schedule an UpdateOp for the current widget.

source

pub fn update(&self) -> &Self

Schedule an update for the current widget.

After the current update the app-extensions, parent window and widgets will update again.

source

pub fn update_info(&self) -> &Self

Schedule an info rebuild for the current widget.

After all requested updates apply the parent window and widgets will re-build the info tree.

source

pub fn layout(&self) -> &Self

Schedule a re-layout for the current widget.

After all requested updates apply the parent window and widgets will re-layout.

source

pub fn render(&self) -> &Self

Schedule a re-render for the current widget.

After all requested updates and layouts apply the parent window and widgets will re-render.

This also overrides any pending render_update request.

source

pub fn render_update(&self) -> &Self

Schedule a frame update for the current widget.

After all requested updates and layouts apply the parent window and widgets will update the frame.

This request is supplanted by any render request.

source

pub fn reinit(&self)

Flags the widget to re-init after the current update returns.

The widget responds to this request differently depending on the node method that calls it:

  • UiNode::init and UiNode::deinit: Request is ignored, removed.
  • UiNode::event: If the widget is pending a reinit, it is reinited first, then the event is propagated to child nodes. If a reinit is requested during event handling the widget is reinited immediately after the event handler.
  • UiNode::update: If the widget is pending a reinit, it is reinited and the update ignored. If a reinit is requested during update the widget is reinited immediately after the update.
  • Other methods: Reinit request is flagged and an UiNode::update is requested for the widget.
source

pub fn with_state<R>(&self, f: impl FnOnce(StateMapRef<'_, WIDGET>) -> R) -> R

Calls f with a read lock on the current widget state map.

source

pub fn with_state_mut<R>( &self, f: impl FnOnce(StateMapMut<'_, WIDGET>) -> R, ) -> R

Calls f with a write lock on the current widget state map.

source

pub fn get_state<T: StateValue + Clone>( &self, id: impl Into<StateId<T>>, ) -> Option<T>

Get the widget state id, if it is set.

source

pub fn req_state<T: StateValue + Clone>(&self, id: impl Into<StateId<T>>) -> T

Require the widget state id.

Panics if the id is not set.

source

pub fn set_state<T: StateValue>( &self, id: impl Into<StateId<T>>, value: impl Into<T>, ) -> Option<T>

Set the widget state id to value.

Returns the previous set value.

source

pub fn flag_state(&self, id: impl Into<StateId<()>>) -> bool

Sets the widget state id without value.

Returns if the state id was already flagged.

source

pub fn init_state<T: StateValue>( &self, id: impl Into<StateId<T>>, init: impl FnOnce() -> T, )

Calls init and sets id if it is not already set in the widget.

source

pub fn init_state_default<T: StateValue + Default>( &self, id: impl Into<StateId<T>>, )

Sets the id to the default value if it is not already set.

source

pub fn contains_state<T: StateValue>(&self, id: impl Into<StateId<T>>) -> bool

Returns true if the id is set or flagged in the widget.

source

pub fn sub_var_op(&self, op: UpdateOp, var: &impl AnyVar) -> &Self

Subscribe to receive UpdateOp when the var changes.

source

pub fn sub_var_op_when<T: VarValue>( &self, op: UpdateOp, var: &impl Var<T>, predicate: impl Fn(&T) -> bool + Send + Sync + 'static, ) -> &Self

Subscribe to receive UpdateOp when the var changes and predicate approves the new value.

Note that the predicate does not run in the widget context, it runs on the app context.

source

pub fn sub_var(&self, var: &impl AnyVar) -> &Self

Subscribe to receive updates when the var changes.

source

pub fn sub_var_when<T: VarValue>( &self, var: &impl Var<T>, predicate: impl Fn(&T) -> bool + Send + Sync + 'static, ) -> &Self

Subscribe to receive updates when the var changes and the predicate approves the new value.

Note that the predicate does not run in the widget context, it runs on the app context.

source

pub fn sub_var_info(&self, var: &impl AnyVar) -> &Self

Subscribe to receive info rebuild requests when the var changes.

source

pub fn sub_var_info_when<T: VarValue>( &self, var: &impl Var<T>, predicate: impl Fn(&T) -> bool + Send + Sync + 'static, ) -> &Self

Subscribe to receive info rebuild requests when the var changes and the predicate approves the new value.

Note that the predicate does not run in the widget context, it runs on the app context.

source

pub fn sub_var_layout(&self, var: &impl AnyVar) -> &Self

Subscribe to receive layout requests when the var changes.

source

pub fn sub_var_layout_when<T: VarValue>( &self, var: &impl Var<T>, predicate: impl Fn(&T) -> bool + Send + Sync + 'static, ) -> &Self

Subscribe to receive layout requests when the var changes and the predicate approves the new value.

Note that the predicate does not run in the widget context, it runs on the app context.

source

pub fn sub_var_render(&self, var: &impl AnyVar) -> &Self

Subscribe to receive render requests when the var changes.

source

pub fn sub_var_render_when<T: VarValue>( &self, var: &impl Var<T>, predicate: impl Fn(&T) -> bool + Send + Sync + 'static, ) -> &Self

Subscribe to receive render requests when the var changes and the predicate approves the new value.

Note that the predicate does not run in the widget context, it runs on the app context.

source

pub fn sub_var_render_update(&self, var: &impl AnyVar) -> &Self

Subscribe to receive render update requests when the var changes.

source

pub fn sub_var_render_update_when<T: VarValue>( &self, var: &impl Var<T>, predicate: impl Fn(&T) -> bool + Send + Sync + 'static, ) -> &Self

Subscribe to receive render update requests when the var changes and the predicate approves the new value.

Note that the predicate does not run in the widget context, it runs on the app context.

source

pub fn sub_event<A: EventArgs>(&self, event: &Event<A>) -> &Self

Subscribe to receive events from event when the event targets this widget.

source

pub fn push_event_handle(&self, handle: EventHandle)

Hold the event handle until the widget is deinited.

source

pub fn push_event_handles(&self, handles: EventHandles)

Hold the event handles until the widget is deinited.

source

pub fn push_var_handle(&self, handle: VarHandle)

Hold the var handle until the widget is deinited.

source

pub fn push_var_handles(&self, handles: VarHandles)

Hold the var handles until the widget is deinited.

source

pub fn win_point_to_wgt(&self, point: DipPoint) -> Option<PxPoint>

Transform point in the window space to the widget inner bounds.

source

pub fn win_to_wgt(&self) -> Option<PxTransform>

Gets the transform from the window space to the widget inner bounds.

source

pub fn with_handles<R>( &self, handles: &mut WidgetHandlesCtx, f: impl FnOnce() -> R, ) -> R

Calls f with an override target for var and event subscription handles.

By default when vars and events are subscribed using the methods of this service the subscriptions live until the widget is deinited. This method intersects these subscriptions, registering then in handles instead.

source

pub fn with_context<R>( &self, ctx: &mut WidgetCtx, update_mode: WidgetUpdateMode, f: impl FnOnce() -> R, ) -> R

Calls f while the widget is set to ctx.

If update_mode is WidgetUpdateMode::Bubble the update flags requested for the ctx after f will be copied to the caller widget context, otherwise they are ignored.

This method can be used to manually define a widget context, note that widgets already define their own context.

source

pub fn with_no_context<R>(&self, f: impl FnOnce() -> R) -> R

Calls f while no widget is available in the context.

Auto Trait Implementations§

§

impl Freeze for WIDGET

§

impl RefUnwindSafe for WIDGET

§

impl Send for WIDGET

§

impl Sync for WIDGET

§

impl Unpin for WIDGET

§

impl UnwindSafe for WIDGET

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.

§

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

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