pub struct Expand { /* private fields */ }Expand description
Layout modifier that claims space along one or both axes from its parent and stretches its child to fill it.
In an HStack / VStack, Expand participates in flex slack
distribution: it returns a LayoutResponse with flex (default 1.0),
so the parent stack hands it a share of the leftover space proportional
to flex. Default basis is zero — the wrapped child’s natural size
does NOT count in the rigid pool, which gives clean ratio layouts. Call
Expand::respect_intrinsic to switch to auto basis (CSS
flex-basis: auto), where the child’s natural size acts as a floor and
flex adds slack on top.
Expand::new() is the common case: claim space, fill the child.
Use .flex(n) to change the ratio (e.g. 1:2 by pairing flex(1) with
flex(2)). Use .align_child(...) to opt out of fill and align the
child at its natural size within the claimed bounds.
horizontal() / vertical() semantics. The named axis is the one
the wrapper competes for slack on. Both sizing and flex behavior
follow from that:
-
Sizing: when the parent binds an axis (
proposal.{axis} = Some), the wrapper claims that axis regardless of its name. SoExpand::vertical(child)inside aVStack(which binds width and leaves height open) fills the VStack’s full width AND distributes vertical slack via flex. Cross-axis collapse to child intrinsic only happens when the parent left that axis open too. -
Flex contribution: the wrapper reports its
flexweight only on axes the parent is distributing (i.e. left open).Expand::horizontal()inside aVStackreportsflex = 0on the open vertical axis, so it does NOT compete for vertical slack with siblings — it just claims the cross-axis width and sits at its child’s intrinsic height. Symmetric forExpand::vertical()inside anHStack.
Implementations§
Source§impl Expand
impl Expand
Sourcepub fn horizontal() -> Self
pub fn horizontal() -> Self
Compete for slack on the horizontal axis only. Inside an HStack,
distributes flex on width while claiming bound height as-is. Inside
a VStack (which binds width and distributes height), claims the
VStack’s full width but reports flex = 0 so it doesn’t steal
vertical slack from siblings — height stays at child intrinsic.
Sourcepub fn vertical() -> Self
pub fn vertical() -> Self
Compete for slack on the vertical axis only. Inside a VStack,
distributes flex on height while claiming bound width as-is. Inside
an HStack (which binds height and distributes width), claims the
HStack’s full height but reports flex = 0 so it doesn’t steal
horizontal slack from siblings — width stays at child intrinsic.
Sourcepub fn flex(self, flex: f32) -> Self
pub fn flex(self, flex: f32) -> Self
Override the flex weight reported to a parent stack. flex(0) opts
out of slack distribution (the wrapper still claims any offered
proposal, useful inside non-stack containers). Default: 1.0.
Sourcepub fn align_child(self, alignment: Alignment) -> Self
pub fn align_child(self, alignment: Alignment) -> Self
Opt out of stretching the child. The child is laid out at its
natural size and positioned within the Expand’s bounds according
to alignment.
Sourcepub fn respect_intrinsic(self) -> Self
pub fn respect_intrinsic(self) -> Self
Switch to auto flex basis — the wrapped child’s natural size
acts as a floor on each flex axis, and the parent stack adds slack
on top via the flex weight. Useful when the wrapper sits inside an
unconstrained parent (e.g. an outer VStack with height = None),
where the default zero-basis would let the child overflow because
the parent has no bound to share.
Trade-off: with respect_intrinsic, exact ratios bend by content
width — [Expand::flex(1).child(60), Expand::flex(2).child(40)] in
300 px gives 60 + 66 = 126 and 40 + 133 = 173 rather than
100 / 200. Without it (the default), the same layout splits
exactly 100 / 200.
§Do not use this inside a bounded parent
The floor is a hard one: Expand reports shrink = 0, so if the
child’s natural size exceeds what the parent can offer, the resulting
over-constraint deficit cannot be absorbed and later siblings are
pushed outside the bounds.
This bites hardest with children whose natural size is large and
content-driven. A vertical TabBar
answers an unbounded height query with its stacked height — every tab,
one below another. So:
// 21 tabs => the bar's natural height is ~1050 dp.
VStack::new()
.child(Expand::vertical().respect_intrinsic().child(tab_widget))
.child(status_bar)makes the VStack want 1050 + status_bar, at every window size. The
status bar is placed at y=1050 and stays below the fold until the window
is grown past it — the bar never scrolls, because it was never asked to
fit. Dropping respect_intrinsic() fixes it: the bar takes the slack
left after the status bar and scrolls its tabs internally.
Rule of thumb: reach for this only when the parent genuinely has no
bound to share (height = None). When the parent is bounded — a window
root, a sized pane — the default zero basis is what you want.
Trait Implementations§
Source§impl Widget for Expand
impl Widget for Expand
Source§fn build(&mut self, ctx: &mut BuildContext<'_>) -> Vec<WidgetId>
fn build(&mut self, ctx: &mut BuildContext<'_>) -> Vec<WidgetId>
&mut self — store child IDs, signal handles, any state needed later.
Returns the list of root child IDs (empty for leaf widgets).Source§fn layout_response(
&self,
proposal: SizeProposal,
ctx: &LayoutContext<'_>,
) -> LayoutResponse
fn layout_response( &self, proposal: SizeProposal, ctx: &LayoutContext<'_>, ) -> LayoutResponse
LayoutResponse]). Read moreSource§fn place_children(
&self,
bounds: Rect,
_proposal: SizeProposal,
children: &mut [WidgetPlacement],
ctx: &LayoutContext<'_>,
)
fn place_children( &self, bounds: Rect, _proposal: SizeProposal, children: &mut [WidgetPlacement], ctx: &LayoutContext<'_>, )
Source§fn paint(&self, _bounds: Rect, _canvas: &mut Canvas, _ctx: &PaintContext<'_>)
fn paint(&self, _bounds: Rect, _canvas: &mut Canvas, _ctx: &PaintContext<'_>)
§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
"teksilo_widgets::button::Button"). The default implementation
resolves at the impl site via std::any::type_name::<Self>(),
so calls through &dyn Widget correctly dispatch to the
monomorphized fn for the concrete type — getting the
concrete name through the vtable without per-impl boilerplate. Read more§fn cacheable_layout(&self) -> bool
fn cacheable_layout(&self) -> bool
layout_response may be
memoized by the per-pass layout cache. Defaults to true. Read more§fn wants_after_paint(&self) -> bool
fn wants_after_paint(&self) -> bool
after_paint
hook to fire each frame. Returning false (the default) saves
a virtual call per widget per frame for the vast majority of
widgets that don’t aggregate descendant geometry. Read more§fn after_paint(&self, _view: &WidgetTreeView<'_>, _ctx: &PaintContext<'_>)
fn after_paint(&self, _view: &WidgetTreeView<'_>, _ctx: &PaintContext<'_>)
TitleBar aggregates its drag region and control-button
rects into a single HitRegions payload for the Windows
backend’s WM_NCHITTEST. Read more§fn wants_post_paint(&self) -> bool
fn wants_post_paint(&self) -> bool
post_paint
hook to fire each frame. Returning false (the default) saves a
virtual call per widget per frame for the vast majority of widgets
that don’t draw a foreground over their children. Read more§fn post_paint(
&self,
_bounds: Rect,
_canvas: &mut Canvas,
_ctx: &PaintContext<'_>,
)
fn post_paint( &self, _bounds: Rect, _canvas: &mut Canvas, _ctx: &PaintContext<'_>, )
§fn accessibility(&self, _builder: &mut AccessNodeBuilder)
fn accessibility(&self, _builder: &mut AccessNodeBuilder)
§fn wants_descendant_redirects(&self) -> bool
fn wants_descendant_redirects(&self) -> bool
a11y_redirect_descendant
hook for every descendant during AT tree emission, not
just its direct arena children. Read more§fn a11y_redirect_descendant(
&self,
_self_id: WidgetId,
_descendant: WidgetId,
) -> Option<NodeId>
fn a11y_redirect_descendant( &self, _self_id: WidgetId, _descendant: WidgetId, ) -> Option<NodeId>
§fn accessible_title_hint(&self) -> Option<String>
fn accessible_title_hint(&self) -> Option<String>
§fn initial_focus_hint(&self) -> Option<WidgetId>
fn initial_focus_hint(&self) -> Option<WidgetId>
§fn accessibility_children(&self) -> Option<Vec<WidgetId>>
fn accessibility_children(&self) -> Option<Vec<WidgetId>>
§fn as_any(&self) -> Option<&(dyn Any + 'static)>
fn as_any(&self) -> Option<&(dyn Any + 'static)>
None; concrete
widgets override with Some(self) when they want to expose
their concrete type to test-level introspection or reflection.
The trait already bounds on std::any::Any so concrete types
satisfy the 'static requirement.§fn as_any_mut(&mut self) -> Option<&mut (dyn Any + 'static)>
fn as_any_mut(&mut self) -> Option<&mut (dyn Any + 'static)>
as_any. Default
returns None; widgets that want to expose mutable state to
tests (e.g. so a test can mutate a Scene inside a
SceneView post-layout) override with Some(self). Should
follow the same opt-in pattern as as_any: only widgets
that opt into & introspection should opt into &mut.§fn clips_children(&self) -> bool
fn clips_children(&self) -> bool
§fn focus_reveal_rect(&self, _bounds: Rect) -> Option<Rect>
fn focus_reveal_rect(&self, _bounds: Rect) -> Option<Rect>
None (the default) reveals the widget’s whole
bounds — correct for most controls. Read more§fn hit_shape(&self, _local_point: Point, _bounds: Rect) -> bool
fn hit_shape(&self, _local_point: Point, _bounds: Rect) -> bool
false for a point that is inside
the bounding box makes the widget transparent to the click there,
so it falls through to whatever sibling is painted underneath
(the same machinery as a fully pass-through node, but shape-aware). Read more§fn preserves_children_on_rebuild(&self) -> bool
fn preserves_children_on_rebuild(&self) -> bool
rebuild_single_widget treats this widget’s existing children
when re-running its build(). Read more§fn tooltip_has_content(&self) -> bool
fn tooltip_has_content(&self) -> bool
§fn declare_shortcuts(&self) -> Vec<Shortcut>
fn declare_shortcuts(&self) -> Vec<Shortcut>
build()) and at certain lazy
boundaries (e.g. Switcher walks declarations on its
not-yet-mounted Pending slots), so settings UIs and the
ShortcutRegistry see the keystrokes the moment the owning
container mounts — even if build() hasn’t run. Read more§fn take_handler_set(&mut self) -> Option<HandlerSet>
fn take_handler_set(&mut self) -> Option<HandlerSet>
WidgetWithHandlers wrapper.
Called during arena insertion to transfer handlers to the WidgetNode.
Default: returns None (no attached handlers).Auto Trait Implementations§
impl !RefUnwindSafe for Expand
impl !Send for Expand
impl !Sync for Expand
impl !UnwindSafe for Expand
impl Freeze for Expand
impl Unpin for Expand
impl UnsafeUnpin for Expand
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<W> IntoTeksiChild for Wwhere
W: Widget + 'static,
impl<W> IntoTeksiChild for Wwhere
W: Widget + 'static,
fn into_pending(self) -> PendingChild
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<W> WidgetBuilder for Wwhere
W: Widget + 'static,
impl<W> WidgetBuilder for Wwhere
W: Widget + 'static,
fn on_tap( self, f: impl FnMut(&TapEvent, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
fn on_double_tap( self, f: impl FnMut(&TapEvent, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
fn on_triple_tap( self, f: impl FnMut(&TapEvent, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
fn on_long_press( self, f: impl FnMut(&TapEvent, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
on_tap. Default is [ButtonMask::PRIMARY].on_double_tap. Default [ButtonMask::PRIMARY].on_triple_tap. Default [ButtonMask::PRIMARY].on_long_press. Default [ButtonMask::PRIMARY].§fn dim_when_inactive(self, factor: f32) -> DimWhenInactive
fn dim_when_inactive(self, factor: f32) -> DimWhenInactive
factor opacity whenever the host window
is inactive (not focused / occluded), restoring full opacity when it
becomes active again. The opt-in, per-widget layer of the window-active
appearance model — for custom content an app wants to fade back when its
window isn’t the active one. Stock widgets handle their own
inactive appearance (caret hiding, selection desaturation) and need no
wrapping. Layout- and a11y-transparent; the opacity snaps (no tween),
which is correct under prefers-reduced-motion. See
DimWhenInactive.§fn dim_when_inactive_default(self) -> DimWhenInactive
fn dim_when_inactive_default(self) -> DimWhenInactive
dim_when_inactive with the default factor
(DEFAULT_DIM_FACTOR, 70 %).fn on_drag( self, f: impl FnMut(DragPhase, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
fn on_swipe( self, f: impl FnMut(SwipeDirection, f32, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
fn on_pinch( self, f: impl FnMut(PinchPhase, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
fn on_focus( self, f: impl FnMut(bool, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
fn on_key( self, f: impl FnMut(&WidgetEvent, &mut EventContext<'_>) -> EventResponse + 'static, ) -> WidgetWithHandlers<Self>
§fn on_key_preview(
self,
f: impl FnMut(&WidgetEvent, &mut EventContext<'_>) -> EventResponse + 'static,
) -> WidgetWithHandlers<Self>
fn on_key_preview( self, f: impl FnMut(&WidgetEvent, &mut EventContext<'_>) -> EventResponse + 'static, ) -> WidgetWithHandlers<Self>
HandlerSet::on_key_preview].fn on_pointer_event( self, f: impl FnMut(&WidgetEvent, &mut EventContext<'_>) -> EventResponse + 'static, ) -> WidgetWithHandlers<Self>
fn on_hover( self, f: impl FnMut(bool, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
fn on_scroll( self, f: impl FnMut(&WidgetEvent, &mut EventContext<'_>) -> EventResponse + 'static, ) -> WidgetWithHandlers<Self>
fn on_access_action( self, f: impl FnMut(Action, &mut EventContext<'_>) -> EventResponse + 'static, ) -> WidgetWithHandlers<Self>
fn focusable(self, focusable: bool) -> WidgetWithHandlers<Self>
fn tab_index(self, index: i32) -> WidgetWithHandlers<Self>
fn cursor(self, cursor: CursorIcon) -> WidgetWithHandlers<Self>
fn clips_children_on(self, clips: bool) -> WidgetWithHandlers<Self>
§fn ime_input(self, ctx: ImeContext) -> WidgetWithHandlers<Self>
fn ime_input(self, ctx: ImeContext) -> WidgetWithHandlers<Self>
ctx’s purpose) while it is focused. See [crate::ime].§fn event_pass_through(self, pass_through: bool) -> WidgetWithHandlers<Self>
fn event_pass_through(self, pass_through: bool) -> WidgetWithHandlers<Self>
HandlerSet::event_pass_through].§fn gesture_dead_zone(self, dead_zone: bool) -> WidgetWithHandlers<Self>
fn gesture_dead_zone(self, dead_zone: bool) -> WidgetWithHandlers<Self>
HandlerSet::gesture_dead_zone].§fn keyboard_capture(self, capture: bool) -> WidgetWithHandlers<Self>
fn keyboard_capture(self, capture: bool) -> WidgetWithHandlers<Self>
KeyDowns bypass shortcut resolution.
See [HandlerSet::keyboard_capture].§fn hit_transparent(self, transparent: bool) -> WidgetWithHandlers<Self>
fn hit_transparent(self, transparent: bool) -> WidgetWithHandlers<Self>
HandlerSet::hit_transparent].HandlerSet::context_menu] for the full contract.§fn focus_within(self, signal: Signal<bool>) -> WidgetWithHandlers<Self>
fn focus_within(self, signal: Signal<bool>) -> WidgetWithHandlers<Self>
Signal<bool> the framework writes when a strict
descendant has focus. See [HandlerSet::focus_within].§fn hover_within(self, signal: Signal<bool>) -> WidgetWithHandlers<Self>
fn hover_within(self, signal: Signal<bool>) -> WidgetWithHandlers<Self>
Signal<bool> the framework writes when a strict
descendant is hovered. See [HandlerSet::hover_within].§fn visible_when(self, state: impl Into<Prop<bool>>) -> WidgetWithHandlers<Self>
fn visible_when(self, state: impl Into<Prop<bool>>) -> WidgetWithHandlers<Self>
bool / Signal<bool> / Prop<bool>) as
a builder property, so teksu! can write visible_when: sig. Equivalent
to ctx.visible_when(id, ..). See [HandlerSet::visible_when].fn on_drag_hover( self, f: impl FnMut(&DragPayload, Point, &mut EventContext<'_>) -> DropFeedback + 'static, ) -> WidgetWithHandlers<Self>
fn on_drag_leave( self, f: impl FnMut(&mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
fn on_drag_tick( self, f: impl FnMut(Point, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
fn on_drop( self, f: impl FnMut(DragPayload, Point, &mut EventContext<'_>) -> bool + 'static, ) -> WidgetWithHandlers<Self>
§fn on_drag_ended(
self,
f: impl FnMut(DropOutcome, &mut EventContext<'_>) + 'static,
) -> WidgetWithHandlers<Self>
fn on_drag_ended( self, f: impl FnMut(DropOutcome, &mut EventContext<'_>) + 'static, ) -> WidgetWithHandlers<Self>
HandlerSet::on_drag_ended].