Struct masonry::widget::WidgetPod

source ·
pub struct WidgetPod<W> { /* private fields */ }
Expand description

A container for one widget in the hierarchy.

Generally, container widgets don’t contain other widgets directly, but rather contain a WidgetPod, which has additional state needed for layout and for the widget to participate in event flow.

WidgetPod will translate internal Masonry events to regular events, synthesize additional events of interest, and stop propagation when it makes sense.

Implementations§

source§

impl<W: Widget> WidgetPod<W>

source

pub fn new(inner: W) -> WidgetPod<W>

Create a new widget pod.

In a widget hierarchy, each widget is wrapped in a WidgetPod so it can participate in layout and event flow. The process of adding a child widget to a container should call this method.

source

pub fn new_with_id(inner: W, id: WidgetId) -> WidgetPod<W>

Create a new widget pod with fixed id.

source

pub fn widget(&self) -> &W

Return a reference to the inner widget.

source

pub fn as_ref(&self) -> WidgetRef<'_, W>

Return a WidgetRef to the inner widget.

source

pub fn as_dyn(&self) -> WidgetRef<'_, dyn Widget>

Return a type-erased WidgetRef to the inner widget.

source

pub fn is_initialized(&self) -> bool

Return true if the widget has received LifeCycle::WidgetAdded.

source

pub fn has_focus(&self) -> bool

Return true if widget or any descendent is focused

source

pub fn is_active(&self) -> bool

Query the “active” state of the widget.

source

pub fn has_active(&self) -> bool

Return true if any descendant is active.

source

pub fn is_hot(&self) -> bool

Query the “hot” state of the widget.

See EventCtx::is_hot for additional information.

source

pub fn id(&self) -> WidgetId

Get the identity of the widget.

source

pub fn layout_rect(&self) -> Rect

Return the layout rectangle.

This will be a Rect with a Size determined by the child’s layout method, and the origin that was set by place_child.

Two sibling widgets’ layout rects will almost never intersect.

This rect will also be used to detect whether any given pointer event (eg clicks) intersects with the rectangle.

source

pub fn paint_rect(&self) -> Rect

Get the widget’s paint rectangle.

This is the Rect that widget has indicated it needs to paint in. This is the same as the layout_rect with the paint_insets applied; in the general case it is the same as the layout_rect.

source

pub fn paint_insets(&self) -> Insets

Return the paint Insets for this widget.

If these Insets are nonzero, they describe the area beyond a widget’s layout rect where it needs to paint.

These are generally zero; exceptions are widgets that do things like paint a drop shadow.

A widget can set its insets by calling set_paint_insets during its layout method.

source

pub fn compute_parent_paint_insets(&self, parent_size: Size) -> Insets

Given a parents layout size, determine the appropriate paint Insets for the parent.

This is a convenience method to be used from the layout method of a Widget that manages a child; it allows the parent to correctly propagate a child’s desired paint rect, if it extends beyond the bounds of the parent’s layout rect.

source

pub fn baseline_offset(&self) -> f64

The distance from the bottom of this widget to the baseline.

source§

impl<W: Widget + 'static> WidgetPod<W>

source

pub fn boxed(self) -> WidgetPod<Box<dyn Widget>>

Box the contained widget.

Convert a WidgetPod containing a widget of a specific concrete type into a dynamically boxed widget.

source§

impl<W: Widget> WidgetPod<W>

source

pub fn on_pointer_event( &mut self, parent_ctx: &mut EventCtx<'_>, event: &PointerEvent )

— ON_EVENT —

source

pub fn on_text_event( &mut self, parent_ctx: &mut EventCtx<'_>, event: &TextEvent )

source

pub fn on_access_event( &mut self, parent_ctx: &mut EventCtx<'_>, event: &AccessEvent )

source

pub fn lifecycle( &mut self, parent_ctx: &mut LifeCycleCtx<'_>, event: &LifeCycle )

Propagate a LifeCycle event.

source

pub fn layout( &mut self, parent_ctx: &mut LayoutCtx<'_>, bc: &BoxConstraints ) -> Size

Compute layout of a widget.

Generally called by container widgets as part of their layout method.

source

pub fn paint(&mut self, parent_ctx: &mut PaintCtx<'_>, scene: &mut Scene)

Paint the widget, translating it by the origin of its layout rectangle.

This will recursively paint widgets, stopping if a widget’s layout rect is outside of the currently visible region.

source

pub fn accessibility(&mut self, parent_ctx: &mut AccessCtx<'_>)

Auto Trait Implementations§

§

impl<W> !Freeze for WidgetPod<W>

§

impl<W> !RefUnwindSafe for WidgetPod<W>

§

impl<W> Send for WidgetPod<W>
where W: Send,

§

impl<W> Sync for WidgetPod<W>
where W: Sync,

§

impl<W> Unpin for WidgetPod<W>
where W: Unpin,

§

impl<W> !UnwindSafe for WidgetPod<W>

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> AsAny for T
where T: Any,

source§

fn as_dyn_any(&self) -> &(dyn Any + 'static)

Return self.
source§

fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)

Return self.
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> 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>,

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T

source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,