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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use flo_binding::*;

///
/// Trait implemented by objects that can provide properties for creating/updating a flo_draw window
///
/// Window properties are supplied as bindings to make it possible to update them after the window has
/// been created.
///
pub trait FloWindowProperties {
    ///
    /// The title of the window
    ///
    fn title(&self) -> BindRef<String>;

    ///
    /// The initial size of the window
    ///
    fn size(&self) -> BindRef<(u64, u64)>;

    ///
    /// Set to true if the window should be fullscreen
    ///
    fn fullscreen(&self) -> BindRef<bool>;

    ///
    /// Set to true if the window should have decorations
    ///
    fn has_decorations(&self) -> BindRef<bool>;

    ///
    /// The mouse pointer to show for a window
    ///
    fn mouse_pointer(&self) -> BindRef<MousePointer>;
}

///
/// The types of mouse pointer that can be displayed in a window
///
#[derive(Clone, Copy, PartialEq)]
pub enum MousePointer {
    /// No pointer
    None,

    /// The default pointer for the operating system
    SystemDefault
}

///
/// '()' can be used to create a window with the default title
///
impl FloWindowProperties for () {
    fn title(&self) -> BindRef<String>                  { BindRef::from(bind("flo_draw".to_string())) }
    fn size(&self) -> BindRef<(u64, u64)>               { BindRef::from(bind((1024, 768))) }
    fn fullscreen(&self) -> BindRef<bool>               { BindRef::from(bind(false)) }
    fn has_decorations(&self) -> BindRef<bool>          { BindRef::from(bind(true)) }
    fn mouse_pointer(&self) -> BindRef<MousePointer>    { BindRef::from(bind(MousePointer::SystemDefault)) }
}

///
/// A string can be used to set just the window title
///
impl<'a> FloWindowProperties for &'a str {
    fn title(&self) -> BindRef<String>                  { BindRef::from(bind(self.to_string())) }
    fn size(&self) -> BindRef<(u64, u64)>               { BindRef::from(bind((1024, 768))) }
    fn fullscreen(&self) -> BindRef<bool>               { BindRef::from(bind(false)) }
    fn has_decorations(&self) -> BindRef<bool>          { BindRef::from(bind(true)) }
    fn mouse_pointer(&self) -> BindRef<MousePointer>    { BindRef::from(bind(MousePointer::SystemDefault)) }
}

///
/// The window properties struct provides a copy of all of the bindings for a window, and is a good way to provide
/// custom bindings (for example, if you want to be able to toggle the window betwen fullscreen and a normal display)
///
#[derive(Clone)]
pub struct WindowProperties {
    pub title:              BindRef<String>,
    pub size:               BindRef<(u64, u64)>,
    pub fullscreen:         BindRef<bool>,
    pub has_decorations:    BindRef<bool>,
    pub mouse_pointer:      BindRef<MousePointer>
}

impl WindowProperties {
    ///
    /// Creates a clone of an object implementing the FloWindowProperties trait
    ///
    pub fn from<T: FloWindowProperties>(properties: &T) -> WindowProperties {
        WindowProperties {
            title:              properties.title(),
            size:               properties.size(),
            fullscreen:         properties.fullscreen(),
            has_decorations:    properties.has_decorations(),
            mouse_pointer:      properties.mouse_pointer()
        }
    }
}

impl FloWindowProperties for WindowProperties {
    fn title(&self) -> BindRef<String>                  { self.title.clone() }
    fn size(&self) -> BindRef<(u64, u64)>               { self.size.clone() }
    fn fullscreen(&self) -> BindRef<bool>               { self.fullscreen.clone() }
    fn has_decorations(&self) -> BindRef<bool>          { self.has_decorations.clone() }
    fn mouse_pointer(&self) -> BindRef<MousePointer>    { self.mouse_pointer.clone() }
}