gtk/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 gdk;
6use glib::object::Cast;
7use glib::object::IsA;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::StaticType;
12use glib::ToValue;
13use glib::Value;
14use glib_sys;
15use gobject_sys;
16use gtk_sys;
17use std::boxed::Box as Box_;
18use std::fmt;
19use std::mem::transmute;
20use Align;
21use Buildable;
22use Container;
23use Widget;
24
25glib_wrapper! {
26    pub struct Spinner(Object<gtk_sys::GtkSpinner, gtk_sys::GtkSpinnerClass, SpinnerClass>) @extends Widget, @implements Buildable;
27
28    match fn {
29        get_type => || gtk_sys::gtk_spinner_get_type(),
30    }
31}
32
33impl Spinner {
34    pub fn new() -> Spinner {
35        assert_initialized_main_thread!();
36        unsafe { Widget::from_glib_none(gtk_sys::gtk_spinner_new()).unsafe_cast() }
37    }
38}
39
40impl Default for Spinner {
41    fn default() -> Self {
42        Self::new()
43    }
44}
45
46pub struct SpinnerBuilder {
47    active: Option<bool>,
48    app_paintable: Option<bool>,
49    can_default: Option<bool>,
50    can_focus: Option<bool>,
51    events: Option<gdk::EventMask>,
52    expand: Option<bool>,
53    #[cfg(any(feature = "v3_20", feature = "dox"))]
54    focus_on_click: Option<bool>,
55    halign: Option<Align>,
56    has_default: Option<bool>,
57    has_focus: Option<bool>,
58    has_tooltip: Option<bool>,
59    height_request: Option<i32>,
60    hexpand: Option<bool>,
61    hexpand_set: Option<bool>,
62    is_focus: Option<bool>,
63    margin: Option<i32>,
64    margin_bottom: Option<i32>,
65    margin_end: Option<i32>,
66    margin_start: Option<i32>,
67    margin_top: Option<i32>,
68    name: Option<String>,
69    no_show_all: Option<bool>,
70    opacity: Option<f64>,
71    parent: Option<Container>,
72    receives_default: Option<bool>,
73    sensitive: Option<bool>,
74    //style: /*Unknown type*/,
75    tooltip_markup: Option<String>,
76    tooltip_text: Option<String>,
77    valign: Option<Align>,
78    vexpand: Option<bool>,
79    vexpand_set: Option<bool>,
80    visible: Option<bool>,
81    width_request: Option<i32>,
82}
83
84impl SpinnerBuilder {
85    pub fn new() -> Self {
86        Self {
87            active: None,
88            app_paintable: None,
89            can_default: None,
90            can_focus: None,
91            events: None,
92            expand: None,
93            #[cfg(any(feature = "v3_20", feature = "dox"))]
94            focus_on_click: None,
95            halign: None,
96            has_default: None,
97            has_focus: None,
98            has_tooltip: None,
99            height_request: None,
100            hexpand: None,
101            hexpand_set: None,
102            is_focus: None,
103            margin: None,
104            margin_bottom: None,
105            margin_end: None,
106            margin_start: None,
107            margin_top: None,
108            name: None,
109            no_show_all: None,
110            opacity: None,
111            parent: None,
112            receives_default: None,
113            sensitive: None,
114            tooltip_markup: None,
115            tooltip_text: None,
116            valign: None,
117            vexpand: None,
118            vexpand_set: None,
119            visible: None,
120            width_request: None,
121        }
122    }
123
124    pub fn build(self) -> Spinner {
125        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
126        if let Some(ref active) = self.active {
127            properties.push(("active", active));
128        }
129        if let Some(ref app_paintable) = self.app_paintable {
130            properties.push(("app-paintable", app_paintable));
131        }
132        if let Some(ref can_default) = self.can_default {
133            properties.push(("can-default", can_default));
134        }
135        if let Some(ref can_focus) = self.can_focus {
136            properties.push(("can-focus", can_focus));
137        }
138        if let Some(ref events) = self.events {
139            properties.push(("events", events));
140        }
141        if let Some(ref expand) = self.expand {
142            properties.push(("expand", expand));
143        }
144        #[cfg(any(feature = "v3_20", feature = "dox"))]
145        {
146            if let Some(ref focus_on_click) = self.focus_on_click {
147                properties.push(("focus-on-click", focus_on_click));
148            }
149        }
150        if let Some(ref halign) = self.halign {
151            properties.push(("halign", halign));
152        }
153        if let Some(ref has_default) = self.has_default {
154            properties.push(("has-default", has_default));
155        }
156        if let Some(ref has_focus) = self.has_focus {
157            properties.push(("has-focus", has_focus));
158        }
159        if let Some(ref has_tooltip) = self.has_tooltip {
160            properties.push(("has-tooltip", has_tooltip));
161        }
162        if let Some(ref height_request) = self.height_request {
163            properties.push(("height-request", height_request));
164        }
165        if let Some(ref hexpand) = self.hexpand {
166            properties.push(("hexpand", hexpand));
167        }
168        if let Some(ref hexpand_set) = self.hexpand_set {
169            properties.push(("hexpand-set", hexpand_set));
170        }
171        if let Some(ref is_focus) = self.is_focus {
172            properties.push(("is-focus", is_focus));
173        }
174        if let Some(ref margin) = self.margin {
175            properties.push(("margin", margin));
176        }
177        if let Some(ref margin_bottom) = self.margin_bottom {
178            properties.push(("margin-bottom", margin_bottom));
179        }
180        if let Some(ref margin_end) = self.margin_end {
181            properties.push(("margin-end", margin_end));
182        }
183        if let Some(ref margin_start) = self.margin_start {
184            properties.push(("margin-start", margin_start));
185        }
186        if let Some(ref margin_top) = self.margin_top {
187            properties.push(("margin-top", margin_top));
188        }
189        if let Some(ref name) = self.name {
190            properties.push(("name", name));
191        }
192        if let Some(ref no_show_all) = self.no_show_all {
193            properties.push(("no-show-all", no_show_all));
194        }
195        if let Some(ref opacity) = self.opacity {
196            properties.push(("opacity", opacity));
197        }
198        if let Some(ref parent) = self.parent {
199            properties.push(("parent", parent));
200        }
201        if let Some(ref receives_default) = self.receives_default {
202            properties.push(("receives-default", receives_default));
203        }
204        if let Some(ref sensitive) = self.sensitive {
205            properties.push(("sensitive", sensitive));
206        }
207        if let Some(ref tooltip_markup) = self.tooltip_markup {
208            properties.push(("tooltip-markup", tooltip_markup));
209        }
210        if let Some(ref tooltip_text) = self.tooltip_text {
211            properties.push(("tooltip-text", tooltip_text));
212        }
213        if let Some(ref valign) = self.valign {
214            properties.push(("valign", valign));
215        }
216        if let Some(ref vexpand) = self.vexpand {
217            properties.push(("vexpand", vexpand));
218        }
219        if let Some(ref vexpand_set) = self.vexpand_set {
220            properties.push(("vexpand-set", vexpand_set));
221        }
222        if let Some(ref visible) = self.visible {
223            properties.push(("visible", visible));
224        }
225        if let Some(ref width_request) = self.width_request {
226            properties.push(("width-request", width_request));
227        }
228        glib::Object::new(Spinner::static_type(), &properties)
229            .expect("object new")
230            .downcast()
231            .expect("downcast")
232    }
233
234    pub fn active(mut self, active: bool) -> Self {
235        self.active = Some(active);
236        self
237    }
238
239    pub fn app_paintable(mut self, app_paintable: bool) -> Self {
240        self.app_paintable = Some(app_paintable);
241        self
242    }
243
244    pub fn can_default(mut self, can_default: bool) -> Self {
245        self.can_default = Some(can_default);
246        self
247    }
248
249    pub fn can_focus(mut self, can_focus: bool) -> Self {
250        self.can_focus = Some(can_focus);
251        self
252    }
253
254    pub fn events(mut self, events: gdk::EventMask) -> Self {
255        self.events = Some(events);
256        self
257    }
258
259    pub fn expand(mut self, expand: bool) -> Self {
260        self.expand = Some(expand);
261        self
262    }
263
264    #[cfg(any(feature = "v3_20", feature = "dox"))]
265    pub fn focus_on_click(mut self, focus_on_click: bool) -> Self {
266        self.focus_on_click = Some(focus_on_click);
267        self
268    }
269
270    pub fn halign(mut self, halign: Align) -> Self {
271        self.halign = Some(halign);
272        self
273    }
274
275    pub fn has_default(mut self, has_default: bool) -> Self {
276        self.has_default = Some(has_default);
277        self
278    }
279
280    pub fn has_focus(mut self, has_focus: bool) -> Self {
281        self.has_focus = Some(has_focus);
282        self
283    }
284
285    pub fn has_tooltip(mut self, has_tooltip: bool) -> Self {
286        self.has_tooltip = Some(has_tooltip);
287        self
288    }
289
290    pub fn height_request(mut self, height_request: i32) -> Self {
291        self.height_request = Some(height_request);
292        self
293    }
294
295    pub fn hexpand(mut self, hexpand: bool) -> Self {
296        self.hexpand = Some(hexpand);
297        self
298    }
299
300    pub fn hexpand_set(mut self, hexpand_set: bool) -> Self {
301        self.hexpand_set = Some(hexpand_set);
302        self
303    }
304
305    pub fn is_focus(mut self, is_focus: bool) -> Self {
306        self.is_focus = Some(is_focus);
307        self
308    }
309
310    pub fn margin(mut self, margin: i32) -> Self {
311        self.margin = Some(margin);
312        self
313    }
314
315    pub fn margin_bottom(mut self, margin_bottom: i32) -> Self {
316        self.margin_bottom = Some(margin_bottom);
317        self
318    }
319
320    pub fn margin_end(mut self, margin_end: i32) -> Self {
321        self.margin_end = Some(margin_end);
322        self
323    }
324
325    pub fn margin_start(mut self, margin_start: i32) -> Self {
326        self.margin_start = Some(margin_start);
327        self
328    }
329
330    pub fn margin_top(mut self, margin_top: i32) -> Self {
331        self.margin_top = Some(margin_top);
332        self
333    }
334
335    pub fn name(mut self, name: &str) -> Self {
336        self.name = Some(name.to_string());
337        self
338    }
339
340    pub fn no_show_all(mut self, no_show_all: bool) -> Self {
341        self.no_show_all = Some(no_show_all);
342        self
343    }
344
345    pub fn opacity(mut self, opacity: f64) -> Self {
346        self.opacity = Some(opacity);
347        self
348    }
349
350    pub fn parent(mut self, parent: &Container) -> Self {
351        self.parent = Some(parent.clone());
352        self
353    }
354
355    pub fn receives_default(mut self, receives_default: bool) -> Self {
356        self.receives_default = Some(receives_default);
357        self
358    }
359
360    pub fn sensitive(mut self, sensitive: bool) -> Self {
361        self.sensitive = Some(sensitive);
362        self
363    }
364
365    pub fn tooltip_markup(mut self, tooltip_markup: &str) -> Self {
366        self.tooltip_markup = Some(tooltip_markup.to_string());
367        self
368    }
369
370    pub fn tooltip_text(mut self, tooltip_text: &str) -> Self {
371        self.tooltip_text = Some(tooltip_text.to_string());
372        self
373    }
374
375    pub fn valign(mut self, valign: Align) -> Self {
376        self.valign = Some(valign);
377        self
378    }
379
380    pub fn vexpand(mut self, vexpand: bool) -> Self {
381        self.vexpand = Some(vexpand);
382        self
383    }
384
385    pub fn vexpand_set(mut self, vexpand_set: bool) -> Self {
386        self.vexpand_set = Some(vexpand_set);
387        self
388    }
389
390    pub fn visible(mut self, visible: bool) -> Self {
391        self.visible = Some(visible);
392        self
393    }
394
395    pub fn width_request(mut self, width_request: i32) -> Self {
396        self.width_request = Some(width_request);
397        self
398    }
399}
400
401pub const NONE_SPINNER: Option<&Spinner> = None;
402
403pub trait SpinnerExt: 'static {
404    fn start(&self);
405
406    fn stop(&self);
407
408    fn get_property_active(&self) -> bool;
409
410    fn set_property_active(&self, active: bool);
411
412    fn connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
413}
414
415impl<O: IsA<Spinner>> SpinnerExt for O {
416    fn start(&self) {
417        unsafe {
418            gtk_sys::gtk_spinner_start(self.as_ref().to_glib_none().0);
419        }
420    }
421
422    fn stop(&self) {
423        unsafe {
424            gtk_sys::gtk_spinner_stop(self.as_ref().to_glib_none().0);
425        }
426    }
427
428    fn get_property_active(&self) -> bool {
429        unsafe {
430            let mut value = Value::from_type(<bool as StaticType>::static_type());
431            gobject_sys::g_object_get_property(
432                self.to_glib_none().0 as *mut gobject_sys::GObject,
433                b"active\0".as_ptr() as *const _,
434                value.to_glib_none_mut().0,
435            );
436            value.get().unwrap()
437        }
438    }
439
440    fn set_property_active(&self, active: bool) {
441        unsafe {
442            gobject_sys::g_object_set_property(
443                self.to_glib_none().0 as *mut gobject_sys::GObject,
444                b"active\0".as_ptr() as *const _,
445                Value::from(&active).to_glib_none().0,
446            );
447        }
448    }
449
450    fn connect_property_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
451        unsafe extern "C" fn notify_active_trampoline<P, F: Fn(&P) + 'static>(
452            this: *mut gtk_sys::GtkSpinner,
453            _param_spec: glib_sys::gpointer,
454            f: glib_sys::gpointer,
455        ) where
456            P: IsA<Spinner>,
457        {
458            let f: &F = &*(f as *const F);
459            f(&Spinner::from_glib_borrow(this).unsafe_cast())
460        }
461        unsafe {
462            let f: Box_<F> = Box_::new(f);
463            connect_raw(
464                self.as_ptr() as *mut _,
465                b"notify::active\0".as_ptr() as *const _,
466                Some(transmute(notify_active_trampoline::<Self, F> as usize)),
467                Box_::into_raw(f),
468            )
469        }
470    }
471}
472
473impl fmt::Display for Spinner {
474    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
475        write!(f, "Spinner")
476    }
477}