#[non_exhaustive]pub struct LayoutNode {
pub style: Style,
pub self_fragments: Vec<ItemFragment>,
pub children: Vec<LayoutNode>,
pub layout_boxes: LayoutBoxes,
pub placements: Vec<FragmentPlacement>,
/* private fields */
}Expand description
A node in the layout tree.
A LayoutNode represents a single layout object and is responsible for:
- Holding layout-related style information
- Owning child layout nodes (structural hierarchy)
- Providing inline fragment inputs
- Storing layout results (box model and fragment placements)
§Fragment model
self_fragments represent the input fragments provided by the user.
They are immutable logical units and are never reordered by the layout engine.
placements represent the layout result for fragments.
Each entry corresponds 1:1 to self_fragments and stores relative placement
information computed during layout.
Only inline-level nodes are expected to have non-empty self_fragments.
For block-level or flex-level nodes, this vector should be empty.
§Layout invariants
- The order of
self_fragmentsis preserved during layout placements.len() == self_fragments.len()after layoutplacementsare meaningful only after layout computation
This structure intentionally does not distinguish between inline, block,
or flex nodes at the type level; their behavior is defined by Style::display.
§Results storage
Results of the layout process are stored directly within each LayoutNode,
allowing for easy access and further processing after layout computation.
This includes the computed BoxModel and fragment placements.
layout_boxes: The computed box model for this node after layout.placements: The computed placements for each fragment inself_fragments.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.style: Style§self_fragments: Vec<ItemFragment>§children: Vec<LayoutNode>§layout_boxes: LayoutBoxes§placements: Vec<FragmentPlacement>Implementations§
Source§impl LayoutNode
impl LayoutNode
Sourcepub fn new(style: Style) -> Self
pub fn new(style: Style) -> Self
Examples found in repository?
5fn node(display: Display) -> LayoutNode {
6 LayoutNode::new(Style {
7 display,
8 spacing: Spacing {
9 margin_left: Length::Px(2.0),
10 margin_right: Length::Px(2.0),
11 padding_left: Length::Px(1.0),
12 padding_right: Length::Px(1.0),
13 border_left: Length::Px(1.0),
14 border_right: Length::Px(1.0),
15 ..Default::default()
16 },
17 size: SizeStyle {
18 min_width: Length::Px(0.0),
19 max_width: Length::Px(10_000.0),
20 ..Default::default()
21 },
22 ..Default::default()
23 })
24}More examples
4fn make_node(is_flex: bool) -> LayoutNode {
5 LayoutNode::new(Style {
6 display: if is_flex {
7 Display::Flex {
8 flex_direction: FlexDirection::Row,
9 }
10 } else {
11 Display::Block
12 },
13 size: SizeStyle {
14 width: Length::Auto,
15 height: Length::Auto,
16 min_width: Length::Px(0.0),
17 max_width: Length::Px(10_000.0),
18 min_height: Length::Px(0.0),
19 max_height: Length::Px(10_000.0),
20 },
21 spacing: Spacing {
22 margin_left: Length::Px(2.0),
23 margin_right: Length::Px(2.0),
24 margin_top: Length::Px(1.0),
25 margin_bottom: Length::Px(1.0),
26 padding_left: Length::Px(1.0),
27 padding_right: Length::Px(1.0),
28 padding_top: Length::Px(1.0),
29 padding_bottom: Length::Px(1.0),
30 border_left: Length::Px(1.0),
31 border_right: Length::Px(1.0),
32 border_top: Length::Px(1.0),
33 border_bottom: Length::Px(1.0),
34 ..Default::default()
35 },
36 ..Default::default()
37 })
38}pub fn with_children(style: Style, children: Vec<LayoutNode>) -> Self
Sourcepub fn set_fragments(&mut self, fragments: Vec<ItemFragment>)
pub fn set_fragments(&mut self, fragments: Vec<ItemFragment>)
Sets input fragments for this node.
This method defines the inline content owned by the node. Any previously computed fragment placements become invalid and must be recomputed during the next layout pass.