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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#![allow(unused_variables)]
use crate::prelude::*;
use crate::{Actor, Widget};
use glib::signal::SignalHandlerId;
use std::{cell::RefCell, fmt};
#[derive(Clone, Debug)]
pub struct SpinnerProps {
pub texture: Option<dx::Handle>,
pub material: Option<dx::Handle>,
pub frames: u32,
pub anim_duration: u32,
pub current_frame: u32,
pub update_id: u32,
pub animating: bool,
}
#[derive(Clone, Debug)]
pub struct Spinner {
props: RefCell<SpinnerProps>,
widget: Widget,
}
impl Spinner {
pub fn new() -> Spinner {
let props = SpinnerProps {
texture: None,
material: None,
frames: 1,
anim_duration: 500,
current_frame: 0,
update_id: 0,
animating: true,
};
println!("create spinner");
let spinner = Self {
props: RefCell::new(props),
widget: Widget::new(),
};
let actor: &Actor = spinner.widget.as_ref();
actor.set_background_color(Some(color::RED_9));
actor.set_size(100_f32, 100_f32);
actor.set_position(100_f32, 100_f32);
spinner
}
}
impl Default for Spinner {
fn default() -> Self {
Self::new()
}
}
impl Object for Spinner {}
impl Is<Spinner> for Spinner {}
impl AsRef<Spinner> for Spinner {
fn as_ref(&self) -> &Spinner {
self
}
}
impl Is<Widget> for Spinner {}
impl AsRef<Widget> for Spinner {
fn as_ref(&self) -> &Widget {
&self.widget
}
}
impl Is<Actor> for Spinner {}
impl AsRef<Actor> for Spinner {
fn as_ref(&self) -> &Actor {
let actor: &Actor = self.widget.as_ref();
actor
}
}
pub trait SpinnerExt: 'static {
fn get_animating(&self) -> bool;
fn set_animating(&self, animating: bool);
fn connect_looped<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
fn connect_property_animating_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: Is<Spinner>> SpinnerExt for O {
fn get_animating(&self) -> bool {
let spinner = self.as_ref();
let props = spinner.props.borrow();
props.animating
}
fn set_animating(&self, animating: bool) {
let spinner = self.as_ref();
let mut props = spinner.props.borrow_mut();
if props.animating != animating {
props.animating = animating;
}
}
fn connect_looped<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unimplemented!()
}
fn connect_property_animating_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unimplemented!()
}
}
impl fmt::Display for Spinner {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Spinner")
}
}