pub struct StyledContainer { /* private fields */ }Implementations§
Source§impl StyledContainer
impl StyledContainer
pub fn new( layout_style: LayoutStyle, style: impl Fn(Rect) -> RectStyle + 'static, children: Vec<Box<dyn LayoutItem>>, ) -> Result<Self, LayoutError>
Sourcepub fn from_slots(
layout_style: LayoutStyle,
style: impl Fn(Rect) -> RectStyle + 'static,
slots: Vec<ChildSlot>,
) -> Result<Self, LayoutError>
pub fn from_slots( layout_style: LayoutStyle, style: impl Fn(Rect) -> RectStyle + 'static, slots: Vec<ChildSlot>, ) -> Result<Self, LayoutError>
A styled box whose children are a mix of static widgets and reactive fragments (ChildSlots),
reconciled into this box’s own node so they inherit its flex direction/gap — the transparent
box-with-a-for path (see Container::from_slots).
pub fn with_opacity(self, opacity: impl Fn() -> f32 + 'static) -> Self
Sourcepub fn with_transform(
self,
transform: impl Fn(Rect) -> Option<[f32; 6]> + 'static,
) -> Self
pub fn with_transform( self, transform: impl Fn(Rect) -> Option<[f32; 6]> + 'static, ) -> Self
Apply an affine transform (rotate/scale/translate) to the whole box each view(). The closure
takes the laid-out rect and returns the 2×3 matrix, or None for identity.
Sourcepub fn on_hover_style(self, f: impl Fn(Rect) -> RectStyle + 'static) -> Self
pub fn on_hover_style(self, f: impl Fn(Rect) -> RectStyle + 'static) -> Self
Paint the box with f while the mouse hovers it (a declarative style swap, like Button).
Hover is mouse-only; touch never sets it, so a tap leaves no stuck hover state.
Sourcepub fn on_active_style(self, f: impl Fn(Rect) -> RectStyle + 'static) -> Self
pub fn on_active_style(self, f: impl Fn(Rect) -> RectStyle + 'static) -> Self
Paint the box with f while a primary pointer is held down inside it — the pressed / CSS :active
state, which takes precedence over on_hover_style. Unlike hover it tracks touch as well as mouse,
and it clears on release, on leaving the box, or once the press drags off, so it never sticks.
Sourcepub fn keeping(self, subscription: Effect) -> Self
pub fn keeping(self, subscription: Effect) -> Self
Give this widget ownership of an Effect, so it runs for exactly as long as the widget exists.
The reactive runtime scopes an effect to the surface it was registered on, which is the right span for a shell-wide subscription and far too coarse for one row of a list: the row goes, the effect stays, and it keeps firing at a node that is gone. Dropping the handle instead is the opposite failure — the effect deregisters, runs once, and stops, with nothing to say so. This is the third answer, and the one an effect that belongs to a widget wants.
Chainable, so several effects can be kept without nesting anything.
Sourcepub fn styled_by(self, style: impl Fn() -> LayoutStyle + 'static) -> Self
pub fn styled_by(self, style: impl Fn() -> LayoutStyle + 'static) -> Self
Keeps the box’s layout style in step with the reactive state it was built from — the theme’s metric
tokens, today. style runs now, and again whenever a signal it read changes; the node is restyled in
place, so a live theme switch re-spaces the box as well as re-colouring it.
Paint needs nothing like this: a rect or text style is a closure the renderer re-runs every frame, so a token read inside one is already live. A layout style is a value, handed to the layout tree once when the node is made — which is why the reactive read has to be arranged here rather than coming for free.
Give new the same builder, so the node starts at the style it will settle on:
StyledContainer::new(shell(), paint, kids)?.styled_by(shell).
Sourcepub fn on_press(self, f: impl Fn() + 'static) -> Self
pub fn on_press(self, f: impl Fn() + 'static) -> Self
Make the box itself pressable. The callback fires on a tap (release, not press) inside the box; a child widget that handles the press wins, and a scroll gesture started on the box does not fire it.
Sourcepub fn maybe_on_press(self, f: Option<impl Fn() + 'static>) -> Self
pub fn maybe_on_press(self, f: Option<impl Fn() + 'static>) -> Self
on_press for a handler the caller may not have supplied.
What a wrapper component needs to forward an optional callback. A box whose press handler is a no-op
still reports the tap Handled, so “no handler” would become “swallows the click” — a display-only chip
eating a press instead of letting it through. None leaves the box exactly as it was; the maybe_*
pairs below say the same for every other event whose absence the box can observe.
Sourcepub fn on_alt_press(self, f: impl Fn(PointerButton) + 'static) -> Self
pub fn on_alt_press(self, f: impl Fn(PointerButton) + 'static) -> Self
Fire f(button) on a tap with a non-primary button — Secondary (right) or Auxiliary (middle).
Same tap-on-release semantics as Self::on_press: a child that handles the press wins, and travel
past the tap slop cancels it.
Opt-in per box rather than folded into on_press, because a non-primary press otherwise falls through
to whatever is behind it — silently swallowing right-clicks on every pressable box would break that.
Sourcepub fn on_long_press(self, f: impl Fn() + 'static) -> Self
pub fn on_long_press(self, f: impl Fn() + 'static) -> Self
Fires once a press inside the box is held past ~500ms without moving past the tap slop, instead of
on_press’s tap-on-release. There is no dedicated timer in the gesture pipeline, so the threshold is
only checked on the next pointer event after the press (a move or the release) — it fires slightly
late, never at exactly 500ms, and a release before that next check-in is a normal tap.
Sourcepub fn maybe_on_long_press(self, f: Option<impl Fn() + 'static>) -> Self
pub fn maybe_on_long_press(self, f: Option<impl Fn() + 'static>) -> Self
on_long_press for a handler the caller may not have supplied.
Sourcepub fn on_drag_end(self, f: impl Fn(f32, f32) + 'static) -> Self
pub fn on_drag_end(self, f: impl Fn(f32, f32) + 'static) -> Self
Make the box draggable. The callback fires with the pointer position (layout space) on a press
inside the box and on every move until release — even after the pointer leaves the box. Map the
coordinate to a value (slider) or an offset (reorder/resize).
Fires once when a drag started on this box ends, with the position it finished at (layout space, local
to the box, same as on_drag).
This is what makes a threshold gesture expressible: on_drag alone reports where the pointer is but
never that it let go, so a swipe-to-dismiss or a drag-to-open can be tracked and never decided. A drag
also ends when the pointer leaves the window or a child consumes the release; those carry no position,
so the last one the drag reached is reported instead — the gesture always ends exactly once.
Sourcepub fn maybe_on_drag_end(self, f: Option<impl Fn(f32, f32) + 'static>) -> Self
pub fn maybe_on_drag_end(self, f: Option<impl Fn(f32, f32) + 'static>) -> Self
on_drag_end for a handler the caller may not have supplied.
pub fn on_drag(self, f: impl Fn(f32, f32) + 'static) -> Self
Sourcepub fn maybe_on_drag(self, f: Option<impl Fn(f32, f32) + 'static>) -> Self
pub fn maybe_on_drag(self, f: Option<impl Fn(f32, f32) + 'static>) -> Self
on_drag for a handler the caller may not have supplied.
Sourcepub fn on_hover(self, f: impl Fn(bool) + 'static) -> Self
pub fn on_hover(self, f: impl Fn(bool) + 'static) -> Self
Fire f(true) when the mouse enters the box and f(false) when it leaves (mouse only). Independent
of on_hover_style: a box can observe hover without swapping its paint.
Registers the box as a pointer target, like on_scroll does for the same reason: a
surface that carves its input region from its content (a click-through overlay) never receives a move
event over a box it left out of that region, so a hover it did not register is a hover it can’t observe.
Sourcepub fn maybe_on_hover(self, f: Option<impl Fn(bool) + 'static>) -> Self
pub fn maybe_on_hover(self, f: Option<impl Fn(bool) + 'static>) -> Self
on_hover for a handler the caller may not have supplied.
Sourcepub fn on_scroll(self, f: impl Fn(f32, f32) + 'static) -> Self
pub fn on_scroll(self, f: impl Fn(f32, f32) + 'static) -> Self
Fire f(dx, dy) with the wheel delta while the mouse is over the box — scroll-to-adjust on a control
(a volume or brightness chip, a stepper). Deltas are normalised to pixels, matching
ScrollArea: a line delta counts as 20px, so one wheel notch is roughly ±60.
Scroll events carry no pointer position, so the box’s hover state is what targets them; this enables
hover tracking on its own, without needing an on_hover_style. A scrollable child (a scroll area
inside the box) hit-tests first and keeps the event.
Sourcepub fn maybe_on_scroll(self, f: Option<impl Fn(f32, f32) + 'static>) -> Self
pub fn maybe_on_scroll(self, f: Option<impl Fn(f32, f32) + 'static>) -> Self
on_scroll for a handler the caller may not have supplied.
Sourcepub fn on_key(self, f: impl Fn(&Key) + 'static) -> Self
pub fn on_key(self, f: impl Fn(&Key) + 'static) -> Self
Fire f(&key) on every key press. This is a GLOBAL handler (key events reach every widget; there is
no per-widget focus), so it suits app-level shortcuts, not focused text entry.
Sourcepub fn maybe_on_key(self, f: Option<impl Fn(&Key) + 'static>) -> Self
pub fn maybe_on_key(self, f: Option<impl Fn(&Key) + 'static>) -> Self
on_key for a handler the caller may not have supplied.
Sourcepub fn on_focus(self, f: impl Fn(bool) + 'static) -> Self
pub fn on_focus(self, f: impl Fn(bool) + 'static) -> Self
Make the box focusable and fire f(true)/f(false) when it gains/loses keyboard focus. It joins
the tab order (Tab/Shift-Tab reach it) and takes focus on tap. Use it to drive a focus ring or to
build a custom focusable widget on top of a box.