1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/// Which way the rectangles should flex
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum FlexDirection {
    Column,
    Row,
}

#[derive(Debug, Clone)]
pub struct NodeData<T: Clone> {
    /// Minimum width of this node
    pub min_width: Option<f32>,
    /// Minimum height of this node
    pub min_height: Option<f32>,
    /// Maximum width of this node
    pub max_width: Option<f32>,
    /// Maximum height of this node
    pub max_height: Option<f32>,
    /// Width of the node (must be initialized for the root node)
    pub width: Option<f32>,
    /// Width of the node. (must be initialized for the root node)
    pub height: Option<f32>,
    /// What direction the children should flex to
    pub flex_direction: FlexDirection,
    /// Abstract data of the node, defined by the renderer / application (not inside this library)
    pub data: T,
}

impl<T: Clone> NodeData<T> {
    /// Creates a new node
    pub fn new(min_width: Option<f32>,
               min_height: Option<f32>,
               max_width: Option<f32>,
               max_height: Option<f32>,
               width: Option<f32>,
               height: Option<f32>,
               flex_direction: FlexDirection,
               data: T)
    -> Self {
        Self {
            min_width,
            min_height,
            max_width,
            max_height,
            width,
            height,
            flex_direction,
            data,
        }
    }

    /// Creates an empty node
    pub fn empty(flex_direction: FlexDirection,
               data: T)
    -> Self {
        Self {
            min_width: None,
            min_height: None,
            max_width: None,
            max_height: None,
            width: None,
            height: None,
            flex_direction: flex_direction,
            data: data,
        }
    }
}