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>
impl<W: Widget> WidgetPod<W>
sourcepub fn new(inner: W) -> WidgetPod<W>
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.
sourcepub fn new_with_id(inner: W, id: WidgetId) -> WidgetPod<W>
pub fn new_with_id(inner: W, id: WidgetId) -> WidgetPod<W>
Create a new widget pod with fixed id.
sourcepub fn as_dyn(&self) -> WidgetRef<'_, dyn Widget>
pub fn as_dyn(&self) -> WidgetRef<'_, dyn Widget>
Return a type-erased WidgetRef
to the inner widget.
sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Return true
if the widget has received LifeCycle::WidgetAdded
.
sourcepub fn has_active(&self) -> bool
pub fn has_active(&self) -> bool
Return true
if any descendant is active.
sourcepub fn is_hot(&self) -> bool
pub fn is_hot(&self) -> bool
Query the “hot” state of the widget.
See EventCtx::is_hot
for additional information.
sourcepub fn layout_rect(&self) -> Rect
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.
sourcepub fn paint_rect(&self) -> Rect
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
.
sourcepub fn paint_insets(&self) -> Insets
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.
sourcepub fn compute_parent_paint_insets(&self, parent_size: Size) -> Insets
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.
sourcepub fn baseline_offset(&self) -> f64
pub fn baseline_offset(&self) -> f64
The distance from the bottom of this widget to the baseline.
source§impl<W: Widget> WidgetPod<W>
impl<W: Widget> WidgetPod<W>
sourcepub fn on_pointer_event(
&mut self,
parent_ctx: &mut EventCtx<'_>,
event: &PointerEvent
)
pub fn on_pointer_event( &mut self, parent_ctx: &mut EventCtx<'_>, event: &PointerEvent )
— ON_EVENT —
pub fn on_text_event( &mut self, parent_ctx: &mut EventCtx<'_>, event: &TextEvent )
pub fn on_access_event( &mut self, parent_ctx: &mut EventCtx<'_>, event: &AccessEvent )
sourcepub fn lifecycle(
&mut self,
parent_ctx: &mut LifeCycleCtx<'_>,
event: &LifeCycle
)
pub fn lifecycle( &mut self, parent_ctx: &mut LifeCycleCtx<'_>, event: &LifeCycle )
Propagate a LifeCycle
event.
sourcepub fn layout(
&mut self,
parent_ctx: &mut LayoutCtx<'_>,
bc: &BoxConstraints
) -> Size
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.
sourcepub fn paint(&mut self, parent_ctx: &mut PaintCtx<'_>, scene: &mut Scene)
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.
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> AsAny for Twhere
T: Any,
impl<T> AsAny for Twhere
T: Any,
source§fn as_dyn_any(&self) -> &(dyn Any + 'static)
fn as_dyn_any(&self) -> &(dyn Any + 'static)
source§fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)
fn as_mut_dyn_any(&mut self) -> &mut (dyn Any + 'static)
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§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
.source§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
.source§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.source§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.