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