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
use super::*;

use modifier::*;

///
/// Possible visibilities for the scrollbars
/// 
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub enum ScrollBarVisibility {
    Never,
    Always,
    OnlyIfNeeded    
}

///
/// Specifies a fixed axis
///
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub enum FixedAxis {
    /// Fixed in position along the horizontal axis
    Horizontal,

    /// Fixed in position along the vertical axis
    Vertical,

    /// Fixed in position along both axes
    Both
}

///
/// Attributes representing the way a control scrolls its content
/// 
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub enum Scroll {
    /// The size of the content of this scroll region
    /// 
    /// This is a minimum size. If there are items placed outside this region, the scroll 
    /// region will grow to accomodate them.
    /// 
    /// If the control is larger than this size, then the bounds will be set to the
    /// overall size of the control.
    MinimumContentSize(f32, f32),

    /// Specifies the visibility of the horizontal scroll bar
    HorizontalScrollBar(ScrollBarVisibility),

    /// Specifies the visibility of the vertical scroll bar
    VerticalScrollBar(ScrollBarVisibility),

    /// Fixes the position of this element relative to its containing scroll region
    ///
    /// It will be laid out as normal but will not move when the region is scrolled
    Fix(FixedAxis)
}

impl Modifier<Control> for Scroll {
    fn modify(self, control: &mut Control) {
        control.add_attribute(ControlAttribute::ScrollAttr(self))
    }
}

impl<'a> Modifier<Control> for &'a Scroll {
    fn modify(self, control: &mut Control) {
        control.add_attribute(ControlAttribute::ScrollAttr(self.clone()))
    }
}