Positioned
Positioned is the absolute-positioning helper for layered layouts.
It is designed to be used inside a parent such as ZStack, where one child should sit at a specific edge, corner, or offset relative to the stack's bounds. Common uses include badges, tooltips, floating buttons, corner actions, or popups anchored inside an overlay surface.
Use Positioned when placement relative to parent edges matters. Do not use it for ordinary spacing in a row or column. Absolute positioning is powerful, but it is the wrong tool for most everyday layout.
Example
use fission::core::ui::{Positioned, Text};
let badge = Positioned {
top: Some(8.0),
right: Some(8.0),
child: Some(Box::new(Text::new("New").into_node())),
..Default::default()
}
.into_node();
Field table
| Field | Type | Meaning | Notes / default behavior |
|---|---|---|---|
id | Option<NodeId> | Stable node identity. | Defaults to None. |
left | Option<f32> | Distance from the parent's left edge. | Defaults to None. |
top | Option<f32> | Distance from the parent's top edge. | Defaults to None. |
right | Option<f32> | Distance from the parent's right edge. | Defaults to None. |
bottom | Option<f32> | Distance from the parent's bottom edge. | Defaults to None. |
width | Option<f32> | Explicit width for the child region. | Defaults to None. |
height | Option<f32> | Explicit height for the child region. | Defaults to None. |
child | Option<Box<Node>> | The positioned child. | Defaults to None. |
Placement behavior
If you provide both left and right, the available width is derived from the remaining horizontal space. Likewise, if you provide both top and bottom, the available height is derived from the remaining vertical space. Explicit width and height tighten the child constraints further.
If only one edge is provided on an axis, the child keeps its natural size on that axis and is placed from that edge.
Specific advice
Positioned reads best when the placement is part of the design, not a last-minute correction. If you find yourself using it repeatedly just to fix normal layout problems, step back and reconsider whether the parent should really be a row, column, or container instead.
Related
ZStack, Overlay, and absolute_fill(...).