Struct gooey::context::GraphicsContext
source · pub struct GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass> {
pub widget: WidgetContext<'context, 'window>,
pub gfx: Exclusive<'context, Graphics<'clip, 'gfx, 'pass>>,
}
Expand description
A context to a function that is rendering a widget.
Fields§
§widget: WidgetContext<'context, 'window>
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<'context, 'window, 'clip, 'gfx, 'pass> GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>
impl<'context, 'window, 'clip, 'gfx, 'pass> GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>
sourcepub fn borrowed(&mut self) -> GraphicsContext<'_, 'window, 'clip, 'gfx, 'pass>
pub fn borrowed(&mut self) -> GraphicsContext<'_, 'window, '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, 'window, 'child, 'gfx, 'pass>>>::Resultwhere
Widget: ManageWidget,
Widget::Managed: MapManagedWidget<GraphicsContext<'child, 'window, 'child, 'gfx, 'pass>>,
pub fn for_other<'child, Widget>(
&'child mut self,
widget: &Widget
) -> <Widget::Managed as MapManagedWidget<GraphicsContext<'child, 'window, 'child, 'gfx, 'pass>>>::Resultwhere
Widget: ManageWidget,
Widget::Managed: MapManagedWidget<GraphicsContext<'child, 'window, 'child, 'gfx, 'pass>>,
Returns a new GraphicsContext
that allows invoking graphics functions
for widget
.
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<'_, 'window, '_, 'gfx, 'pass>
pub fn clipped_to( &mut self, clip: Rect<Px> ) -> GraphicsContext<'_, 'window, '_, '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 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.
Panics
This function panics if the widget being drawn has no layout set (via
LayoutContext::set_child_layout()
).
Methods from Deref<Target = WidgetContext<'context, 'window>>§
sourcepub fn borrowed(&mut self) -> WidgetContext<'_, 'window>
pub fn borrowed(&mut self) -> WidgetContext<'_, 'window>
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, 'window>>>::Result
pub fn for_other<'child, Widget>( &'child mut self, widget: &Widget ) -> <Widget::Managed as MapManagedWidget<WidgetContext<'child, 'window>>>::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(&self, theme_mode: Value<ThemeMode>)
pub fn attach_theme_mode(&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 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) -> &RunningWindow<'window>
pub fn window(&self) -> &RunningWindow<'window>
Returns the window containing this widget.
sourcepub fn window_mut(&mut self) -> &mut RunningWindow<'window>
pub fn window_mut(&mut self) -> &mut RunningWindow<'window>
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 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.
Methods from Deref<Target = RunningWindow<'window>>§
sourcepub fn focused(&self) -> &Dynamic<bool>
pub fn focused(&self) -> &Dynamic<bool>
Returns a dynamic that is updated whenever this window’s focus status changes.
sourcepub fn occluded(&self) -> &Dynamic<bool>
pub fn occluded(&self) -> &Dynamic<bool>
Returns a dynamic that is updated whenever this window’s occlusion status changes.
sourcepub fn request_close(&self)
pub fn request_close(&self)
Request that the window closes.
A window may disallow itself from being closed by customizing
WindowBehavior::close_requested
.
sourcepub fn handle(&self) -> WindowHandle
pub fn handle(&self) -> WindowHandle
Returns a handle to this window.
sourcepub fn inner_size(&self) -> &Dynamic<Size<UPx>>
pub fn inner_size(&self) -> &Dynamic<Size<UPx>>
Returns a dynamic that is synchronized with this window’s inner size.
Whenever the window is resized, this dynamic will be updated with the new inner size. Setting a new value will request the new size from the operating system, but resize requests may be altered or ignored by the operating system.
sourcepub fn clipboard_guard(&self) -> Option<MutexGuard<'_, Clipboard>>
pub fn clipboard_guard(&self) -> Option<MutexGuard<'_, Clipboard>>
Returns a locked mutex guard to the OS’s clipboard, if one was able to be initialized when the window opened.
Methods from Deref<Target = Window<'window, WindowCommand>>§
sourcepub fn handle(&self) -> WindowHandle<WindowEvent>
pub fn handle(&self) -> WindowHandle<WindowEvent>
Returns a handle to this window, which can be used to send
WindowEvent
s to it.
sourcepub fn app(&self) -> App<AppEvent<WindowEvent>>
pub fn app(&self) -> App<AppEvent<WindowEvent>>
Returns a handle to the application.
This is useful for opening additional windows in a multi-window application.
sourcepub fn set_position(&self, position: Point<Px>)
pub fn set_position(&self, position: Point<Px>)
Sets the current position of the window.
sourcepub fn inner_size(&self) -> Size<UPx>
pub fn inner_size(&self) -> Size<UPx>
Returns the inner size of the window.
sourcepub fn set_inner_size(&self, inner_size: Size<UPx>)
pub fn set_inner_size(&self, inner_size: Size<UPx>)
Sets the inner size of the window.
sourcepub fn focused(&self) -> bool
pub fn focused(&self) -> bool
Returns true if the window is currently focused for keyboard input.
sourcepub fn ocluded(&self) -> bool
pub fn ocluded(&self) -> bool
Returns true if the window is currenly not visible because it is completely hidden behind other windows, offcreen, or minimized.
sourcepub fn set_ime_allowed(&self, allowed: bool)
pub fn set_ime_allowed(&self, allowed: bool)
Sets whether IME input is allowed on the window.
sourcepub fn set_ime_purpose(&self, purpose: ImePurpose)
pub fn set_ime_purpose(&self, purpose: ImePurpose)
Sets the IME purpose.
sourcepub fn set_ime_cursor_area(&self, area: Rect<UPx>)
pub fn set_ime_cursor_area(&self, area: Rect<UPx>)
Sets the cursor area for IME input suggestions.
sourcepub fn redraw_in(&mut self, duration: Duration)
pub fn redraw_in(&mut self, duration: Duration)
Sets the window to redraw after a duration
.
If the window is already set to redraw sooner, this function does nothing.
sourcepub fn redraw_at(&mut self, time: Instant)
pub fn redraw_at(&mut self, time: Instant)
Sets the window to redraw at the provided time.
If the window is already set to redraw sooner, this function does nothing.
sourcepub fn set_needs_redraw(&mut self)
pub fn set_needs_redraw(&mut self)
Sets the window to redraw as soon as it can.
sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Returns the duration that has elapsed since the last frame start and the current frame start.
This value is calculated once per frame and will not update between calls within the same event.
sourcepub fn last_frame_rendered_in(&self) -> Duration
pub fn last_frame_rendered_in(&self) -> Duration
Returns the duration taken between when the last frame’s redraw started and when the surface’s frame was presented.
sourcepub fn cursor_position(&self) -> Option<Point<Px>>
pub fn cursor_position(&self) -> Option<Point<Px>>
Returns the position of the mouse cursor within this window, if the cursor is currently above the window.
Returns true if the given button is currently pressed.
sourcepub fn key_pressed(&self, key: impl Into<PhysicalKey>) -> bool
pub fn key_pressed(&self, key: impl Into<PhysicalKey>) -> bool
Returns true if the given virtual key code is currently pressed.
sourcepub fn set_min_inner_size(&self, min_size: Option<Size<UPx>>)
pub fn set_min_inner_size(&self, min_size: Option<Size<UPx>>)
Sets the window’s minimum inner size.
sourcepub fn set_max_inner_size(&self, max_size: Option<Size<UPx>>)
pub fn set_max_inner_size(&self, max_size: Option<Size<UPx>>)
Sets the window’s maximum inner size.
Trait Implementations§
source§impl<'window> AsEventContext<'window> for GraphicsContext<'_, 'window, '_, '_, '_>
impl<'window> AsEventContext<'window> for GraphicsContext<'_, 'window, '_, '_, '_>
source§fn as_event_context(&mut self) -> EventContext<'_, 'window>
fn as_event_context(&mut self) -> EventContext<'_, 'window>
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, 'window, 'clip, 'gfx, 'pass> Deref for GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>
impl<'context, 'window, 'clip, 'gfx, 'pass> Deref for GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>
source§impl<'context, 'window, 'clip, 'gfx, 'pass> DerefMut for GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>
impl<'context, 'window, 'clip, 'gfx, 'pass> DerefMut for GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>
Auto Trait Implementations§
impl<'context, 'window, 'clip, 'gfx, 'pass> !RefUnwindSafe for GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>
impl<'context, 'window, 'clip, 'gfx, 'pass> Send for GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>
impl<'context, 'window, 'clip, 'gfx, 'pass> !Sync for GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>
impl<'context, 'window, 'clip, 'gfx, 'pass> Unpin for GraphicsContext<'context, 'window, 'clip, 'gfx, 'pass>
impl<'context, 'window, 'clip, 'gfx, 'pass> !UnwindSafe for GraphicsContext<'context, 'window, '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<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.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§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<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> 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
.source§impl<'a, T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<'a, T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
§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