pub struct WidgetContext<'context> { /* private fields */ }
Expand description
A context for a widget.
This type provides access to the widget hierarchy from the perspective of a specific widget.
Implementations§
source§impl<'context> WidgetContext<'context>
impl<'context> WidgetContext<'context>
sourcepub fn borrowed(&mut self) -> WidgetContext<'_>
pub fn borrowed(&mut self) -> WidgetContext<'_>
Returns a new instance that borrows from self
.
sourcepub fn for_other<'child, Widget>(
&'child mut self,
widget: &Widget,
) -> <Widget::Managed as MapManagedWidget<WidgetContext<'child>>>::Result
pub fn for_other<'child, Widget>( &'child mut self, widget: &Widget, ) -> <Widget::Managed as MapManagedWidget<WidgetContext<'child>>>::Result
Returns a new context representing widget
.
sourcepub fn is_child_of(&self, possible_parent: &WidgetInstance) -> bool
pub fn is_child_of(&self, possible_parent: &WidgetInstance) -> bool
Returns true if possible_parent
is in this widget’s parent list.
sourcepub fn redraw_when_changed(&self, value: &impl Trackable)
pub fn redraw_when_changed(&self, value: &impl Trackable)
Ensures that this widget will be redrawn when value
has been updated.
sourcepub fn invalidate_when_changed(&self, value: &impl Trackable)
pub fn invalidate_when_changed(&self, value: &impl Trackable)
Ensures that this widget will be redrawn when value
has been updated.
sourcepub fn last_layout(&self) -> Option<Rect<Px>>
pub fn last_layout(&self) -> Option<Rect<Px>>
Returns the last layout of this widget.
sourcepub fn focus(&mut self)
pub fn focus(&mut self)
Sets the currently focused widget to this widget.
Widget events relating to focus changes are deferred until after the all contexts for the currently firing event are dropped.
sourcepub fn blur(&mut self) -> bool
pub fn blur(&mut self) -> bool
Clears focus from this widget, if it is the focused widget.
Returns true if this function resulted in the focus being changed.
Widget events relating to focus changes are deferred until after the all contexts for the currently firing event are dropped.
sourcepub fn focus_is_advancing(&mut self) -> bool
pub fn focus_is_advancing(&mut self) -> bool
Returns true if the last focus event was an advancing motion, not a returning motion.
This value is meaningless outside of focus-related events.
sourcepub fn activate(&mut self) -> bool
pub fn activate(&mut self) -> bool
Activates this widget, if it is not already active.
Returns true if this function resulted in the currently active widget being changed.
Widget events relating to activation changes are deferred until after the all contexts for the currently firing event are dropped.
sourcepub fn deactivate(&mut self) -> bool
pub fn deactivate(&mut self) -> bool
Deactivates this widget, if it is the currently active widget.
Returns true if this function resulted in the active widget being changed.
Widget events relating to activation changes are deferred until after the all contexts for the currently firing event are dropped.
sourcepub fn hovered(&self) -> bool
pub fn hovered(&self) -> bool
Returns true if this widget is currently hovered, even if the cursor is over a child widget.
sourcepub fn primary_hover(&self) -> bool
pub fn primary_hover(&self) -> bool
Returns true if this widget that is directly beneath the cursor.
sourcepub fn focused(&self, check_window: bool) -> bool
pub fn focused(&self, check_window: bool) -> bool
Returns true if this widget is currently focused for user input.
sourcepub fn is_default(&self) -> bool
pub fn is_default(&self) -> bool
Returns true if this widget is the target to activate when the user triggers a default action.
See
MakeWidget::into_default()
for more information.
sourcepub fn is_escape(&self) -> bool
pub fn is_escape(&self) -> bool
Returns true if this widget is the target to activate when the user triggers an escape action.
See
MakeWidget::into_escape()
for more information.
sourcepub const fn widget(&self) -> &MountedWidget
pub const fn widget(&self) -> &MountedWidget
Returns the widget this context is for.
sourcepub fn attach_styles(&self, styles: impl IntoValue<Styles>)
pub fn attach_styles(&self, styles: impl IntoValue<Styles>)
Attaches styles
to the widget hierarchy for this widget.
Style queries for children will return any values matching this collection.
sourcepub fn attach_theme(&self, theme: Value<ThemePair>)
pub fn attach_theme(&self, theme: Value<ThemePair>)
Attaches theme
to the widget hierarchy for this widget.
All children nodes will access this theme in their contexts.
sourcepub fn attach_theme_mode(&mut self, theme_mode: Value<ThemeMode>)
pub fn attach_theme_mode(&mut self, theme_mode: Value<ThemeMode>)
Attaches theme_mode
to the widget hierarchy for this widget.
All children nodes will use this theme mode.
sourcepub fn attach_locale(&self, locale: Value<LanguageIdentifier>)
pub fn attach_locale(&self, locale: Value<LanguageIdentifier>)
Attaches locale
to the widget hierarchy for this widget.
All children nodes will access this theme in their contexts.
sourcepub fn get<Component: ComponentDefinition>(
&self,
query: &Component,
) -> Component::ComponentType
pub fn get<Component: ComponentDefinition>( &self, query: &Component, ) -> Component::ComponentType
Queries the widget hierarchy for a single style component.
This function traverses up the widget hierarchy looking for the component being requested. If a matching component is found, it will be returned. Otherwise, the default value will be returned.
sourcepub fn try_get<Component: ComponentDefinition>(
&self,
query: &Component,
) -> Option<Component::ComponentType>
pub fn try_get<Component: ComponentDefinition>( &self, query: &Component, ) -> Option<Component::ComponentType>
Queries the widget hierarchy for a single style component.
This function traverses up the widget hierarchy looking for the component being requested. If a matching component is found, it will be returned.
sourcepub const fn window(&self) -> &dyn PlatformWindow
pub const fn window(&self) -> &dyn PlatformWindow
Returns the window containing this widget.
sourcepub const fn localizations(&self) -> &Localizations
pub const fn localizations(&self) -> &Localizations
Returns the localizations for this application.
sourcepub const fn window_mut(&mut self) -> &mut dyn PlatformWindow
pub const fn window_mut(&mut self) -> &mut dyn PlatformWindow
Returns an exclusive reference to the window containing this widget.
sourcepub fn theme_pair(&self) -> &ThemePair
pub fn theme_pair(&self) -> &ThemePair
Returns the theme pair for the window.
sourcepub fn theme_mode(&self) -> ThemeMode
pub fn theme_mode(&self) -> ThemeMode
Returns the currently active theme mode.
sourcepub fn inverse_theme(&self) -> &Theme
pub fn inverse_theme(&self) -> &Theme
Returns the opposite theme of Self::theme()
.
sourcepub fn cache_key(&self) -> WidgetCacheKey
pub fn cache_key(&self) -> WidgetCacheKey
Returns a key that can be checked to see if a widget should invalidate caches it stores.
sourcepub fn loaded_font_faces(&self, font: &LoadedFont) -> &[LoadedFontFace]
pub fn loaded_font_faces(&self, font: &LoadedFont) -> &[LoadedFontFace]
Returns a list of faces that were loaded from font
, or an empty slice
if no faces were loaded.
Trait Implementations§
source§impl<'context> Deref for WidgetContext<'context>
impl<'context> Deref for WidgetContext<'context>
source§impl DerefMut for WidgetContext<'_>
impl DerefMut for WidgetContext<'_>
source§impl LocalizationContext for WidgetContext<'_>
impl LocalizationContext for WidgetContext<'_>
source§fn localizations(&self) -> &Localizations
fn localizations(&self) -> &Localizations
source§fn invalidate_when_changed(&self, trackable: &impl Trackable)
fn invalidate_when_changed(&self, trackable: &impl Trackable)
trackable
when changed. Read moreAuto Trait Implementations§
impl<'context> Freeze for WidgetContext<'context>
impl<'context> !RefUnwindSafe for WidgetContext<'context>
impl<'context> !Send for WidgetContext<'context>
impl<'context> !Sync for WidgetContext<'context>
impl<'context> Unpin for WidgetContext<'context>
impl<'context> !UnwindSafe for WidgetContext<'context>
Blanket Implementations§
source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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
source§impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters
when converting.source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.§impl<A> Cast for A
impl<A> Cast for A
source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle
.source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other
into Self
, while performing the appropriate scaling,
rounding and clamping.§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, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
source§fn into_angle(self) -> U
fn into_angle(self) -> U
T
.source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters
when converting.source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
source§fn into_color(self) -> U
fn into_color(self) -> U
source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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 moresource§impl<T> IntoReadOnly<T> for T
impl<T> IntoReadOnly<T> for T
source§fn into_read_only(self) -> ReadOnly<T>
fn into_read_only(self) -> ReadOnly<T>
self
as a ReadOnly
.source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self
into T
, while performing the appropriate scaling,
rounding and clamping.source§impl<T> IntoValue<T> for T
impl<T> IntoValue<T> for T
source§fn into_value(self) -> Value<T>
fn into_value(self) -> Value<T>
Value
.§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors
fails to cast.source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains
the unclamped color. Read more