[][src]Struct druid::PaintCtx

pub struct PaintCtx<'a, 'b, 'c> {
    pub render_ctx: &'a mut Piet<'c>,
    // some fields omitted
}

A context passed to paint methods of widgets.

Widgets paint their appearance by calling methods on the render_ctx, which PaintCtx derefs to for convenience. This struct is expected to grow, for example to include the "damage region" indicating that only a subset of the entire widget hierarchy needs repainting.

Fields

render_ctx: &'a mut Piet<'c>

The render context for actually painting.

Implementations

impl PaintCtx<'_, '_, '_>[src]

pub fn widget_id(&self) -> WidgetId[src]

get the WidgetId of the current widget.

pub fn window(&self) -> &WindowHandle[src]

Returns a reference to the current WindowHandle.

pub fn window_id(&self) -> WindowId[src]

Get the WindowId of the current window.

pub fn text(&mut self) -> &mut PietText[src]

Get an object which can create text layouts.

impl PaintCtx<'_, '_, '_>[src]

pub fn size(&self) -> Size[src]

The layout size.

This is the layout size as ultimately determined by the parent container, on the previous layout pass.

Generally it will be the same as the size returned by the child widget's layout method.

pub fn is_hot(&self) -> bool[src]

The "hot" (aka hover) status of a widget.

A widget is "hot" when the mouse is hovered over it. Widgets will often change their appearance as a visual indication that they will respond to mouse interaction.

The hot status is computed from the widget's layout rect. In a container hierarchy, all widgets with layout rects containing the mouse position have hot status.

Discussion: there is currently some confusion about whether a widget can be considered hot when some other widget is active (for example, when clicking to one widget and dragging to the next). The documentation should clearly state the resolution.

pub fn is_active(&self) -> bool[src]

The active status of a widget.

Active status generally corresponds to a mouse button down. Widgets with behavior similar to a button will call set_active on mouse down and then up.

When a widget is active, it gets mouse events even when the mouse is dragged away.

pub fn is_focused(&self) -> bool[src]

The focus status of a widget.

Returns true if this specific widget is focused. To check if any descendants are focused use has_focus.

Focus means that the widget receives keyboard events.

A widget can request focus using the request_focus method. It's also possible to register for automatic focus via register_for_focus.

If a widget gains or loses focus it will get a LifeCycle::FocusChanged event.

Only one widget at a time is focused. However due to the way events are routed, all ancestors of that widget will also receive keyboard events.

pub fn has_focus(&self) -> bool[src]

The (tree) focus status of a widget.

Returns true if either this specific widget or any one of its descendants is focused. To check if only this specific widget is focused use is_focused,

impl PaintCtx<'_, '_, '_>[src]

pub fn depth(&self) -> u32[src]

The depth in the tree of the currently painting widget.

This may be used in combination with paint_with_z_index in order to correctly order painting operations.

The depth here may not be exact; it is only guaranteed that a child will have a greater depth than its parent.

pub fn region(&self) -> &Region[src]

Returns the region that needs to be repainted.

pub fn with_child_ctx(
    &mut self,
    region: impl Into<Region>,
    f: impl FnOnce(&mut PaintCtx<'_, '_, '_>)
)
[src]

Creates a temporary PaintCtx with a new visible region, and calls the provided function with that PaintCtx.

This is used by containers to ensure that their children have the correct visible region given their layout.

pub fn with_save(&mut self, f: impl FnOnce(&mut PaintCtx<'_, '_, '_>))[src]

Saves the current context, executes the closures, and restores the context.

This is useful if you would like to transform or clip or otherwise modify the drawing context but do not want that modification to effect other widgets.

Examples

fn paint(&mut self, ctx: &mut PaintCtx, _data: &T, env: &Env) {
    let clip_rect = ctx.size().to_rect().inset(5.0);
    ctx.with_save(|ctx| {
        ctx.clip(clip_rect);
        ctx.stroke(clip_rect, &env.get(theme::PRIMARY_DARK), 5.0);
    });
}

pub fn paint_with_z_index(
    &mut self,
    z_index: u32,
    paint_func: impl FnOnce(&mut PaintCtx<'_, '_, '_>) + 'static
)
[src]

Allows to specify order for paint operations.

Larger z_index indicate that an operation will be executed later.

Methods from Deref<Target = Piet<'c>>

pub fn assert_finished(&mut self)

Check whether drawing operations have finished.

Clients should call this before extracting or presenting the contents of the drawing surface.

Trait Implementations

impl<'c> Deref for PaintCtx<'_, '_, 'c>[src]

type Target = Piet<'c>

The resulting type after dereferencing.

impl<'c> DerefMut for PaintCtx<'_, '_, 'c>[src]

Auto Trait Implementations

impl<'a, 'b, 'c> !RefUnwindSafe for PaintCtx<'a, 'b, 'c>[src]

impl<'a, 'b, 'c> !Send for PaintCtx<'a, 'b, 'c>[src]

impl<'a, 'b, 'c> !Sync for PaintCtx<'a, 'b, 'c>[src]

impl<'a, 'b, 'c> Unpin for PaintCtx<'a, 'b, 'c> where
    'b: 'a,
    'c: 'a, 
[src]

impl<'a, 'b, 'c> !UnwindSafe for PaintCtx<'a, 'b, 'c>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> RoundFrom<T> for T

impl<T, U> RoundInto<U> for T where
    U: RoundFrom<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.