[go: up one dir, main page]

gtk4/auto/
progress_bar.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
5#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::AccessibleRange;
8use crate::{
9    ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Orientable,
10    Orientation, Overflow, Widget,
11};
12use glib::{
13    prelude::*,
14    signal::{connect_raw, SignalHandlerId},
15    translate::*,
16};
17use std::boxed::Box as Box_;
18
19#[cfg(feature = "v4_10")]
20#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
21glib::wrapper! {
22    #[doc(alias = "GtkProgressBar")]
23    pub struct ProgressBar(Object<ffi::GtkProgressBar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, AccessibleRange, Orientable;
24
25    match fn {
26        type_ => || ffi::gtk_progress_bar_get_type(),
27    }
28}
29
30#[cfg(not(any(feature = "v4_10")))]
31glib::wrapper! {
32    #[doc(alias = "GtkProgressBar")]
33    pub struct ProgressBar(Object<ffi::GtkProgressBar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Orientable;
34
35    match fn {
36        type_ => || ffi::gtk_progress_bar_get_type(),
37    }
38}
39
40impl ProgressBar {
41    #[doc(alias = "gtk_progress_bar_new")]
42    pub fn new() -> ProgressBar {
43        assert_initialized_main_thread!();
44        unsafe { Widget::from_glib_none(ffi::gtk_progress_bar_new()).unsafe_cast() }
45    }
46
47    // rustdoc-stripper-ignore-next
48    /// Creates a new builder-pattern struct instance to construct [`ProgressBar`] objects.
49    ///
50    /// This method returns an instance of [`ProgressBarBuilder`](crate::builders::ProgressBarBuilder) which can be used to create [`ProgressBar`] objects.
51    pub fn builder() -> ProgressBarBuilder {
52        ProgressBarBuilder::new()
53    }
54
55    #[doc(alias = "gtk_progress_bar_get_ellipsize")]
56    #[doc(alias = "get_ellipsize")]
57    pub fn ellipsize(&self) -> pango::EllipsizeMode {
58        unsafe { from_glib(ffi::gtk_progress_bar_get_ellipsize(self.to_glib_none().0)) }
59    }
60
61    #[doc(alias = "gtk_progress_bar_get_fraction")]
62    #[doc(alias = "get_fraction")]
63    pub fn fraction(&self) -> f64 {
64        unsafe { ffi::gtk_progress_bar_get_fraction(self.to_glib_none().0) }
65    }
66
67    #[doc(alias = "gtk_progress_bar_get_inverted")]
68    #[doc(alias = "get_inverted")]
69    #[doc(alias = "inverted")]
70    pub fn is_inverted(&self) -> bool {
71        unsafe { from_glib(ffi::gtk_progress_bar_get_inverted(self.to_glib_none().0)) }
72    }
73
74    #[doc(alias = "gtk_progress_bar_get_pulse_step")]
75    #[doc(alias = "get_pulse_step")]
76    #[doc(alias = "pulse-step")]
77    pub fn pulse_step(&self) -> f64 {
78        unsafe { ffi::gtk_progress_bar_get_pulse_step(self.to_glib_none().0) }
79    }
80
81    #[doc(alias = "gtk_progress_bar_get_show_text")]
82    #[doc(alias = "get_show_text")]
83    #[doc(alias = "show-text")]
84    pub fn shows_text(&self) -> bool {
85        unsafe { from_glib(ffi::gtk_progress_bar_get_show_text(self.to_glib_none().0)) }
86    }
87
88    #[doc(alias = "gtk_progress_bar_get_text")]
89    #[doc(alias = "get_text")]
90    pub fn text(&self) -> Option<glib::GString> {
91        unsafe { from_glib_none(ffi::gtk_progress_bar_get_text(self.to_glib_none().0)) }
92    }
93
94    #[doc(alias = "gtk_progress_bar_pulse")]
95    pub fn pulse(&self) {
96        unsafe {
97            ffi::gtk_progress_bar_pulse(self.to_glib_none().0);
98        }
99    }
100
101    #[doc(alias = "gtk_progress_bar_set_ellipsize")]
102    #[doc(alias = "ellipsize")]
103    pub fn set_ellipsize(&self, mode: pango::EllipsizeMode) {
104        unsafe {
105            ffi::gtk_progress_bar_set_ellipsize(self.to_glib_none().0, mode.into_glib());
106        }
107    }
108
109    #[doc(alias = "gtk_progress_bar_set_fraction")]
110    #[doc(alias = "fraction")]
111    pub fn set_fraction(&self, fraction: f64) {
112        unsafe {
113            ffi::gtk_progress_bar_set_fraction(self.to_glib_none().0, fraction);
114        }
115    }
116
117    #[doc(alias = "gtk_progress_bar_set_inverted")]
118    #[doc(alias = "inverted")]
119    pub fn set_inverted(&self, inverted: bool) {
120        unsafe {
121            ffi::gtk_progress_bar_set_inverted(self.to_glib_none().0, inverted.into_glib());
122        }
123    }
124
125    #[doc(alias = "gtk_progress_bar_set_pulse_step")]
126    #[doc(alias = "pulse-step")]
127    pub fn set_pulse_step(&self, fraction: f64) {
128        unsafe {
129            ffi::gtk_progress_bar_set_pulse_step(self.to_glib_none().0, fraction);
130        }
131    }
132
133    #[doc(alias = "gtk_progress_bar_set_show_text")]
134    #[doc(alias = "show-text")]
135    pub fn set_show_text(&self, show_text: bool) {
136        unsafe {
137            ffi::gtk_progress_bar_set_show_text(self.to_glib_none().0, show_text.into_glib());
138        }
139    }
140
141    #[doc(alias = "gtk_progress_bar_set_text")]
142    #[doc(alias = "text")]
143    pub fn set_text(&self, text: Option<&str>) {
144        unsafe {
145            ffi::gtk_progress_bar_set_text(self.to_glib_none().0, text.to_glib_none().0);
146        }
147    }
148
149    #[doc(alias = "ellipsize")]
150    pub fn connect_ellipsize_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
151        unsafe extern "C" fn notify_ellipsize_trampoline<F: Fn(&ProgressBar) + 'static>(
152            this: *mut ffi::GtkProgressBar,
153            _param_spec: glib::ffi::gpointer,
154            f: glib::ffi::gpointer,
155        ) {
156            let f: &F = &*(f as *const F);
157            f(&from_glib_borrow(this))
158        }
159        unsafe {
160            let f: Box_<F> = Box_::new(f);
161            connect_raw(
162                self.as_ptr() as *mut _,
163                c"notify::ellipsize".as_ptr() as *const _,
164                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
165                    notify_ellipsize_trampoline::<F> as *const (),
166                )),
167                Box_::into_raw(f),
168            )
169        }
170    }
171
172    #[doc(alias = "fraction")]
173    pub fn connect_fraction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
174        unsafe extern "C" fn notify_fraction_trampoline<F: Fn(&ProgressBar) + 'static>(
175            this: *mut ffi::GtkProgressBar,
176            _param_spec: glib::ffi::gpointer,
177            f: glib::ffi::gpointer,
178        ) {
179            let f: &F = &*(f as *const F);
180            f(&from_glib_borrow(this))
181        }
182        unsafe {
183            let f: Box_<F> = Box_::new(f);
184            connect_raw(
185                self.as_ptr() as *mut _,
186                c"notify::fraction".as_ptr() as *const _,
187                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
188                    notify_fraction_trampoline::<F> as *const (),
189                )),
190                Box_::into_raw(f),
191            )
192        }
193    }
194
195    #[doc(alias = "inverted")]
196    pub fn connect_inverted_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
197        unsafe extern "C" fn notify_inverted_trampoline<F: Fn(&ProgressBar) + 'static>(
198            this: *mut ffi::GtkProgressBar,
199            _param_spec: glib::ffi::gpointer,
200            f: glib::ffi::gpointer,
201        ) {
202            let f: &F = &*(f as *const F);
203            f(&from_glib_borrow(this))
204        }
205        unsafe {
206            let f: Box_<F> = Box_::new(f);
207            connect_raw(
208                self.as_ptr() as *mut _,
209                c"notify::inverted".as_ptr() as *const _,
210                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
211                    notify_inverted_trampoline::<F> as *const (),
212                )),
213                Box_::into_raw(f),
214            )
215        }
216    }
217
218    #[doc(alias = "pulse-step")]
219    pub fn connect_pulse_step_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
220        unsafe extern "C" fn notify_pulse_step_trampoline<F: Fn(&ProgressBar) + 'static>(
221            this: *mut ffi::GtkProgressBar,
222            _param_spec: glib::ffi::gpointer,
223            f: glib::ffi::gpointer,
224        ) {
225            let f: &F = &*(f as *const F);
226            f(&from_glib_borrow(this))
227        }
228        unsafe {
229            let f: Box_<F> = Box_::new(f);
230            connect_raw(
231                self.as_ptr() as *mut _,
232                c"notify::pulse-step".as_ptr() as *const _,
233                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
234                    notify_pulse_step_trampoline::<F> as *const (),
235                )),
236                Box_::into_raw(f),
237            )
238        }
239    }
240
241    #[doc(alias = "show-text")]
242    pub fn connect_show_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
243        unsafe extern "C" fn notify_show_text_trampoline<F: Fn(&ProgressBar) + 'static>(
244            this: *mut ffi::GtkProgressBar,
245            _param_spec: glib::ffi::gpointer,
246            f: glib::ffi::gpointer,
247        ) {
248            let f: &F = &*(f as *const F);
249            f(&from_glib_borrow(this))
250        }
251        unsafe {
252            let f: Box_<F> = Box_::new(f);
253            connect_raw(
254                self.as_ptr() as *mut _,
255                c"notify::show-text".as_ptr() as *const _,
256                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
257                    notify_show_text_trampoline::<F> as *const (),
258                )),
259                Box_::into_raw(f),
260            )
261        }
262    }
263
264    #[doc(alias = "text")]
265    pub fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
266        unsafe extern "C" fn notify_text_trampoline<F: Fn(&ProgressBar) + 'static>(
267            this: *mut ffi::GtkProgressBar,
268            _param_spec: glib::ffi::gpointer,
269            f: glib::ffi::gpointer,
270        ) {
271            let f: &F = &*(f as *const F);
272            f(&from_glib_borrow(this))
273        }
274        unsafe {
275            let f: Box_<F> = Box_::new(f);
276            connect_raw(
277                self.as_ptr() as *mut _,
278                c"notify::text".as_ptr() as *const _,
279                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
280                    notify_text_trampoline::<F> as *const (),
281                )),
282                Box_::into_raw(f),
283            )
284        }
285    }
286}
287
288impl Default for ProgressBar {
289    fn default() -> Self {
290        Self::new()
291    }
292}
293
294// rustdoc-stripper-ignore-next
295/// A [builder-pattern] type to construct [`ProgressBar`] objects.
296///
297/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
298#[must_use = "The builder must be built to be used"]
299pub struct ProgressBarBuilder {
300    builder: glib::object::ObjectBuilder<'static, ProgressBar>,
301}
302
303impl ProgressBarBuilder {
304    fn new() -> Self {
305        Self {
306            builder: glib::object::Object::builder(),
307        }
308    }
309
310    pub fn ellipsize(self, ellipsize: pango::EllipsizeMode) -> Self {
311        Self {
312            builder: self.builder.property("ellipsize", ellipsize),
313        }
314    }
315
316    pub fn fraction(self, fraction: f64) -> Self {
317        Self {
318            builder: self.builder.property("fraction", fraction),
319        }
320    }
321
322    pub fn inverted(self, inverted: bool) -> Self {
323        Self {
324            builder: self.builder.property("inverted", inverted),
325        }
326    }
327
328    pub fn pulse_step(self, pulse_step: f64) -> Self {
329        Self {
330            builder: self.builder.property("pulse-step", pulse_step),
331        }
332    }
333
334    pub fn show_text(self, show_text: bool) -> Self {
335        Self {
336            builder: self.builder.property("show-text", show_text),
337        }
338    }
339
340    pub fn text(self, text: impl Into<glib::GString>) -> Self {
341        Self {
342            builder: self.builder.property("text", text.into()),
343        }
344    }
345
346    pub fn can_focus(self, can_focus: bool) -> Self {
347        Self {
348            builder: self.builder.property("can-focus", can_focus),
349        }
350    }
351
352    pub fn can_target(self, can_target: bool) -> Self {
353        Self {
354            builder: self.builder.property("can-target", can_target),
355        }
356    }
357
358    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
359        Self {
360            builder: self.builder.property("css-classes", css_classes.into()),
361        }
362    }
363
364    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
365        Self {
366            builder: self.builder.property("css-name", css_name.into()),
367        }
368    }
369
370    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
371        Self {
372            builder: self.builder.property("cursor", cursor.clone()),
373        }
374    }
375
376    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
377        Self {
378            builder: self.builder.property("focus-on-click", focus_on_click),
379        }
380    }
381
382    pub fn focusable(self, focusable: bool) -> Self {
383        Self {
384            builder: self.builder.property("focusable", focusable),
385        }
386    }
387
388    pub fn halign(self, halign: Align) -> Self {
389        Self {
390            builder: self.builder.property("halign", halign),
391        }
392    }
393
394    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
395        Self {
396            builder: self.builder.property("has-tooltip", has_tooltip),
397        }
398    }
399
400    pub fn height_request(self, height_request: i32) -> Self {
401        Self {
402            builder: self.builder.property("height-request", height_request),
403        }
404    }
405
406    pub fn hexpand(self, hexpand: bool) -> Self {
407        Self {
408            builder: self.builder.property("hexpand", hexpand),
409        }
410    }
411
412    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
413        Self {
414            builder: self.builder.property("hexpand-set", hexpand_set),
415        }
416    }
417
418    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
419        Self {
420            builder: self
421                .builder
422                .property("layout-manager", layout_manager.clone().upcast()),
423        }
424    }
425
426    #[cfg(feature = "v4_18")]
427    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
428    pub fn limit_events(self, limit_events: bool) -> Self {
429        Self {
430            builder: self.builder.property("limit-events", limit_events),
431        }
432    }
433
434    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
435        Self {
436            builder: self.builder.property("margin-bottom", margin_bottom),
437        }
438    }
439
440    pub fn margin_end(self, margin_end: i32) -> Self {
441        Self {
442            builder: self.builder.property("margin-end", margin_end),
443        }
444    }
445
446    pub fn margin_start(self, margin_start: i32) -> Self {
447        Self {
448            builder: self.builder.property("margin-start", margin_start),
449        }
450    }
451
452    pub fn margin_top(self, margin_top: i32) -> Self {
453        Self {
454            builder: self.builder.property("margin-top", margin_top),
455        }
456    }
457
458    pub fn name(self, name: impl Into<glib::GString>) -> Self {
459        Self {
460            builder: self.builder.property("name", name.into()),
461        }
462    }
463
464    pub fn opacity(self, opacity: f64) -> Self {
465        Self {
466            builder: self.builder.property("opacity", opacity),
467        }
468    }
469
470    pub fn overflow(self, overflow: Overflow) -> Self {
471        Self {
472            builder: self.builder.property("overflow", overflow),
473        }
474    }
475
476    pub fn receives_default(self, receives_default: bool) -> Self {
477        Self {
478            builder: self.builder.property("receives-default", receives_default),
479        }
480    }
481
482    pub fn sensitive(self, sensitive: bool) -> Self {
483        Self {
484            builder: self.builder.property("sensitive", sensitive),
485        }
486    }
487
488    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
489        Self {
490            builder: self
491                .builder
492                .property("tooltip-markup", tooltip_markup.into()),
493        }
494    }
495
496    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
497        Self {
498            builder: self.builder.property("tooltip-text", tooltip_text.into()),
499        }
500    }
501
502    pub fn valign(self, valign: Align) -> Self {
503        Self {
504            builder: self.builder.property("valign", valign),
505        }
506    }
507
508    pub fn vexpand(self, vexpand: bool) -> Self {
509        Self {
510            builder: self.builder.property("vexpand", vexpand),
511        }
512    }
513
514    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
515        Self {
516            builder: self.builder.property("vexpand-set", vexpand_set),
517        }
518    }
519
520    pub fn visible(self, visible: bool) -> Self {
521        Self {
522            builder: self.builder.property("visible", visible),
523        }
524    }
525
526    pub fn width_request(self, width_request: i32) -> Self {
527        Self {
528            builder: self.builder.property("width-request", width_request),
529        }
530    }
531
532    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
533        Self {
534            builder: self.builder.property("accessible-role", accessible_role),
535        }
536    }
537
538    pub fn orientation(self, orientation: Orientation) -> Self {
539        Self {
540            builder: self.builder.property("orientation", orientation),
541        }
542    }
543
544    // rustdoc-stripper-ignore-next
545    /// Build the [`ProgressBar`].
546    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
547    pub fn build(self) -> ProgressBar {
548        assert_initialized_main_thread!();
549        self.builder.build()
550    }
551}