gtk4/auto/
spinner.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6    ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
7    Widget,
8};
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
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    // rustdoc-stripper-ignore-next
33    /// Creates a new builder-pattern struct instance to construct [`Spinner`] objects.
34    ///
35    /// This method returns an instance of [`SpinnerBuilder`](crate::builders::SpinnerBuilder) which can be used to create [`Spinner`] objects.
36    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            let f: &F = &*(f as *const F);
77            f(&from_glib_borrow(this))
78        }
79        unsafe {
80            let f: Box_<F> = Box_::new(f);
81            connect_raw(
82                self.as_ptr() as *mut _,
83                b"notify::spinning\0".as_ptr() as *const _,
84                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
85                    notify_spinning_trampoline::<F> as *const (),
86                )),
87                Box_::into_raw(f),
88            )
89        }
90    }
91}
92
93impl Default for Spinner {
94    fn default() -> Self {
95        Self::new()
96    }
97}
98
99// rustdoc-stripper-ignore-next
100/// A [builder-pattern] type to construct [`Spinner`] objects.
101///
102/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
103#[must_use = "The builder must be built to be used"]
104pub struct SpinnerBuilder {
105    builder: glib::object::ObjectBuilder<'static, Spinner>,
106}
107
108impl SpinnerBuilder {
109    fn new() -> Self {
110        Self {
111            builder: glib::object::Object::builder(),
112        }
113    }
114
115    pub fn spinning(self, spinning: bool) -> Self {
116        Self {
117            builder: self.builder.property("spinning", spinning),
118        }
119    }
120
121    pub fn can_focus(self, can_focus: bool) -> Self {
122        Self {
123            builder: self.builder.property("can-focus", can_focus),
124        }
125    }
126
127    pub fn can_target(self, can_target: bool) -> Self {
128        Self {
129            builder: self.builder.property("can-target", can_target),
130        }
131    }
132
133    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
134        Self {
135            builder: self.builder.property("css-classes", css_classes.into()),
136        }
137    }
138
139    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
140        Self {
141            builder: self.builder.property("css-name", css_name.into()),
142        }
143    }
144
145    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
146        Self {
147            builder: self.builder.property("cursor", cursor.clone()),
148        }
149    }
150
151    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
152        Self {
153            builder: self.builder.property("focus-on-click", focus_on_click),
154        }
155    }
156
157    pub fn focusable(self, focusable: bool) -> Self {
158        Self {
159            builder: self.builder.property("focusable", focusable),
160        }
161    }
162
163    pub fn halign(self, halign: Align) -> Self {
164        Self {
165            builder: self.builder.property("halign", halign),
166        }
167    }
168
169    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
170        Self {
171            builder: self.builder.property("has-tooltip", has_tooltip),
172        }
173    }
174
175    pub fn height_request(self, height_request: i32) -> Self {
176        Self {
177            builder: self.builder.property("height-request", height_request),
178        }
179    }
180
181    pub fn hexpand(self, hexpand: bool) -> Self {
182        Self {
183            builder: self.builder.property("hexpand", hexpand),
184        }
185    }
186
187    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
188        Self {
189            builder: self.builder.property("hexpand-set", hexpand_set),
190        }
191    }
192
193    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
194        Self {
195            builder: self
196                .builder
197                .property("layout-manager", layout_manager.clone().upcast()),
198        }
199    }
200
201    #[cfg(feature = "v4_18")]
202    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
203    pub fn limit_events(self, limit_events: bool) -> Self {
204        Self {
205            builder: self.builder.property("limit-events", limit_events),
206        }
207    }
208
209    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
210        Self {
211            builder: self.builder.property("margin-bottom", margin_bottom),
212        }
213    }
214
215    pub fn margin_end(self, margin_end: i32) -> Self {
216        Self {
217            builder: self.builder.property("margin-end", margin_end),
218        }
219    }
220
221    pub fn margin_start(self, margin_start: i32) -> Self {
222        Self {
223            builder: self.builder.property("margin-start", margin_start),
224        }
225    }
226
227    pub fn margin_top(self, margin_top: i32) -> Self {
228        Self {
229            builder: self.builder.property("margin-top", margin_top),
230        }
231    }
232
233    pub fn name(self, name: impl Into<glib::GString>) -> Self {
234        Self {
235            builder: self.builder.property("name", name.into()),
236        }
237    }
238
239    pub fn opacity(self, opacity: f64) -> Self {
240        Self {
241            builder: self.builder.property("opacity", opacity),
242        }
243    }
244
245    pub fn overflow(self, overflow: Overflow) -> Self {
246        Self {
247            builder: self.builder.property("overflow", overflow),
248        }
249    }
250
251    pub fn receives_default(self, receives_default: bool) -> Self {
252        Self {
253            builder: self.builder.property("receives-default", receives_default),
254        }
255    }
256
257    pub fn sensitive(self, sensitive: bool) -> Self {
258        Self {
259            builder: self.builder.property("sensitive", sensitive),
260        }
261    }
262
263    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
264        Self {
265            builder: self
266                .builder
267                .property("tooltip-markup", tooltip_markup.into()),
268        }
269    }
270
271    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
272        Self {
273            builder: self.builder.property("tooltip-text", tooltip_text.into()),
274        }
275    }
276
277    pub fn valign(self, valign: Align) -> Self {
278        Self {
279            builder: self.builder.property("valign", valign),
280        }
281    }
282
283    pub fn vexpand(self, vexpand: bool) -> Self {
284        Self {
285            builder: self.builder.property("vexpand", vexpand),
286        }
287    }
288
289    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
290        Self {
291            builder: self.builder.property("vexpand-set", vexpand_set),
292        }
293    }
294
295    pub fn visible(self, visible: bool) -> Self {
296        Self {
297            builder: self.builder.property("visible", visible),
298        }
299    }
300
301    pub fn width_request(self, width_request: i32) -> Self {
302        Self {
303            builder: self.builder.property("width-request", width_request),
304        }
305    }
306
307    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
308        Self {
309            builder: self.builder.property("accessible-role", accessible_role),
310        }
311    }
312
313    // rustdoc-stripper-ignore-next
314    /// Build the [`Spinner`].
315    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
316    pub fn build(self) -> Spinner {
317        assert_initialized_main_thread!();
318        self.builder.build()
319    }
320}