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
/// The `ScrollMode` defines the mode of a scroll direction.
#[derive(Copy, Debug, Clone, PartialEq)]
pub enum ScrollMode {
    /// Scrolling will process by `ScrollViewer` logic
    Auto,

    /// Scrolling could be handled from outside. It will not be process by `ScrollViewer` logic.
    Custom,

    /// Scrolling will be disabled.
    Disabled,
}

impl Default for ScrollMode {
    fn default() -> Self {
        ScrollMode::Auto
    }
}

impl From<&str> for ScrollMode {
    fn from(s: &str) -> ScrollMode {
        match s {
            "Custom" | "custom" => ScrollMode::Custom,
            "Disabled" | "disabled" => ScrollMode::Disabled,
            _ => ScrollMode::Auto,
        }
    }
}

/// `ScrollViewerMode` describes the vertical and horizontal scroll behavior of the `ScrollViewer`.
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct ScrollViewerMode {
    /// Vertical scroll mode.
    pub vertical: ScrollMode,

    /// Horizontal scroll mode.
    pub horizontal: ScrollMode,
}

// --- Conversions ---

impl From<(&str, &str)> for ScrollViewerMode {
    fn from(s: (&str, &str)) -> ScrollViewerMode {
        ScrollViewerMode {
            horizontal: ScrollMode::from(s.0),
            vertical: ScrollMode::from(s.1),
        }
    }
}

impl Default for ScrollViewerMode {
    fn default() -> ScrollViewerMode {
        ScrollViewerMode {
            vertical: ScrollMode::Auto,
            horizontal: ScrollMode::Auto,
        }
    }
}