1//! Final and cached data structures that represent the high-level UI layout
2
3use crate::flexbox::ComputeResult;
4use crate::geometry::{Point, Size};
5use crate::number::Number;
6
7/// The final result of a layout algorithm for a single [`Node`](crate::node::Node).
8#[derive(Copy, Debug, Clone)]
9pub struct Layout {
10 /// The relative ordering of the node
11 ///
12 /// Nodes with a higher order should be rendered on top of those with a lower order.
13 /// This is effectively a topological sort of each tree.
14 pub order: u32,
15 /// The width and height of the node
16 pub size: Size<f32>,
17 /// The bottom-left corner of the node
18 pub location: Point<f32>,
19}
20
21impl Layout {
22 /// Creates a new [`Layout`] struct with zero size positioned at the origin
23 #[must_use]
24 pub(crate) fn new() -> Self {
25 Self { order: 0, size: Size::zero(), location: Point::zero() }
26 }
27}
28
29/// Cached intermediate layout results
30#[derive(Debug, Clone)]
31pub(crate) struct Cache {
32 /// The initial cached size of the node itself
33 pub(crate) node_size: Size<Number>,
34 /// The initial cached size of the parent's node
35 pub(crate) parent_size: Size<Number>,
36 /// Whether or not layout should be recomputed
37 pub(crate) perform_layout: bool,
38
39 /// The stored result of the layout calculations
40 pub(crate) result: ComputeResult,
41}