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