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