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
use graphics::character::CharacterCache;
use super::Kind;
use super::Update;
use ui::{Ui, UiId};
pub trait Custom: Clone + ::std::fmt::Debug {
type State: State;
fn set<C>(self, ui_id: UiId, ui: &mut Ui<C, Self>) where C: CharacterCache {
let state = match *ui.get_widget_mut(ui_id, Kind::Custom(Self::State::init())) {
::widget::Kind::Custom(ref state) => state.clone(),
_ => panic!("The Kind variant returned by Ui is different to that which \
was requested (Check that there are no UiId conflicts)."),
};
let Update { new_state, xy, depth, element } = self.update(state, ui_id, ui);
ui.update_widget(ui_id, Kind::Custom(new_state), xy, depth, Some(element));
}
fn update<C>(mut self, prev: Self::State, ui_id: UiId, ui: &mut Ui<C, Self>) -> Update<Self::State> where C: CharacterCache;
}
pub trait State: Clone + ::std::fmt::Debug {
fn matches(&self, other: &Self) -> bool;
fn init() -> Self;
}
impl Custom for () {
type State = ();
fn set<C>(self, _: UiId, _ui: &mut Ui<C, ()>) {}
fn update<C>(self, _: (), _: UiId, _: &mut Ui<C, ()>) -> Update<()> {
Update {
new_state: (),
xy: [0.0, 0.0],
depth: 0.0,
element: ::elmesque::element::empty(),
}
}
}
impl State for () {
fn matches(&self, _other: &()) -> bool { true }
fn init() -> Self { () }
}