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
impl WIDGET
sourcepub fn is_in_widget(&self) -> bool
pub fn is_in_widget(&self) -> bool
Returns true
if called inside a widget.
sourcepub fn trace_path(&self) -> Txt
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.
sourcepub fn trace_id(&self) -> Txt
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.
sourcepub fn info(&self) -> WidgetInfo
pub fn info(&self) -> WidgetInfo
Gets the widget info.
sourcepub fn bounds(&self) -> WidgetBoundsInfo
pub fn bounds(&self) -> WidgetBoundsInfo
Widget bounds, updated every layout.
sourcepub fn border(&self) -> WidgetBorderInfo
pub fn border(&self) -> WidgetBorderInfo
Widget border, updated every layout.
sourcepub fn parent_id(&self) -> Option<WidgetId>
pub fn parent_id(&self) -> Option<WidgetId>
Gets the parent widget or None
if is root.
Panics if not called inside a widget.
sourcepub fn update(&self) -> &Self
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.
sourcepub fn update_info(&self) -> &Self
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.
sourcepub fn layout(&self) -> &Self
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.
sourcepub fn render(&self) -> &Self
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.
sourcepub fn render_update(&self) -> &Self
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.
sourcepub fn reinit(&self)
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
andUiNode::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.
sourcepub fn with_state<R>(&self, f: impl FnOnce(StateMapRef<'_, WIDGET>) -> R) -> R
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.
sourcepub fn with_state_mut<R>(
&self,
f: impl FnOnce(StateMapMut<'_, WIDGET>) -> R,
) -> R
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.
sourcepub fn get_state<T: StateValue + Clone>(
&self,
id: impl Into<StateId<T>>,
) -> Option<T>
pub fn get_state<T: StateValue + Clone>( &self, id: impl Into<StateId<T>>, ) -> Option<T>
Get the widget state id
, if it is set.
sourcepub fn req_state<T: StateValue + Clone>(&self, id: impl Into<StateId<T>>) -> T
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.
sourcepub fn set_state<T: StateValue>(
&self,
id: impl Into<StateId<T>>,
value: impl Into<T>,
) -> Option<T>
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.
sourcepub fn flag_state(&self, id: impl Into<StateId<()>>) -> bool
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.
sourcepub fn init_state<T: StateValue>(
&self,
id: impl Into<StateId<T>>,
init: impl FnOnce() -> T,
)
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.
sourcepub fn init_state_default<T: StateValue + Default>(
&self,
id: impl Into<StateId<T>>,
)
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.
sourcepub fn contains_state<T: StateValue>(&self, id: impl Into<StateId<T>>) -> bool
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.
sourcepub fn sub_var_op(&self, op: UpdateOp, var: &impl AnyVar) -> &Self
pub fn sub_var_op(&self, op: UpdateOp, var: &impl AnyVar) -> &Self
Subscribe to receive UpdateOp
when the var
changes.
sourcepub fn sub_var_op_when<T: VarValue>(
&self,
op: UpdateOp,
var: &impl Var<T>,
predicate: impl Fn(&T) -> bool + Send + Sync + 'static,
) -> &Self
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.
sourcepub fn sub_var(&self, var: &impl AnyVar) -> &Self
pub fn sub_var(&self, var: &impl AnyVar) -> &Self
Subscribe to receive updates when the var
changes.
sourcepub fn sub_var_when<T: VarValue>(
&self,
var: &impl Var<T>,
predicate: impl Fn(&T) -> bool + Send + Sync + 'static,
) -> &Self
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.
sourcepub fn sub_var_info(&self, var: &impl AnyVar) -> &Self
pub fn sub_var_info(&self, var: &impl AnyVar) -> &Self
Subscribe to receive info rebuild requests when the var
changes.
sourcepub fn sub_var_info_when<T: VarValue>(
&self,
var: &impl Var<T>,
predicate: impl Fn(&T) -> bool + Send + Sync + 'static,
) -> &Self
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.
sourcepub fn sub_var_layout(&self, var: &impl AnyVar) -> &Self
pub fn sub_var_layout(&self, var: &impl AnyVar) -> &Self
Subscribe to receive layout requests when the var
changes.
sourcepub fn sub_var_layout_when<T: VarValue>(
&self,
var: &impl Var<T>,
predicate: impl Fn(&T) -> bool + Send + Sync + 'static,
) -> &Self
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.
sourcepub fn sub_var_render(&self, var: &impl AnyVar) -> &Self
pub fn sub_var_render(&self, var: &impl AnyVar) -> &Self
Subscribe to receive render requests when the var
changes.
sourcepub fn sub_var_render_when<T: VarValue>(
&self,
var: &impl Var<T>,
predicate: impl Fn(&T) -> bool + Send + Sync + 'static,
) -> &Self
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.
sourcepub fn sub_var_render_update(&self, var: &impl AnyVar) -> &Self
pub fn sub_var_render_update(&self, var: &impl AnyVar) -> &Self
Subscribe to receive render update requests when the var
changes.
sourcepub fn sub_var_render_update_when<T: VarValue>(
&self,
var: &impl Var<T>,
predicate: impl Fn(&T) -> bool + Send + Sync + 'static,
) -> &Self
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.
sourcepub fn sub_event<A: EventArgs>(&self, event: &Event<A>) -> &Self
pub fn sub_event<A: EventArgs>(&self, event: &Event<A>) -> &Self
Subscribe to receive events from event
when the event targets this widget.
sourcepub fn push_event_handle(&self, handle: EventHandle)
pub fn push_event_handle(&self, handle: EventHandle)
Hold the event handle
until the widget is deinited.
sourcepub fn push_event_handles(&self, handles: EventHandles)
pub fn push_event_handles(&self, handles: EventHandles)
Hold the event handles
until the widget is deinited.
sourcepub fn push_var_handle(&self, handle: VarHandle)
pub fn push_var_handle(&self, handle: VarHandle)
Hold the var handle
until the widget is deinited.
sourcepub fn push_var_handles(&self, handles: VarHandles)
pub fn push_var_handles(&self, handles: VarHandles)
Hold the var handles
until the widget is deinited.
sourcepub fn win_point_to_wgt(&self, point: DipPoint) -> Option<PxPoint>
pub fn win_point_to_wgt(&self, point: DipPoint) -> Option<PxPoint>
Transform point in the window space to the widget inner bounds.
sourcepub fn win_to_wgt(&self) -> Option<PxTransform>
pub fn win_to_wgt(&self) -> Option<PxTransform>
Gets the transform from the window space to the widget inner bounds.
sourcepub fn with_handles<R>(
&self,
handles: &mut WidgetHandlesCtx,
f: impl FnOnce() -> R,
) -> R
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.
sourcepub fn with_context<R>(
&self,
ctx: &mut WidgetCtx,
update_mode: WidgetUpdateMode,
f: impl FnOnce() -> R,
) -> R
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.
sourcepub fn with_no_context<R>(&self, f: impl FnOnce() -> R) -> R
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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