pub struct GraphicsContext<'context, 'clip, 'gfx, 'pass> {
pub widget: WidgetContext<'context>,
pub gfx: Exclusive<'context, Graphics<'clip, 'gfx, 'pass>>,
}
Expand description
A context to a function that is rendering a widget.
Fields§
§widget: WidgetContext<'context>
The context of the widget being rendered.
gfx: Exclusive<'context, Graphics<'clip, 'gfx, 'pass>>
The graphics context clipped and offset to the area of the widget being rendered. Drawing at 0,0 will draw at the top-left pixel of the laid-out widget region.
Implementations§
source§impl<'clip, 'gfx, 'pass> GraphicsContext<'_, 'clip, 'gfx, 'pass>
impl<'clip, 'gfx, 'pass> GraphicsContext<'_, 'clip, 'gfx, 'pass>
sourcepub fn borrowed(&mut self) -> GraphicsContext<'_, 'clip, 'gfx, 'pass>
pub fn borrowed(&mut self) -> GraphicsContext<'_, 'clip, 'gfx, 'pass>
Returns a new instance that borrows from self
.
sourcepub fn for_other<'child, Widget>(
&'child mut self,
widget: &Widget,
) -> <Widget::Managed as MapManagedWidget<GraphicsContext<'child, 'child, 'gfx, 'pass>>>::Resultwhere
Widget: ManageWidget,
Widget::Managed: MapManagedWidget<GraphicsContext<'child, 'child, 'gfx, 'pass>>,
pub fn for_other<'child, Widget>(
&'child mut self,
widget: &Widget,
) -> <Widget::Managed as MapManagedWidget<GraphicsContext<'child, 'child, 'gfx, 'pass>>>::Resultwhere
Widget: ManageWidget,
Widget::Managed: MapManagedWidget<GraphicsContext<'child, 'child, 'gfx, 'pass>>,
Returns a new GraphicsContext
that allows invoking graphics functions
for widget
.
sourcepub fn set_font_family(&mut self, family: FamilyOwned)
pub fn set_font_family(&mut self, family: FamilyOwned)
Sets the current font family.
sourcepub fn current_family_list(&mut self) -> FontFamilyList
pub fn current_family_list(&mut self) -> FontFamilyList
Returns the currently set font family list.
sourcepub fn find_available_font_family(
&mut self,
list: &FontFamilyList,
) -> Option<FamilyOwned>
pub fn find_available_font_family( &mut self, list: &FontFamilyList, ) -> Option<FamilyOwned>
Returns the first font family in list
that is currently in the font
system, or None if no font families match.
sourcepub fn set_available_font_family(&mut self, list: &FontFamilyList)
pub fn set_available_font_family(&mut self, list: &FontFamilyList)
Sets the font family to the first family in list
.
sourcepub fn apply_opacity(&mut self, opacity: impl Into<ZeroToOne>)
pub fn apply_opacity(&mut self, opacity: impl Into<ZeroToOne>)
Updates self
to have opacity
.
This setting will be mixed with the current opacity value.
sourcepub fn clipped_to(
&mut self,
clip: Rect<Px>,
) -> GraphicsContext<'_, '_, 'gfx, 'pass>
pub fn clipped_to( &mut self, clip: Rect<Px>, ) -> GraphicsContext<'_, '_, 'gfx, 'pass>
Returns a new graphics context that renders to the clip
rectangle.
sourcepub fn fill(&mut self, color: Color)
pub fn fill(&mut self, color: Color)
Fills the background of this widget with color
, honoring the current
CornerRadius
setting.
If the alpha channel of color
is 0, this function does nothing.
sourcepub fn stroke_outline<Unit>(
&mut self,
color: Color,
options: StrokeOptions<Unit>,
)where
Unit: ScreenScale<Px = Px, Lp = Lp, UPx = UPx> + Zero,
pub fn stroke_outline<Unit>(
&mut self,
color: Color,
options: StrokeOptions<Unit>,
)where
Unit: ScreenScale<Px = Px, Lp = Lp, UPx = UPx> + Zero,
Strokes an outline around this widget’s contents.
sourcepub fn draw_focus_ring(&mut self)
pub fn draw_focus_ring(&mut self)
Renders the default focus ring for this widget.
sourcepub fn current_font_settings(&self) -> FontSettings
pub fn current_font_settings(&self) -> FontSettings
Returns the widget context’s current font settings.
The settings returned are from retrieving the values of these style components:
The returned settings are not necessarily what is currently applied to
this graphics context. To apply these settings, consider using
Self::apply_current_font_settings()
or FontSettings::apply
.
sourcepub fn apply_current_font_settings(&mut self)
pub fn apply_current_font_settings(&mut self)
Applies the current style settings for font family, text size, font style, and font weight.
sourcepub fn redraw(&mut self)
pub fn redraw(&mut self)
Invokes Widget::redraw()
on this
context’s widget.
Methods from Deref<Target = 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 fn widget(&self) -> &MountedWidget
pub 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 fn window(&self) -> &dyn PlatformWindow
pub fn window(&self) -> &dyn PlatformWindow
Returns the window containing this widget.
sourcepub fn localizations(&self) -> &Localizations
pub fn localizations(&self) -> &Localizations
Returns the localizations for this application.
sourcepub fn window_mut(&mut self) -> &mut dyn PlatformWindow
pub 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 AsEventContext for GraphicsContext<'_, '_, '_, '_>
impl AsEventContext for GraphicsContext<'_, '_, '_, '_>
source§fn as_event_context(&mut self) -> EventContext<'_>
fn as_event_context(&mut self) -> EventContext<'_>
EventContext
.source§fn push_child(&mut self, child: WidgetInstance) -> MountedWidget
fn push_child(&mut self, child: WidgetInstance) -> MountedWidget
source§fn remove_child(&mut self, child: &MountedWidget)
fn remove_child(&mut self, child: &MountedWidget)
source§impl<'context> Deref for GraphicsContext<'context, '_, '_, '_>
impl<'context> Deref for GraphicsContext<'context, '_, '_, '_>
source§impl DerefMut for GraphicsContext<'_, '_, '_, '_>
impl DerefMut for GraphicsContext<'_, '_, '_, '_>
source§impl Drop for GraphicsContext<'_, '_, '_, '_>
impl Drop for GraphicsContext<'_, '_, '_, '_>
source§impl LocalizationContext for GraphicsContext<'_, '_, '_, '_>
impl LocalizationContext for GraphicsContext<'_, '_, '_, '_>
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, 'clip, 'gfx, 'pass> Freeze for GraphicsContext<'context, 'clip, 'gfx, 'pass>
impl<'context, 'clip, 'gfx, 'pass> !RefUnwindSafe for GraphicsContext<'context, 'clip, 'gfx, 'pass>
impl<'context, 'clip, 'gfx, 'pass> !Send for GraphicsContext<'context, 'clip, 'gfx, 'pass>
impl<'context, 'clip, 'gfx, 'pass> !Sync for GraphicsContext<'context, 'clip, 'gfx, 'pass>
impl<'context, 'clip, 'gfx, 'pass> Unpin for GraphicsContext<'context, 'clip, 'gfx, 'pass>
impl<'context, 'clip, 'gfx, 'pass> !UnwindSafe for GraphicsContext<'context, 'clip, 'gfx, 'pass>
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