pub struct PaintCtx<'a, 'b, 'c> {
    pub render_ctx: &'a mut CairoRenderContext<'c>,
    /* private fields */
}
Expand description

A context passed to paint methods of widgets.

In addition to the API below, PaintCtx derefs to an implementation of the RenderContext trait, which defines the basic available drawing commands.

Fields§

§render_ctx: &'a mut CairoRenderContext<'c>

The render context for actually painting.

Implementations§

§

impl PaintCtx<'_, '_, '_>

pub fn widget_id(&self) -> WidgetId

get the WidgetId of the current widget.

pub fn window(&self) -> &WindowHandle

Returns a reference to the current WindowHandle.

pub fn window_id(&self) -> WindowId

Get the WindowId of the current window.

pub fn text(&mut self) -> &mut CairoText

Get an object which can create text layouts.

pub fn scale(&self) -> Scale

The current window’s Scale.

The returned Scale is a copy and thus its information will be stale after the platform changes the window’s scale. This means you can only rely on it until the next Event::WindowScale event happens.

§

impl PaintCtx<'_, '_, '_>

pub fn size(&self) -> Size

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 window_origin(&self) -> Point

The origin of the widget in window coordinates, relative to the top left corner of the content area.

pub fn to_window(&self, widget_point: Point) -> Point

Convert a point from the widget’s coordinate space to the window’s.

The returned point is relative to the content area; it excludes window chrome.

pub fn to_screen(&self, widget_point: Point) -> Point

Convert a point from the widget’s coordinate space to the screen’s. See the Screen module

pub fn is_hot(&self) -> bool

Query the “hot” state of the widget.

See WidgetPod::is_hot for additional information.

pub fn is_active(&self) -> bool

Query the “active” state of the widget.

See WidgetPod::is_active for additional information.

pub fn is_focused(&self) -> bool

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

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,

pub fn is_disabled(&self) -> bool

The disabled state of a widget.

Returns true if this widget or any of its ancestors is explicitly disabled. To make this widget explicitly disabled use set_disabled.

Disabled means that this widget should not change the state of the application. What that means is not entirely clear but in any it should not change its data. Therefore others can use this as a safety mechanism to prevent the application from entering an illegal state. For an example the decrease button of a counter of type usize should be disabled if the value is 0.

§

impl PaintCtx<'_, '_, '_>

pub fn depth(&self) -> u32

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

Returns the region that needs to be repainted.

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

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<'_, '_, '_>))

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 )

Allows to specify order for paint operations.

Larger z_index indicate that an operation will be executed later.

Trait Implementations§

§

impl<'c> Deref for PaintCtx<'_, '_, 'c>

§

type Target = CairoRenderContext<'c>

The resulting type after dereferencing.
§

fn deref(&self) -> &<PaintCtx<'_, '_, 'c> as Deref>::Target

Dereferences the value.
§

impl<'c> DerefMut for PaintCtx<'_, '_, 'c>

§

fn deref_mut(&mut self) -> &mut <PaintCtx<'_, '_, 'c> as Deref>::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> RoundFrom<T> for T

§

fn round_from(x: T) -> T

Performs the conversion.
§

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

§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more