flo/color/
color_picker_controller.rs

1use super::hsluv_picker_controller::*;
2
3use ui::*;
4use canvas::*;
5use binding::*;
6
7use std::sync::*;
8
9///
10/// Controller that makes it possible to pick a colour
11/// 
12pub struct ColorPickerController {
13    ui:     BindRef<Control>,
14
15    hsluv:  Arc<HsluvPickerController>
16}
17
18impl ColorPickerController {
19    ///
20    /// Creates a new color picker controller
21    /// 
22    pub fn new(color: &Binding<Color>) -> ColorPickerController {
23        let ui      = Self::create_ui();
24        let hsluv   = HsluvPickerController::new(color);
25
26        ColorPickerController {
27            ui:     ui,
28            hsluv:  Arc::new(hsluv)
29        }
30    }
31
32    ///
33    /// Creates the UI for this controller
34    /// 
35    fn create_ui() -> BindRef<Control> {
36        BindRef::from(computed(move || {
37            Control::container()
38                .with_controller("HSLUV")
39                .with(Bounds::fill_all())
40        }))
41    }
42}
43
44impl Controller for ColorPickerController {
45    fn ui(&self) -> BindRef<Control> {
46        self.ui.clone()
47    }
48
49    fn get_subcontroller(&self, id: &str) -> Option<Arc<Controller>> {
50        match id {
51            "HSLUV" => Some(self.hsluv.clone()),
52            _       => None
53        }
54    }
55}