Struct druid::WidgetPod

source ·
pub struct WidgetPod<T, 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 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§

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.

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

Returns true if widget or any descendent is focused

The “active” (aka pressed) status of a widget.

Active status generally corresponds to a mouse button down. Widgets with behavior similar to a button will call set_active on mouse down and then up.

The active status can only be set manually. Druid doesn’t automatically set it to false on mouse release or anything like that.

There is no special handling of the active status for multi-pointer devices.

When a widget is active, it gets mouse events even when the mouse is dragged away.

Returns true if any descendant is active.

The “hot” (aka hover) status of a widget.

A widget is “hot” when the mouse is hovered over it. Some Widgets (eg buttons) will change their appearance when hot as a visual indication that they will respond to mouse interaction.

The hot status is automatically computed from the widget’s layout rect. In a container hierarchy, all widgets with layout rects containing the mouse position have hot status. The hot status cannot be set manually.

There is no special handling of the hot status for multi-pointer devices.

Note: a widget can be hot while another is active (for example, when clicking a button and dragging the cursor to another widget).

Get the identity of the widget.

This widget or any of its children have requested layout.

Set the origin of this widget, in the parent’s coordinate space.

A container widget should call the [Widget::layout] method on its children in its own [Widget::layout] implementation, and then call set_origin to position those children.

The changed origin won’t be fully in effect until LifeCycle::ViewContextChanged has finished propagating. Specifically methods that depend on the widget’s origin in relation to the window will return stale results during the period after calling set_origin but before LifeCycle::ViewContextChanged has finished propagating.

The widget container can also call set_origin from other context, but calling set_origin after the widget received LifeCycle::ViewContextChanged and before the next event results in an inconsistent state of the widget tree.

The child will receive the LifeCycle::Size event informing them of the final Size.

Returns the layout Rect.

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

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.

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.

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.

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

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.

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.

Paint the widget, even if its layout rect is outside of the currently visible region.

Compute layout of a widget.

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

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.

Propagate a LifeCycle event.

Propagate a data update.

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

Box the contained widget.

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

Return a reference to the inner widget.

Return a mutable reference to the inner widget.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Calls U::from(self).

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

Performs the conversion.
Performs the conversion.
Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more