1use crate::{
6 Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
7 Widget, ffi,
8};
9use glib::{
10 prelude::*,
11 signal::{SignalHandlerId, connect_raw},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 #[doc(alias = "GtkSpinner")]
18 pub struct Spinner(Object<ffi::GtkSpinner>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
19
20 match fn {
21 type_ => || ffi::gtk_spinner_get_type(),
22 }
23}
24
25impl Spinner {
26 #[doc(alias = "gtk_spinner_new")]
27 pub fn new() -> Spinner {
28 assert_initialized_main_thread!();
29 unsafe { Widget::from_glib_none(ffi::gtk_spinner_new()).unsafe_cast() }
30 }
31
32 pub fn builder() -> SpinnerBuilder {
37 SpinnerBuilder::new()
38 }
39
40 #[doc(alias = "gtk_spinner_get_spinning")]
41 #[doc(alias = "get_spinning")]
42 #[doc(alias = "spinning")]
43 pub fn is_spinning(&self) -> bool {
44 unsafe { from_glib(ffi::gtk_spinner_get_spinning(self.to_glib_none().0)) }
45 }
46
47 #[doc(alias = "gtk_spinner_set_spinning")]
48 #[doc(alias = "spinning")]
49 pub fn set_spinning(&self, spinning: bool) {
50 unsafe {
51 ffi::gtk_spinner_set_spinning(self.to_glib_none().0, spinning.into_glib());
52 }
53 }
54
55 #[doc(alias = "gtk_spinner_start")]
56 pub fn start(&self) {
57 unsafe {
58 ffi::gtk_spinner_start(self.to_glib_none().0);
59 }
60 }
61
62 #[doc(alias = "gtk_spinner_stop")]
63 pub fn stop(&self) {
64 unsafe {
65 ffi::gtk_spinner_stop(self.to_glib_none().0);
66 }
67 }
68
69 #[doc(alias = "spinning")]
70 pub fn connect_spinning_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
71 unsafe extern "C" fn notify_spinning_trampoline<F: Fn(&Spinner) + 'static>(
72 this: *mut ffi::GtkSpinner,
73 _param_spec: glib::ffi::gpointer,
74 f: glib::ffi::gpointer,
75 ) {
76 unsafe {
77 let f: &F = &*(f as *const F);
78 f(&from_glib_borrow(this))
79 }
80 }
81 unsafe {
82 let f: Box_<F> = Box_::new(f);
83 connect_raw(
84 self.as_ptr() as *mut _,
85 c"notify::spinning".as_ptr(),
86 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
87 notify_spinning_trampoline::<F> as *const (),
88 )),
89 Box_::into_raw(f),
90 )
91 }
92 }
93}
94
95impl Default for Spinner {
96 fn default() -> Self {
97 Self::new()
98 }
99}
100
101#[must_use = "The builder must be built to be used"]
106pub struct SpinnerBuilder {
107 builder: glib::object::ObjectBuilder<'static, Spinner>,
108}
109
110impl SpinnerBuilder {
111 fn new() -> Self {
112 Self {
113 builder: glib::object::Object::builder(),
114 }
115 }
116
117 pub fn spinning(self, spinning: bool) -> Self {
118 Self {
119 builder: self.builder.property("spinning", spinning),
120 }
121 }
122
123 pub fn can_focus(self, can_focus: bool) -> Self {
124 Self {
125 builder: self.builder.property("can-focus", can_focus),
126 }
127 }
128
129 pub fn can_target(self, can_target: bool) -> Self {
130 Self {
131 builder: self.builder.property("can-target", can_target),
132 }
133 }
134
135 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
136 Self {
137 builder: self.builder.property("css-classes", css_classes.into()),
138 }
139 }
140
141 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
142 Self {
143 builder: self.builder.property("css-name", css_name.into()),
144 }
145 }
146
147 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
148 Self {
149 builder: self.builder.property("cursor", cursor.clone()),
150 }
151 }
152
153 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
154 Self {
155 builder: self.builder.property("focus-on-click", focus_on_click),
156 }
157 }
158
159 pub fn focusable(self, focusable: bool) -> Self {
160 Self {
161 builder: self.builder.property("focusable", focusable),
162 }
163 }
164
165 pub fn halign(self, halign: Align) -> Self {
166 Self {
167 builder: self.builder.property("halign", halign),
168 }
169 }
170
171 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
172 Self {
173 builder: self.builder.property("has-tooltip", has_tooltip),
174 }
175 }
176
177 pub fn height_request(self, height_request: i32) -> Self {
178 Self {
179 builder: self.builder.property("height-request", height_request),
180 }
181 }
182
183 pub fn hexpand(self, hexpand: bool) -> Self {
184 Self {
185 builder: self.builder.property("hexpand", hexpand),
186 }
187 }
188
189 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
190 Self {
191 builder: self.builder.property("hexpand-set", hexpand_set),
192 }
193 }
194
195 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
196 Self {
197 builder: self
198 .builder
199 .property("layout-manager", layout_manager.clone().upcast()),
200 }
201 }
202
203 #[cfg(feature = "v4_18")]
204 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
205 pub fn limit_events(self, limit_events: bool) -> Self {
206 Self {
207 builder: self.builder.property("limit-events", limit_events),
208 }
209 }
210
211 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
212 Self {
213 builder: self.builder.property("margin-bottom", margin_bottom),
214 }
215 }
216
217 pub fn margin_end(self, margin_end: i32) -> Self {
218 Self {
219 builder: self.builder.property("margin-end", margin_end),
220 }
221 }
222
223 pub fn margin_start(self, margin_start: i32) -> Self {
224 Self {
225 builder: self.builder.property("margin-start", margin_start),
226 }
227 }
228
229 pub fn margin_top(self, margin_top: i32) -> Self {
230 Self {
231 builder: self.builder.property("margin-top", margin_top),
232 }
233 }
234
235 pub fn name(self, name: impl Into<glib::GString>) -> Self {
236 Self {
237 builder: self.builder.property("name", name.into()),
238 }
239 }
240
241 pub fn opacity(self, opacity: f64) -> Self {
242 Self {
243 builder: self.builder.property("opacity", opacity),
244 }
245 }
246
247 pub fn overflow(self, overflow: Overflow) -> Self {
248 Self {
249 builder: self.builder.property("overflow", overflow),
250 }
251 }
252
253 pub fn receives_default(self, receives_default: bool) -> Self {
254 Self {
255 builder: self.builder.property("receives-default", receives_default),
256 }
257 }
258
259 pub fn sensitive(self, sensitive: bool) -> Self {
260 Self {
261 builder: self.builder.property("sensitive", sensitive),
262 }
263 }
264
265 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
266 Self {
267 builder: self
268 .builder
269 .property("tooltip-markup", tooltip_markup.into()),
270 }
271 }
272
273 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
274 Self {
275 builder: self.builder.property("tooltip-text", tooltip_text.into()),
276 }
277 }
278
279 pub fn valign(self, valign: Align) -> Self {
280 Self {
281 builder: self.builder.property("valign", valign),
282 }
283 }
284
285 pub fn vexpand(self, vexpand: bool) -> Self {
286 Self {
287 builder: self.builder.property("vexpand", vexpand),
288 }
289 }
290
291 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
292 Self {
293 builder: self.builder.property("vexpand-set", vexpand_set),
294 }
295 }
296
297 pub fn visible(self, visible: bool) -> Self {
298 Self {
299 builder: self.builder.property("visible", visible),
300 }
301 }
302
303 pub fn width_request(self, width_request: i32) -> Self {
304 Self {
305 builder: self.builder.property("width-request", width_request),
306 }
307 }
308
309 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
310 Self {
311 builder: self.builder.property("accessible-role", accessible_role),
312 }
313 }
314
315 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
318 pub fn build(self) -> Spinner {
319 assert_initialized_main_thread!();
320 self.builder.build()
321 }
322}