Move `hidden_layout()` to parent scope (#208)
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 zero-[`Layout`].
21 ///
22 /// The Zero-layout has size and location set to ZERO.
23 /// The `order` value of this layout is set to the minimum value of 0.
24 /// This means it should be rendered below all other [`Layout`]s.
25 #[must_use]
26 pub const fn new() -> Self {
27 Self { order: 0, size: Size::ZERO, location: Point::ZERO }
28 }
29
30 /// Creates a new zero-[`Layout`] with the supplied `order` value.
31 ///
32 /// Nodes with a higher order should be rendered on top of those with a lower order.
33 /// The Zero-layout has size and location set to ZERO.
34 #[must_use]
35 pub const fn with_order(order: u32) -> Self {
36 Self { order, size: Size::ZERO, location: Point::ZERO }
37 }
38}
39
40/// Cached intermediate layout results
41#[derive(Debug, Clone)]
42pub(crate) struct Cache {
43 /// The initial cached size of the node itself
44 pub(crate) node_size: Size<Option<f32>>,
45 /// The initial cached size of the parent's node
46 pub(crate) parent_size: Size<Option<f32>>,
47 /// Whether or not layout should be recomputed
48 pub(crate) perform_layout: bool,
49
50 /// The cached size of the item
51 pub(crate) size: Size<f32>,
52}