Skip to main content

PaintCtx

Struct PaintCtx 

Source
pub struct PaintCtx<'a> { /* private fields */ }
Expand description

A context passed to Widget::paint method.

Implementations§

Source§

impl PaintCtx<'_>

Source

pub fn widget_id(&self) -> WidgetId

The WidgetId of the current widget.

Source

pub fn transform(&self) -> Affine

The current (local) transform of this widget.

Source§

impl PaintCtx<'_>

Source

pub fn text_contexts( &mut self, ) -> (&mut FontContext, &mut LayoutContext<BrushIndex>)

Get the Parley contexts needed to build and paint text sections.

Most users should embed a pre-built label widget (such as masonry::widgets::Label) as a child for non-interactive text. These contexts could however be useful for custom text editing, such as for rich text editing.

Any cached text layouts should be invalidated in the layout pass when Self::fonts_changed returns true.

Source

pub fn fonts_changed(&mut self) -> bool

Whether the set of loaded fonts has changed since layout was most recently called.

Any cached text layouts should be invalidated in the layout pass when this is true.

Source§

impl PaintCtx<'_>

Source

pub fn size(&self) -> Size

The layout size.

This is roughly the layout size returned by the layout method on the previous layout pass, with some adjustment for pixel snapping.

Source

pub fn baseline_offset(&self) -> f64

The offset of the baseline relative to the bottom of the widget.

Source

pub fn window_origin(&self) -> Point

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

Source

pub fn window_transform(&self) -> Affine

Global transform of this widget in the window coordinate space.

Computed from all transform and scroll_translation values from this to the root widget.

Source

pub fn bounding_rect(&self) -> Rect

The bounding rect of the widget in window coordinates.

See bounding rect documentation for details.

Source

pub fn paint_rect(&self) -> Rect

The paint rect of the widget.

Covers the area we expect to be invalidated when the widget is painted.

Source

pub fn clip_path(&self) -> Option<Rect>

The clip path of the widget, if any was set.

For more information, see LayoutCtx::set_clip_path.

Source

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.

Source§

impl PaintCtx<'_>

Source

pub fn get_scale_factor(&self) -> f64

Get DPI scaling factor.

This is not required for most widgets, and should be used only for precise rendering, such as rendering single pixel lines or selecting image variants. This is currently only provided in the render stages, as these are the only passes which are re-run when the scale factor changes, except EventCtx where it is necessary to translate pointer events which are currently in physical coordinates.

Note that accessibility nodes and paint results will automatically be scaled by Masonry. This also doesn’t account for the widget’s current transform, which cannot currently be accessed by widgets directly.

Source§

impl PaintCtx<'_>

Source

pub fn is_hovered(&self) -> bool

The “hovered” status of a widget.

A widget is “hovered” when a pointer is hovering over it. Widgets will often change their appearance as a visual indication that they will respond to pointer (usually mouse) interaction.

If the pointer is captured, then only the capturing widget can have hovered status. If the pointer is captured but not hovering over the captured widget, then no widget has the hovered status.

Source

pub fn has_hovered(&self) -> bool

Whether this widget or any of its descendants are hovered.

To check if only this specific widget is hovered use is_hovered.

Source

pub fn is_active(&self) -> bool

The “active” status of a widget.

A widget is “active” when the user is “actively” interacting with it. Currently, a widget is determined to be active when it has captured a pointer, but this may change in the future to account for e.g. keyboard interactions.

Source

pub fn has_active(&self) -> bool

Whether this widget or any of its descendants are active.

To check if only this specific widget is active use is_active.

Source

pub fn is_pointer_capture_target(&self) -> bool

Whether a pointer is captured by this widget.

The pointer will usually be the mouse. In future versions, this function will take a pointer id as input to test a specific pointer.

Source

pub fn is_focus_target(&self) -> bool

The text focus status of a widget.

The focused widget is the one that receives keyboard events.

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

Source

pub fn has_focus_target(&self) -> bool

Whether this widget or any of its descendants are focused.

To check if only this specific widget is focused use is_focus_target.

Source

pub fn is_window_focused(&self) -> bool

Whether the window is focused.

Source

pub fn accepts_pointer_interaction(&self) -> bool

Whether this widget gets pointer events and hovered status.

Source

pub fn accepts_focus(&self) -> bool

Whether this widget gets text focus.

Source

pub fn accepts_text_input(&self) -> bool

Whether this widget gets IME events.

Source

pub fn is_disabled(&self) -> bool

Whether this widget is disabled.

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

Source

pub fn is_stashed(&self) -> bool

Whether this widget is stashed.

Source§

impl PaintCtx<'_>

Source

pub fn debug_paint_enabled(&self) -> bool

Whether debug paint is enabled.

If this property is set, your widget may draw additional debug information (such as the position of the text baseline). These should normally use the debug color for this widget. Please note that when debug painting is enabled, each widget’s layout boundaries are outlined by Masonry, so you should avoid duplicating that.

Debug paint can be enabled by setting the environment variable MASONRY_DEBUG_PAINT.

Source

pub fn debug_color(&self) -> Color

A color used for debug painting in this widget.

This is normally used to paint additional debugging information when debug paint is enabled, see Self::debug_paint_enabled.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for PaintCtx<'a>

§

impl<'a> !Send for PaintCtx<'a>

§

impl<'a> !Sync for PaintCtx<'a>

§

impl<'a> !UnwindSafe for PaintCtx<'a>

§

impl<'a> Freeze for PaintCtx<'a>

§

impl<'a> Unpin for PaintCtx<'a>

§

impl<'a> UnsafeUnpin for PaintCtx<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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 T
where U: From<T>,

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.

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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