[−][src]Struct druid::WidgetPod
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 druid events to regular events,
synthesize additional events of interest, and stop propagation when it makes sense.
This struct also contains the previous data for a widget, which is
essential for the update
method, both to decide when the update
needs to propagate, and to provide the previous data so that a
widget can process a diff between the old value and the new.
Implementations
impl<T, W: Widget<T>> WidgetPod<T, W>
[src]
pub fn new(inner: W) -> WidgetPod<T, W>
[src]
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.
pub fn is_active(&self) -> bool
[src]
Query the "active" state of the widget.
pub fn has_active(&self) -> bool
[src]
Returns true
if any descendant is active.
pub fn is_hot(&self) -> bool
[src]
Query the "hot" state of the widget.
See EventCtx::is_hot
for
additional information.
pub fn widget(&self) -> &W
[src]
Return a reference to the inner widget.
pub fn widget_mut(&mut self) -> &mut W
[src]
Return a mutable reference to the inner widget.
pub fn id(&self) -> WidgetId
[src]
Get the identity of the widget.
pub fn set_layout_rect(
&mut self,
ctx: &mut LayoutCtx,
data: &T,
env: &Env,
layout_rect: Rect
)
[src]
&mut self,
ctx: &mut LayoutCtx,
data: &T,
env: &Env,
layout_rect: Rect
)
Set the layout Rect
.
A container widget should call the Widget::layout
method on its children in
its own Widget::layout
implementation, then possibly modify the returned Size
, and
finally call this set_layout_rect
method on the child to set the final layout Rect
.
The child will receive the LifeCycle::Size
event informing them of the final Size
.
pub fn layout_rect(&self) -> Rect
[src]
Returns the layout Rect
.
This will be the same Rect
that was set by set_layout_rect
.
pub fn set_viewport_offset(&mut self, offset: Vec2)
[src]
Set the viewport offset.
This is relevant only for children of a scroll view (or similar). It must
be set by the parent widget whenever it modifies the position of its child
while painting it and propagating events. As a rule of thumb, you need this
if and only if you Affine::translate
the paint context before painting
your child. For an example, see the implentation of Scroll
.
pub fn viewport_offset(&self) -> Vec2
[src]
The viewport offset.
This will be the same value as set by set_viewport_offset
.
pub fn paint_rect(&self) -> Rect
[src]
Get the widget's paint Rect
.
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
.
pub fn paint_insets(&self) -> Insets
[src]
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.
pub fn compute_parent_paint_insets(&self, parent_size: Size) -> Insets
[src]
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
propogate a child's desired paint rect, if it extends beyond the bounds
of the parent's layout rect.
impl<T: Data, W: Widget<T>> WidgetPod<T, W>
[src]
pub fn paint_raw(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env)
[src]
Paint a child widget.
Generally called by container widgets as part of their Widget::paint
method.
Note that this method does not apply the offset of the layout rect.
If that is desired, use paint
instead.
pub fn paint(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env)
[src]
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 paint_always(&mut self, ctx: &mut PaintCtx, data: &T, env: &Env)
[src]
Paint the widget, even if its layout rect is outside of the currently visible region.
pub fn layout(
&mut self,
ctx: &mut LayoutCtx,
bc: &BoxConstraints,
data: &T,
env: &Env
) -> Size
[src]
&mut self,
ctx: &mut LayoutCtx,
bc: &BoxConstraints,
data: &T,
env: &Env
) -> Size
Compute layout of a widget.
Generally called by container widgets as part of their layout
method.
pub fn event(
&mut self,
ctx: &mut EventCtx,
event: &Event,
data: &mut T,
env: &Env
)
[src]
&mut self,
ctx: &mut EventCtx,
event: &Event,
data: &mut T,
env: &Env
)
Propagate an event.
Generally the event
method of a container widget will call this
method on all its children. Here is where a great deal of the event
flow logic resides, particularly whether to continue propagating
the event.
pub fn lifecycle(
&mut self,
ctx: &mut LifeCycleCtx,
event: &LifeCycle,
data: &T,
env: &Env
)
[src]
&mut self,
ctx: &mut LifeCycleCtx,
event: &LifeCycle,
data: &T,
env: &Env
)
pub fn update(&mut self, ctx: &mut UpdateCtx, data: &T, env: &Env)
[src]
Propagate a data update.
Generally called by container widgets as part of their update
method.
impl<T, W: Widget<T> + 'static> WidgetPod<T, W>
[src]
pub fn boxed(self) -> WidgetPod<T, Box<dyn Widget<T>>>
[src]
Box the contained widget.
Convert a WidgetPod
containing a widget of a specific concrete type
into a dynamically boxed widget.
Auto Trait Implementations
impl<T, W> !RefUnwindSafe for WidgetPod<T, W>
impl<T, W> !Send for WidgetPod<T, W>
impl<T, W> !Sync for WidgetPod<T, W>
impl<T, W> Unpin for WidgetPod<T, W> where
T: Unpin,
W: Unpin,
T: Unpin,
W: Unpin,
impl<T, W> !UnwindSafe for WidgetPod<T, W>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
fn round_into(self) -> U
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]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,