Skip to main content

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::{Accessible, AccessibleRange};
8use crate::{
9    AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Orientable, Orientation,
10    Overflow, Widget, ffi,
11};
12use glib::{
13    prelude::*,
14    signal::{SignalHandlerId, connect_raw},
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    ///
23    ///
24    /// When an application can determine how much work needs to take place
25    /// (e.g. read a fixed number of bytes from a file) and can monitor its
26    /// progress, it can use the [`ProgressBar`][crate::ProgressBar] in percentage mode and the
27    /// user sees a growing bar indicating the percentage of the work that
28    /// has been completed. In this mode, the application is required to call
29    /// [`set_fraction()`][Self::set_fraction()] periodically to update the progress bar.
30    ///
31    /// When an application has no accurate way of knowing the amount of work
32    /// to do, it can use the [`ProgressBar`][crate::ProgressBar] in activity mode, which shows
33    /// activity by a block moving back and forth within the progress area. In
34    /// this mode, the application is required to call [`pulse()`][Self::pulse()]
35    /// periodically to update the progress bar.
36    ///
37    /// There is quite a bit of flexibility provided to control the appearance
38    /// of the [`ProgressBar`][crate::ProgressBar]. Functions are provided to control the orientation
39    /// of the bar, optional text can be displayed along with the bar, and the
40    /// step size used in activity mode can be set.
41    ///
42    /// # CSS nodes
43    ///
44    /// ```text
45    /// progressbar[.osd]
46    /// ├── [text]
47    /// ╰── trough[.empty][.full]
48    ///     ╰── progress[.pulse]
49    /// ```
50    ///
51    /// [`ProgressBar`][crate::ProgressBar] has a main CSS node with name progressbar and subnodes with
52    /// names text and trough, of which the latter has a subnode named progress. The
53    /// text subnode is only present if text is shown. The progress subnode has the
54    /// style class .pulse when in activity mode. It gets the style classes .left,
55    /// .right, .top or .bottom added when the progress 'touches' the corresponding
56    /// end of the GtkProgressBar. The .osd class on the progressbar node is for use
57    /// in overlays like the one Epiphany has for page loading progress.
58    ///
59    /// # Accessibility
60    ///
61    /// [`ProgressBar`][crate::ProgressBar] uses the [enum@Gtk.AccessibleRole.progress_bar] role
62    /// and sets the [enum@Gtk.AccessibleProperty.value_min], [enum@Gtk.AccessibleProperty.value_max] and [enum@Gtk.AccessibleProperty.value_now] properties to reflect
63    /// the progress.
64    ///
65    /// ## Properties
66    ///
67    ///
68    /// #### `ellipsize`
69    ///  The preferred place to ellipsize the string.
70    ///
71    /// The text will be ellipsized if the progress bar does not have enough room
72    /// to display the entire string, specified as a [`pango::EllipsizeMode`][crate::pango::EllipsizeMode].
73    ///
74    /// Note that setting this property to a value other than
75    /// [`pango::EllipsizeMode::None`][crate::pango::EllipsizeMode::None] has the side-effect that the progress bar requests
76    /// only enough space to display the ellipsis ("..."). Another means to set a
77    /// progress bar's width is [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()].
78    ///
79    /// Readable | Writable
80    ///
81    ///
82    /// #### `fraction`
83    ///  The fraction of total work that has been completed.
84    ///
85    /// Readable | Writable
86    ///
87    ///
88    /// #### `inverted`
89    ///  Invert the direction in which the progress bar grows.
90    ///
91    /// Readable | Writable
92    ///
93    ///
94    /// #### `pulse-step`
95    ///  The fraction of total progress to move the bounding block when pulsed.
96    ///
97    /// Readable | Writable
98    ///
99    ///
100    /// #### `show-text`
101    ///  Sets whether the progress bar will show a text in addition
102    /// to the bar itself.
103    ///
104    /// The shown text is either the value of the [`text`][struct@crate::ProgressBar#text]
105    /// property or, if that is [`None`], the [`fraction`][struct@crate::ProgressBar#fraction]
106    /// value, as a percentage.
107    ///
108    /// To make a progress bar that is styled and sized suitably for showing text
109    /// (even if the actual text is blank), set [`show-text`][struct@crate::ProgressBar#show-text]
110    /// to [`true`] and [`text`][struct@crate::ProgressBar#text] to the empty string (not [`None`]).
111    ///
112    /// Readable | Writable
113    ///
114    ///
115    /// #### `text`
116    ///  Text to be displayed in the progress bar.
117    ///
118    /// Readable | Writable
119    /// <details><summary><h4>Widget</h4></summary>
120    ///
121    ///
122    /// #### `can-focus`
123    ///  Whether the widget or any of its descendents can accept
124    /// the input focus.
125    ///
126    /// This property is meant to be set by widget implementations,
127    /// typically in their instance init function.
128    ///
129    /// Readable | Writable
130    ///
131    ///
132    /// #### `can-target`
133    ///  Whether the widget can receive pointer events.
134    ///
135    /// Readable | Writable
136    ///
137    ///
138    /// #### `css-classes`
139    ///  A list of css classes applied to this widget.
140    ///
141    /// Readable | Writable
142    ///
143    ///
144    /// #### `css-name`
145    ///  The name of this widget in the CSS tree.
146    ///
147    /// This property is meant to be set by widget implementations,
148    /// typically in their instance init function.
149    ///
150    /// Readable | Writable | Construct Only
151    ///
152    ///
153    /// #### `cursor`
154    ///  The cursor used by @widget.
155    ///
156    /// Readable | Writable
157    ///
158    ///
159    /// #### `focus-on-click`
160    ///  Whether the widget should grab focus when it is clicked with the mouse.
161    ///
162    /// This property is only relevant for widgets that can take focus.
163    ///
164    /// Readable | Writable
165    ///
166    ///
167    /// #### `focusable`
168    ///  Whether this widget itself will accept the input focus.
169    ///
170    /// Readable | Writable
171    ///
172    ///
173    /// #### `halign`
174    ///  How to distribute horizontal space if widget gets extra space.
175    ///
176    /// Readable | Writable
177    ///
178    ///
179    /// #### `has-default`
180    ///  Whether the widget is the default widget.
181    ///
182    /// Readable
183    ///
184    ///
185    /// #### `has-focus`
186    ///  Whether the widget has the input focus.
187    ///
188    /// Readable
189    ///
190    ///
191    /// #### `has-tooltip`
192    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
193    /// signal on @widget.
194    ///
195    /// A true value indicates that @widget can have a tooltip, in this case
196    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
197    /// determine whether it will provide a tooltip or not.
198    ///
199    /// Readable | Writable
200    ///
201    ///
202    /// #### `height-request`
203    ///  Overrides for height request of the widget.
204    ///
205    /// If this is -1, the natural request will be used.
206    ///
207    /// Readable | Writable
208    ///
209    ///
210    /// #### `hexpand`
211    ///  Whether to expand horizontally.
212    ///
213    /// Readable | Writable
214    ///
215    ///
216    /// #### `hexpand-set`
217    ///  Whether to use the `hexpand` property.
218    ///
219    /// Readable | Writable
220    ///
221    ///
222    /// #### `layout-manager`
223    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
224    /// the preferred size of the widget, and allocate its children.
225    ///
226    /// This property is meant to be set by widget implementations,
227    /// typically in their instance init function.
228    ///
229    /// Readable | Writable
230    ///
231    ///
232    /// #### `limit-events`
233    ///  Makes this widget act like a modal dialog, with respect to
234    /// event delivery.
235    ///
236    /// Global event controllers will not handle events with targets
237    /// inside the widget, unless they are set up to ignore propagation
238    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
239    ///
240    /// Readable | Writable
241    ///
242    ///
243    /// #### `margin-bottom`
244    ///  Margin on bottom side of widget.
245    ///
246    /// This property adds margin outside of the widget's normal size
247    /// request, the margin will be added in addition to the size from
248    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
249    ///
250    /// Readable | Writable
251    ///
252    ///
253    /// #### `margin-end`
254    ///  Margin on end of widget, horizontally.
255    ///
256    /// This property supports left-to-right and right-to-left text
257    /// directions.
258    ///
259    /// This property adds margin outside of the widget's normal size
260    /// request, the margin will be added in addition to the size from
261    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
262    ///
263    /// Readable | Writable
264    ///
265    ///
266    /// #### `margin-start`
267    ///  Margin on start of widget, horizontally.
268    ///
269    /// This property supports left-to-right and right-to-left text
270    /// directions.
271    ///
272    /// This property adds margin outside of the widget's normal size
273    /// request, the margin will be added in addition to the size from
274    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
275    ///
276    /// Readable | Writable
277    ///
278    ///
279    /// #### `margin-top`
280    ///  Margin on top side of widget.
281    ///
282    /// This property adds margin outside of the widget's normal size
283    /// request, the margin will be added in addition to the size from
284    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
285    ///
286    /// Readable | Writable
287    ///
288    ///
289    /// #### `name`
290    ///  The name of the widget.
291    ///
292    /// Readable | Writable
293    ///
294    ///
295    /// #### `opacity`
296    ///  The requested opacity of the widget.
297    ///
298    /// Readable | Writable
299    ///
300    ///
301    /// #### `overflow`
302    ///  How content outside the widget's content area is treated.
303    ///
304    /// This property is meant to be set by widget implementations,
305    /// typically in their instance init function.
306    ///
307    /// Readable | Writable
308    ///
309    ///
310    /// #### `parent`
311    ///  The parent widget of this widget.
312    ///
313    /// Readable
314    ///
315    ///
316    /// #### `receives-default`
317    ///  Whether the widget will receive the default action when it is focused.
318    ///
319    /// Readable | Writable
320    ///
321    ///
322    /// #### `root`
323    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
324    ///
325    /// This will be `NULL` if the widget is not contained in a root widget.
326    ///
327    /// Readable
328    ///
329    ///
330    /// #### `scale-factor`
331    ///  The scale factor of the widget.
332    ///
333    /// Readable
334    ///
335    ///
336    /// #### `sensitive`
337    ///  Whether the widget responds to input.
338    ///
339    /// Readable | Writable
340    ///
341    ///
342    /// #### `tooltip-markup`
343    ///  Sets the text of tooltip to be the given string, which is marked up
344    /// with Pango markup.
345    ///
346    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
347    ///
348    /// This is a convenience property which will take care of getting the
349    /// tooltip shown if the given string is not `NULL`:
350    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
351    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
352    /// the default signal handler.
353    ///
354    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
355    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
356    ///
357    /// Readable | Writable
358    ///
359    ///
360    /// #### `tooltip-text`
361    ///  Sets the text of tooltip to be the given string.
362    ///
363    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
364    ///
365    /// This is a convenience property which will take care of getting the
366    /// tooltip shown if the given string is not `NULL`:
367    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
368    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
369    /// the default signal handler.
370    ///
371    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
372    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
373    ///
374    /// Readable | Writable
375    ///
376    ///
377    /// #### `valign`
378    ///  How to distribute vertical space if widget gets extra space.
379    ///
380    /// Readable | Writable
381    ///
382    ///
383    /// #### `vexpand`
384    ///  Whether to expand vertically.
385    ///
386    /// Readable | Writable
387    ///
388    ///
389    /// #### `vexpand-set`
390    ///  Whether to use the `vexpand` property.
391    ///
392    /// Readable | Writable
393    ///
394    ///
395    /// #### `visible`
396    ///  Whether the widget is visible.
397    ///
398    /// Readable | Writable
399    ///
400    ///
401    /// #### `width-request`
402    ///  Overrides for width request of the widget.
403    ///
404    /// If this is -1, the natural request will be used.
405    ///
406    /// Readable | Writable
407    /// </details>
408    /// <details><summary><h4>Accessible</h4></summary>
409    ///
410    ///
411    /// #### `accessible-role`
412    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
413    ///
414    /// The accessible role cannot be changed once set.
415    ///
416    /// Readable | Writable
417    /// </details>
418    /// <details><summary><h4>Orientable</h4></summary>
419    ///
420    ///
421    /// #### `orientation`
422    ///  The orientation of the orientable.
423    ///
424    /// Readable | Writable
425    /// </details>
426    ///
427    /// # Implements
428    ///
429    /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`AccessibleRangeExt`][trait@crate::prelude::AccessibleRangeExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
430    #[doc(alias = "GtkProgressBar")]
431    pub struct ProgressBar(Object<ffi::GtkProgressBar>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, AccessibleRange, Orientable;
432
433    match fn {
434        type_ => || ffi::gtk_progress_bar_get_type(),
435    }
436}
437
438#[cfg(not(feature = "v4_10"))]
439glib::wrapper! {
440    #[doc(alias = "GtkProgressBar")]
441    pub struct ProgressBar(Object<ffi::GtkProgressBar>) @extends Widget, @implements Buildable, ConstraintTarget, Orientable;
442
443    match fn {
444        type_ => || ffi::gtk_progress_bar_get_type(),
445    }
446}
447
448impl ProgressBar {
449    /// Creates a new [`ProgressBar`][crate::ProgressBar].
450    ///
451    /// # Returns
452    ///
453    /// a [`ProgressBar`][crate::ProgressBar].
454    #[doc(alias = "gtk_progress_bar_new")]
455    pub fn new() -> ProgressBar {
456        assert_initialized_main_thread!();
457        unsafe { Widget::from_glib_none(ffi::gtk_progress_bar_new()).unsafe_cast() }
458    }
459
460    // rustdoc-stripper-ignore-next
461    /// Creates a new builder-pattern struct instance to construct [`ProgressBar`] objects.
462    ///
463    /// This method returns an instance of [`ProgressBarBuilder`](crate::builders::ProgressBarBuilder) which can be used to create [`ProgressBar`] objects.
464    pub fn builder() -> ProgressBarBuilder {
465        ProgressBarBuilder::new()
466    }
467
468    /// Returns the ellipsizing position of the progress bar.
469    ///
470    /// See [`set_ellipsize()`][Self::set_ellipsize()].
471    ///
472    /// # Returns
473    ///
474    /// [`pango::EllipsizeMode`][crate::pango::EllipsizeMode]
475    #[doc(alias = "gtk_progress_bar_get_ellipsize")]
476    #[doc(alias = "get_ellipsize")]
477    pub fn ellipsize(&self) -> pango::EllipsizeMode {
478        unsafe { from_glib(ffi::gtk_progress_bar_get_ellipsize(self.to_glib_none().0)) }
479    }
480
481    /// Returns the current fraction of the task that’s been completed.
482    ///
483    /// # Returns
484    ///
485    /// a fraction from 0.0 to 1.0
486    #[doc(alias = "gtk_progress_bar_get_fraction")]
487    #[doc(alias = "get_fraction")]
488    pub fn fraction(&self) -> f64 {
489        unsafe { ffi::gtk_progress_bar_get_fraction(self.to_glib_none().0) }
490    }
491
492    /// Returns whether the progress bar is inverted.
493    ///
494    /// # Returns
495    ///
496    /// [`true`] if the progress bar is inverted
497    #[doc(alias = "gtk_progress_bar_get_inverted")]
498    #[doc(alias = "get_inverted")]
499    #[doc(alias = "inverted")]
500    pub fn is_inverted(&self) -> bool {
501        unsafe { from_glib(ffi::gtk_progress_bar_get_inverted(self.to_glib_none().0)) }
502    }
503
504    /// Retrieves the pulse step.
505    ///
506    /// See [`set_pulse_step()`][Self::set_pulse_step()].
507    ///
508    /// # Returns
509    ///
510    /// a fraction from 0.0 to 1.0
511    #[doc(alias = "gtk_progress_bar_get_pulse_step")]
512    #[doc(alias = "get_pulse_step")]
513    #[doc(alias = "pulse-step")]
514    pub fn pulse_step(&self) -> f64 {
515        unsafe { ffi::gtk_progress_bar_get_pulse_step(self.to_glib_none().0) }
516    }
517
518    /// Returns whether the [`ProgressBar`][crate::ProgressBar] shows text.
519    ///
520    /// See [`set_show_text()`][Self::set_show_text()].
521    ///
522    /// # Returns
523    ///
524    /// [`true`] if text is shown in the progress bar
525    #[doc(alias = "gtk_progress_bar_get_show_text")]
526    #[doc(alias = "get_show_text")]
527    #[doc(alias = "show-text")]
528    pub fn shows_text(&self) -> bool {
529        unsafe { from_glib(ffi::gtk_progress_bar_get_show_text(self.to_glib_none().0)) }
530    }
531
532    /// Retrieves the text that is displayed with the progress bar.
533    ///
534    /// The return value is a reference to the text, not a copy of it,
535    /// so will become invalid if you change the text in the progress bar.
536    ///
537    /// # Returns
538    ///
539    /// the text
540    #[doc(alias = "gtk_progress_bar_get_text")]
541    #[doc(alias = "get_text")]
542    pub fn text(&self) -> Option<glib::GString> {
543        unsafe { from_glib_none(ffi::gtk_progress_bar_get_text(self.to_glib_none().0)) }
544    }
545
546    /// Indicates that some progress has been made, but you don’t know how much.
547    ///
548    /// Causes the progress bar to enter “activity mode,” where a block
549    /// bounces back and forth. Each call to [`pulse()`][Self::pulse()]
550    /// causes the block to move by a little bit (the amount of movement
551    /// per pulse is determined by [`set_pulse_step()`][Self::set_pulse_step()]).
552    #[doc(alias = "gtk_progress_bar_pulse")]
553    pub fn pulse(&self) {
554        unsafe {
555            ffi::gtk_progress_bar_pulse(self.to_glib_none().0);
556        }
557    }
558
559    /// Sets the mode used to ellipsize the text.
560    ///
561    /// The text is ellipsized if there is not enough space
562    /// to render the entire string.
563    /// ## `mode`
564    /// a [`pango::EllipsizeMode`][crate::pango::EllipsizeMode]
565    #[doc(alias = "gtk_progress_bar_set_ellipsize")]
566    #[doc(alias = "ellipsize")]
567    pub fn set_ellipsize(&self, mode: pango::EllipsizeMode) {
568        unsafe {
569            ffi::gtk_progress_bar_set_ellipsize(self.to_glib_none().0, mode.into_glib());
570        }
571    }
572
573    /// Causes the progress bar to “fill in” the given fraction
574    /// of the bar.
575    ///
576    /// The fraction should be between 0.0 and 1.0, inclusive.
577    /// ## `fraction`
578    /// fraction of the task that’s been completed
579    #[doc(alias = "gtk_progress_bar_set_fraction")]
580    #[doc(alias = "fraction")]
581    pub fn set_fraction(&self, fraction: f64) {
582        unsafe {
583            ffi::gtk_progress_bar_set_fraction(self.to_glib_none().0, fraction);
584        }
585    }
586
587    /// Sets whether the progress bar is inverted.
588    ///
589    /// Progress bars normally grow from top to bottom or left to right.
590    /// Inverted progress bars grow in the opposite direction.
591    /// ## `inverted`
592    /// [`true`] to invert the progress bar
593    #[doc(alias = "gtk_progress_bar_set_inverted")]
594    #[doc(alias = "inverted")]
595    pub fn set_inverted(&self, inverted: bool) {
596        unsafe {
597            ffi::gtk_progress_bar_set_inverted(self.to_glib_none().0, inverted.into_glib());
598        }
599    }
600
601    /// Sets the fraction of total progress bar length to move the
602    /// bouncing block.
603    ///
604    /// The bouncing block is moved when [`pulse()`][Self::pulse()]
605    /// is called.
606    /// ## `fraction`
607    /// fraction between 0.0 and 1.0
608    #[doc(alias = "gtk_progress_bar_set_pulse_step")]
609    #[doc(alias = "pulse-step")]
610    pub fn set_pulse_step(&self, fraction: f64) {
611        unsafe {
612            ffi::gtk_progress_bar_set_pulse_step(self.to_glib_none().0, fraction);
613        }
614    }
615
616    /// Sets whether the progress bar will show text next to the bar.
617    ///
618    /// The shown text is either the value of the [`text`][struct@crate::ProgressBar#text]
619    /// property or, if that is [`None`], the [`fraction`][struct@crate::ProgressBar#fraction] value,
620    /// as a percentage.
621    ///
622    /// To make a progress bar that is styled and sized suitably for containing
623    /// text (even if the actual text is blank), set [`show-text`][struct@crate::ProgressBar#show-text]
624    /// to [`true`] and [`text`][struct@crate::ProgressBar#text] to the empty string (not [`None`]).
625    /// ## `show_text`
626    /// whether to show text
627    #[doc(alias = "gtk_progress_bar_set_show_text")]
628    #[doc(alias = "show-text")]
629    pub fn set_show_text(&self, show_text: bool) {
630        unsafe {
631            ffi::gtk_progress_bar_set_show_text(self.to_glib_none().0, show_text.into_glib());
632        }
633    }
634
635    /// Causes the given @text to appear next to the progress bar.
636    ///
637    /// If @text is [`None`] and [`show-text`][struct@crate::ProgressBar#show-text] is [`true`],
638    /// the current value of [`fraction`][struct@crate::ProgressBar#fraction] will be displayed
639    /// as a percentage.
640    ///
641    /// If @text is non-[`None`] and [`show-text`][struct@crate::ProgressBar#show-text] is [`true`],
642    /// the text will be displayed. In this case, it will not display the progress
643    /// percentage. If @text is the empty string, the progress bar will still
644    /// be styled and sized suitably for containing text, as long as
645    /// [`show-text`][struct@crate::ProgressBar#show-text] is [`true`].
646    /// ## `text`
647    /// a UTF-8 string
648    #[doc(alias = "gtk_progress_bar_set_text")]
649    #[doc(alias = "text")]
650    pub fn set_text(&self, text: Option<&str>) {
651        unsafe {
652            ffi::gtk_progress_bar_set_text(self.to_glib_none().0, text.to_glib_none().0);
653        }
654    }
655
656    #[doc(alias = "ellipsize")]
657    pub fn connect_ellipsize_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
658        unsafe extern "C" fn notify_ellipsize_trampoline<F: Fn(&ProgressBar) + 'static>(
659            this: *mut ffi::GtkProgressBar,
660            _param_spec: glib::ffi::gpointer,
661            f: glib::ffi::gpointer,
662        ) {
663            unsafe {
664                let f: &F = &*(f as *const F);
665                f(&from_glib_borrow(this))
666            }
667        }
668        unsafe {
669            let f: Box_<F> = Box_::new(f);
670            connect_raw(
671                self.as_ptr() as *mut _,
672                c"notify::ellipsize".as_ptr(),
673                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
674                    notify_ellipsize_trampoline::<F> as *const (),
675                )),
676                Box_::into_raw(f),
677            )
678        }
679    }
680
681    #[doc(alias = "fraction")]
682    pub fn connect_fraction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
683        unsafe extern "C" fn notify_fraction_trampoline<F: Fn(&ProgressBar) + 'static>(
684            this: *mut ffi::GtkProgressBar,
685            _param_spec: glib::ffi::gpointer,
686            f: glib::ffi::gpointer,
687        ) {
688            unsafe {
689                let f: &F = &*(f as *const F);
690                f(&from_glib_borrow(this))
691            }
692        }
693        unsafe {
694            let f: Box_<F> = Box_::new(f);
695            connect_raw(
696                self.as_ptr() as *mut _,
697                c"notify::fraction".as_ptr(),
698                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
699                    notify_fraction_trampoline::<F> as *const (),
700                )),
701                Box_::into_raw(f),
702            )
703        }
704    }
705
706    #[doc(alias = "inverted")]
707    pub fn connect_inverted_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
708        unsafe extern "C" fn notify_inverted_trampoline<F: Fn(&ProgressBar) + 'static>(
709            this: *mut ffi::GtkProgressBar,
710            _param_spec: glib::ffi::gpointer,
711            f: glib::ffi::gpointer,
712        ) {
713            unsafe {
714                let f: &F = &*(f as *const F);
715                f(&from_glib_borrow(this))
716            }
717        }
718        unsafe {
719            let f: Box_<F> = Box_::new(f);
720            connect_raw(
721                self.as_ptr() as *mut _,
722                c"notify::inverted".as_ptr(),
723                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
724                    notify_inverted_trampoline::<F> as *const (),
725                )),
726                Box_::into_raw(f),
727            )
728        }
729    }
730
731    #[doc(alias = "pulse-step")]
732    pub fn connect_pulse_step_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
733        unsafe extern "C" fn notify_pulse_step_trampoline<F: Fn(&ProgressBar) + 'static>(
734            this: *mut ffi::GtkProgressBar,
735            _param_spec: glib::ffi::gpointer,
736            f: glib::ffi::gpointer,
737        ) {
738            unsafe {
739                let f: &F = &*(f as *const F);
740                f(&from_glib_borrow(this))
741            }
742        }
743        unsafe {
744            let f: Box_<F> = Box_::new(f);
745            connect_raw(
746                self.as_ptr() as *mut _,
747                c"notify::pulse-step".as_ptr(),
748                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
749                    notify_pulse_step_trampoline::<F> as *const (),
750                )),
751                Box_::into_raw(f),
752            )
753        }
754    }
755
756    #[doc(alias = "show-text")]
757    pub fn connect_show_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
758        unsafe extern "C" fn notify_show_text_trampoline<F: Fn(&ProgressBar) + 'static>(
759            this: *mut ffi::GtkProgressBar,
760            _param_spec: glib::ffi::gpointer,
761            f: glib::ffi::gpointer,
762        ) {
763            unsafe {
764                let f: &F = &*(f as *const F);
765                f(&from_glib_borrow(this))
766            }
767        }
768        unsafe {
769            let f: Box_<F> = Box_::new(f);
770            connect_raw(
771                self.as_ptr() as *mut _,
772                c"notify::show-text".as_ptr(),
773                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
774                    notify_show_text_trampoline::<F> as *const (),
775                )),
776                Box_::into_raw(f),
777            )
778        }
779    }
780
781    #[doc(alias = "text")]
782    pub fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
783        unsafe extern "C" fn notify_text_trampoline<F: Fn(&ProgressBar) + 'static>(
784            this: *mut ffi::GtkProgressBar,
785            _param_spec: glib::ffi::gpointer,
786            f: glib::ffi::gpointer,
787        ) {
788            unsafe {
789                let f: &F = &*(f as *const F);
790                f(&from_glib_borrow(this))
791            }
792        }
793        unsafe {
794            let f: Box_<F> = Box_::new(f);
795            connect_raw(
796                self.as_ptr() as *mut _,
797                c"notify::text".as_ptr(),
798                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
799                    notify_text_trampoline::<F> as *const (),
800                )),
801                Box_::into_raw(f),
802            )
803        }
804    }
805}
806
807impl Default for ProgressBar {
808    fn default() -> Self {
809        Self::new()
810    }
811}
812
813// rustdoc-stripper-ignore-next
814/// A [builder-pattern] type to construct [`ProgressBar`] objects.
815///
816/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
817#[must_use = "The builder must be built to be used"]
818pub struct ProgressBarBuilder {
819    builder: glib::object::ObjectBuilder<'static, ProgressBar>,
820}
821
822impl ProgressBarBuilder {
823    fn new() -> Self {
824        Self {
825            builder: glib::object::Object::builder(),
826        }
827    }
828
829    /// The preferred place to ellipsize the string.
830    ///
831    /// The text will be ellipsized if the progress bar does not have enough room
832    /// to display the entire string, specified as a [`pango::EllipsizeMode`][crate::pango::EllipsizeMode].
833    ///
834    /// Note that setting this property to a value other than
835    /// [`pango::EllipsizeMode::None`][crate::pango::EllipsizeMode::None] has the side-effect that the progress bar requests
836    /// only enough space to display the ellipsis ("..."). Another means to set a
837    /// progress bar's width is [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()].
838    pub fn ellipsize(self, ellipsize: pango::EllipsizeMode) -> Self {
839        Self {
840            builder: self.builder.property("ellipsize", ellipsize),
841        }
842    }
843
844    /// The fraction of total work that has been completed.
845    pub fn fraction(self, fraction: f64) -> Self {
846        Self {
847            builder: self.builder.property("fraction", fraction),
848        }
849    }
850
851    /// Invert the direction in which the progress bar grows.
852    pub fn inverted(self, inverted: bool) -> Self {
853        Self {
854            builder: self.builder.property("inverted", inverted),
855        }
856    }
857
858    /// The fraction of total progress to move the bounding block when pulsed.
859    pub fn pulse_step(self, pulse_step: f64) -> Self {
860        Self {
861            builder: self.builder.property("pulse-step", pulse_step),
862        }
863    }
864
865    /// Sets whether the progress bar will show a text in addition
866    /// to the bar itself.
867    ///
868    /// The shown text is either the value of the [`text`][struct@crate::ProgressBar#text]
869    /// property or, if that is [`None`], the [`fraction`][struct@crate::ProgressBar#fraction]
870    /// value, as a percentage.
871    ///
872    /// To make a progress bar that is styled and sized suitably for showing text
873    /// (even if the actual text is blank), set [`show-text`][struct@crate::ProgressBar#show-text]
874    /// to [`true`] and [`text`][struct@crate::ProgressBar#text] to the empty string (not [`None`]).
875    pub fn show_text(self, show_text: bool) -> Self {
876        Self {
877            builder: self.builder.property("show-text", show_text),
878        }
879    }
880
881    /// Text to be displayed in the progress bar.
882    pub fn text(self, text: impl Into<glib::GString>) -> Self {
883        Self {
884            builder: self.builder.property("text", text.into()),
885        }
886    }
887
888    /// Whether the widget or any of its descendents can accept
889    /// the input focus.
890    ///
891    /// This property is meant to be set by widget implementations,
892    /// typically in their instance init function.
893    pub fn can_focus(self, can_focus: bool) -> Self {
894        Self {
895            builder: self.builder.property("can-focus", can_focus),
896        }
897    }
898
899    /// Whether the widget can receive pointer events.
900    pub fn can_target(self, can_target: bool) -> Self {
901        Self {
902            builder: self.builder.property("can-target", can_target),
903        }
904    }
905
906    /// A list of css classes applied to this widget.
907    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
908        Self {
909            builder: self.builder.property("css-classes", css_classes.into()),
910        }
911    }
912
913    /// The name of this widget in the CSS tree.
914    ///
915    /// This property is meant to be set by widget implementations,
916    /// typically in their instance init function.
917    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
918        Self {
919            builder: self.builder.property("css-name", css_name.into()),
920        }
921    }
922
923    /// The cursor used by @widget.
924    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
925        Self {
926            builder: self.builder.property("cursor", cursor.clone()),
927        }
928    }
929
930    /// Whether the widget should grab focus when it is clicked with the mouse.
931    ///
932    /// This property is only relevant for widgets that can take focus.
933    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
934        Self {
935            builder: self.builder.property("focus-on-click", focus_on_click),
936        }
937    }
938
939    /// Whether this widget itself will accept the input focus.
940    pub fn focusable(self, focusable: bool) -> Self {
941        Self {
942            builder: self.builder.property("focusable", focusable),
943        }
944    }
945
946    /// How to distribute horizontal space if widget gets extra space.
947    pub fn halign(self, halign: Align) -> Self {
948        Self {
949            builder: self.builder.property("halign", halign),
950        }
951    }
952
953    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
954    /// signal on @widget.
955    ///
956    /// A true value indicates that @widget can have a tooltip, in this case
957    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
958    /// determine whether it will provide a tooltip or not.
959    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
960        Self {
961            builder: self.builder.property("has-tooltip", has_tooltip),
962        }
963    }
964
965    /// Overrides for height request of the widget.
966    ///
967    /// If this is -1, the natural request will be used.
968    pub fn height_request(self, height_request: i32) -> Self {
969        Self {
970            builder: self.builder.property("height-request", height_request),
971        }
972    }
973
974    /// Whether to expand horizontally.
975    pub fn hexpand(self, hexpand: bool) -> Self {
976        Self {
977            builder: self.builder.property("hexpand", hexpand),
978        }
979    }
980
981    /// Whether to use the `hexpand` property.
982    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
983        Self {
984            builder: self.builder.property("hexpand-set", hexpand_set),
985        }
986    }
987
988    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
989    /// the preferred size of the widget, and allocate its children.
990    ///
991    /// This property is meant to be set by widget implementations,
992    /// typically in their instance init function.
993    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
994        Self {
995            builder: self
996                .builder
997                .property("layout-manager", layout_manager.clone().upcast()),
998        }
999    }
1000
1001    /// Makes this widget act like a modal dialog, with respect to
1002    /// event delivery.
1003    ///
1004    /// Global event controllers will not handle events with targets
1005    /// inside the widget, unless they are set up to ignore propagation
1006    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1007    #[cfg(feature = "v4_18")]
1008    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1009    pub fn limit_events(self, limit_events: bool) -> Self {
1010        Self {
1011            builder: self.builder.property("limit-events", limit_events),
1012        }
1013    }
1014
1015    /// Margin on bottom side of widget.
1016    ///
1017    /// This property adds margin outside of the widget's normal size
1018    /// request, the margin will be added in addition to the size from
1019    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1020    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1021        Self {
1022            builder: self.builder.property("margin-bottom", margin_bottom),
1023        }
1024    }
1025
1026    /// Margin on end of widget, horizontally.
1027    ///
1028    /// This property supports left-to-right and right-to-left text
1029    /// directions.
1030    ///
1031    /// This property adds margin outside of the widget's normal size
1032    /// request, the margin will be added in addition to the size from
1033    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1034    pub fn margin_end(self, margin_end: i32) -> Self {
1035        Self {
1036            builder: self.builder.property("margin-end", margin_end),
1037        }
1038    }
1039
1040    /// Margin on start of widget, horizontally.
1041    ///
1042    /// This property supports left-to-right and right-to-left text
1043    /// directions.
1044    ///
1045    /// This property adds margin outside of the widget's normal size
1046    /// request, the margin will be added in addition to the size from
1047    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1048    pub fn margin_start(self, margin_start: i32) -> Self {
1049        Self {
1050            builder: self.builder.property("margin-start", margin_start),
1051        }
1052    }
1053
1054    /// Margin on top side of widget.
1055    ///
1056    /// This property adds margin outside of the widget's normal size
1057    /// request, the margin will be added in addition to the size from
1058    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1059    pub fn margin_top(self, margin_top: i32) -> Self {
1060        Self {
1061            builder: self.builder.property("margin-top", margin_top),
1062        }
1063    }
1064
1065    /// The name of the widget.
1066    pub fn name(self, name: impl Into<glib::GString>) -> Self {
1067        Self {
1068            builder: self.builder.property("name", name.into()),
1069        }
1070    }
1071
1072    /// The requested opacity of the widget.
1073    pub fn opacity(self, opacity: f64) -> Self {
1074        Self {
1075            builder: self.builder.property("opacity", opacity),
1076        }
1077    }
1078
1079    /// How content outside the widget's content area is treated.
1080    ///
1081    /// This property is meant to be set by widget implementations,
1082    /// typically in their instance init function.
1083    pub fn overflow(self, overflow: Overflow) -> Self {
1084        Self {
1085            builder: self.builder.property("overflow", overflow),
1086        }
1087    }
1088
1089    /// Whether the widget will receive the default action when it is focused.
1090    pub fn receives_default(self, receives_default: bool) -> Self {
1091        Self {
1092            builder: self.builder.property("receives-default", receives_default),
1093        }
1094    }
1095
1096    /// Whether the widget responds to input.
1097    pub fn sensitive(self, sensitive: bool) -> Self {
1098        Self {
1099            builder: self.builder.property("sensitive", sensitive),
1100        }
1101    }
1102
1103    /// Sets the text of tooltip to be the given string, which is marked up
1104    /// with Pango markup.
1105    ///
1106    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1107    ///
1108    /// This is a convenience property which will take care of getting the
1109    /// tooltip shown if the given string is not `NULL`:
1110    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1111    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1112    /// the default signal handler.
1113    ///
1114    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1115    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1116    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1117        Self {
1118            builder: self
1119                .builder
1120                .property("tooltip-markup", tooltip_markup.into()),
1121        }
1122    }
1123
1124    /// Sets the text of tooltip to be the given string.
1125    ///
1126    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1127    ///
1128    /// This is a convenience property which will take care of getting the
1129    /// tooltip shown if the given string is not `NULL`:
1130    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1131    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1132    /// the default signal handler.
1133    ///
1134    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1135    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1136    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1137        Self {
1138            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1139        }
1140    }
1141
1142    /// How to distribute vertical space if widget gets extra space.
1143    pub fn valign(self, valign: Align) -> Self {
1144        Self {
1145            builder: self.builder.property("valign", valign),
1146        }
1147    }
1148
1149    /// Whether to expand vertically.
1150    pub fn vexpand(self, vexpand: bool) -> Self {
1151        Self {
1152            builder: self.builder.property("vexpand", vexpand),
1153        }
1154    }
1155
1156    /// Whether to use the `vexpand` property.
1157    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1158        Self {
1159            builder: self.builder.property("vexpand-set", vexpand_set),
1160        }
1161    }
1162
1163    /// Whether the widget is visible.
1164    pub fn visible(self, visible: bool) -> Self {
1165        Self {
1166            builder: self.builder.property("visible", visible),
1167        }
1168    }
1169
1170    /// Overrides for width request of the widget.
1171    ///
1172    /// If this is -1, the natural request will be used.
1173    pub fn width_request(self, width_request: i32) -> Self {
1174        Self {
1175            builder: self.builder.property("width-request", width_request),
1176        }
1177    }
1178
1179    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1180    ///
1181    /// The accessible role cannot be changed once set.
1182    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1183        Self {
1184            builder: self.builder.property("accessible-role", accessible_role),
1185        }
1186    }
1187
1188    /// The orientation of the orientable.
1189    pub fn orientation(self, orientation: Orientation) -> Self {
1190        Self {
1191            builder: self.builder.property("orientation", orientation),
1192        }
1193    }
1194
1195    // rustdoc-stripper-ignore-next
1196    /// Build the [`ProgressBar`].
1197    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1198    pub fn build(self) -> ProgressBar {
1199        assert_initialized_main_thread!();
1200        self.builder.build()
1201    }
1202}