gtk4/auto/
progress_bar.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5#[cfg(feature = "v4_10")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
7use crate::AccessibleRange;
8use crate::{
9    ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Orientable,
10    Orientation, Overflow, Widget,
11};
12use glib::{
13    prelude::*,
14    signal::{connect_raw, SignalHandlerId},
15    translate::*,
16};
17use std::boxed::Box as Box_;
18
19#[cfg(feature = "v4_10")]
20#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
21glib::wrapper! {
22    /// 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            let f: &F = &*(f as *const F);
672            f(&from_glib_borrow(this))
673        }
674        unsafe {
675            let f: Box_<F> = Box_::new(f);
676            connect_raw(
677                self.as_ptr() as *mut _,
678                c"notify::ellipsize".as_ptr() as *const _,
679                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
680                    notify_ellipsize_trampoline::<F> as *const (),
681                )),
682                Box_::into_raw(f),
683            )
684        }
685    }
686
687    #[doc(alias = "fraction")]
688    pub fn connect_fraction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
689        unsafe extern "C" fn notify_fraction_trampoline<F: Fn(&ProgressBar) + 'static>(
690            this: *mut ffi::GtkProgressBar,
691            _param_spec: glib::ffi::gpointer,
692            f: glib::ffi::gpointer,
693        ) {
694            let f: &F = &*(f as *const F);
695            f(&from_glib_borrow(this))
696        }
697        unsafe {
698            let f: Box_<F> = Box_::new(f);
699            connect_raw(
700                self.as_ptr() as *mut _,
701                c"notify::fraction".as_ptr() as *const _,
702                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
703                    notify_fraction_trampoline::<F> as *const (),
704                )),
705                Box_::into_raw(f),
706            )
707        }
708    }
709
710    #[doc(alias = "inverted")]
711    pub fn connect_inverted_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
712        unsafe extern "C" fn notify_inverted_trampoline<F: Fn(&ProgressBar) + 'static>(
713            this: *mut ffi::GtkProgressBar,
714            _param_spec: glib::ffi::gpointer,
715            f: glib::ffi::gpointer,
716        ) {
717            let f: &F = &*(f as *const F);
718            f(&from_glib_borrow(this))
719        }
720        unsafe {
721            let f: Box_<F> = Box_::new(f);
722            connect_raw(
723                self.as_ptr() as *mut _,
724                c"notify::inverted".as_ptr() as *const _,
725                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
726                    notify_inverted_trampoline::<F> as *const (),
727                )),
728                Box_::into_raw(f),
729            )
730        }
731    }
732
733    #[doc(alias = "pulse-step")]
734    pub fn connect_pulse_step_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
735        unsafe extern "C" fn notify_pulse_step_trampoline<F: Fn(&ProgressBar) + 'static>(
736            this: *mut ffi::GtkProgressBar,
737            _param_spec: glib::ffi::gpointer,
738            f: glib::ffi::gpointer,
739        ) {
740            let f: &F = &*(f as *const F);
741            f(&from_glib_borrow(this))
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() as *const _,
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            let f: &F = &*(f as *const F);
764            f(&from_glib_borrow(this))
765        }
766        unsafe {
767            let f: Box_<F> = Box_::new(f);
768            connect_raw(
769                self.as_ptr() as *mut _,
770                c"notify::show-text".as_ptr() as *const _,
771                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
772                    notify_show_text_trampoline::<F> as *const (),
773                )),
774                Box_::into_raw(f),
775            )
776        }
777    }
778
779    #[doc(alias = "text")]
780    pub fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
781        unsafe extern "C" fn notify_text_trampoline<F: Fn(&ProgressBar) + 'static>(
782            this: *mut ffi::GtkProgressBar,
783            _param_spec: glib::ffi::gpointer,
784            f: glib::ffi::gpointer,
785        ) {
786            let f: &F = &*(f as *const F);
787            f(&from_glib_borrow(this))
788        }
789        unsafe {
790            let f: Box_<F> = Box_::new(f);
791            connect_raw(
792                self.as_ptr() as *mut _,
793                c"notify::text".as_ptr() as *const _,
794                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
795                    notify_text_trampoline::<F> as *const (),
796                )),
797                Box_::into_raw(f),
798            )
799        }
800    }
801}
802
803impl Default for ProgressBar {
804    fn default() -> Self {
805        Self::new()
806    }
807}
808
809// rustdoc-stripper-ignore-next
810/// A [builder-pattern] type to construct [`ProgressBar`] objects.
811///
812/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
813#[must_use = "The builder must be built to be used"]
814pub struct ProgressBarBuilder {
815    builder: glib::object::ObjectBuilder<'static, ProgressBar>,
816}
817
818impl ProgressBarBuilder {
819    fn new() -> Self {
820        Self {
821            builder: glib::object::Object::builder(),
822        }
823    }
824
825    /// The preferred place to ellipsize the string.
826    ///
827    /// The text will be ellipsized if the progress bar does not have enough room
828    /// to display the entire string, specified as a [`pango::EllipsizeMode`][crate::pango::EllipsizeMode].
829    ///
830    /// Note that setting this property to a value other than
831    /// [`pango::EllipsizeMode::None`][crate::pango::EllipsizeMode::None] has the side-effect that the progress bar requests
832    /// only enough space to display the ellipsis ("..."). Another means to set a
833    /// progress bar's width is [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()].
834    pub fn ellipsize(self, ellipsize: pango::EllipsizeMode) -> Self {
835        Self {
836            builder: self.builder.property("ellipsize", ellipsize),
837        }
838    }
839
840    /// The fraction of total work that has been completed.
841    pub fn fraction(self, fraction: f64) -> Self {
842        Self {
843            builder: self.builder.property("fraction", fraction),
844        }
845    }
846
847    /// Invert the direction in which the progress bar grows.
848    pub fn inverted(self, inverted: bool) -> Self {
849        Self {
850            builder: self.builder.property("inverted", inverted),
851        }
852    }
853
854    /// The fraction of total progress to move the bounding block when pulsed.
855    pub fn pulse_step(self, pulse_step: f64) -> Self {
856        Self {
857            builder: self.builder.property("pulse-step", pulse_step),
858        }
859    }
860
861    /// Sets whether the progress bar will show a text in addition
862    /// to the bar itself.
863    ///
864    /// The shown text is either the value of the [`text`][struct@crate::ProgressBar#text]
865    /// property or, if that is [`None`], the [`fraction`][struct@crate::ProgressBar#fraction]
866    /// value, as a percentage.
867    ///
868    /// To make a progress bar that is styled and sized suitably for showing text
869    /// (even if the actual text is blank), set [`show-text`][struct@crate::ProgressBar#show-text]
870    /// to [`true`] and [`text`][struct@crate::ProgressBar#text] to the empty string (not [`None`]).
871    pub fn show_text(self, show_text: bool) -> Self {
872        Self {
873            builder: self.builder.property("show-text", show_text),
874        }
875    }
876
877    /// Text to be displayed in the progress bar.
878    pub fn text(self, text: impl Into<glib::GString>) -> Self {
879        Self {
880            builder: self.builder.property("text", text.into()),
881        }
882    }
883
884    /// Whether the widget or any of its descendents can accept
885    /// the input focus.
886    ///
887    /// This property is meant to be set by widget implementations,
888    /// typically in their instance init function.
889    pub fn can_focus(self, can_focus: bool) -> Self {
890        Self {
891            builder: self.builder.property("can-focus", can_focus),
892        }
893    }
894
895    /// Whether the widget can receive pointer events.
896    pub fn can_target(self, can_target: bool) -> Self {
897        Self {
898            builder: self.builder.property("can-target", can_target),
899        }
900    }
901
902    /// A list of css classes applied to this widget.
903    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
904        Self {
905            builder: self.builder.property("css-classes", css_classes.into()),
906        }
907    }
908
909    /// The name of this widget in the CSS tree.
910    ///
911    /// This property is meant to be set by widget implementations,
912    /// typically in their instance init function.
913    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
914        Self {
915            builder: self.builder.property("css-name", css_name.into()),
916        }
917    }
918
919    /// The cursor used by @widget.
920    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
921        Self {
922            builder: self.builder.property("cursor", cursor.clone()),
923        }
924    }
925
926    /// Whether the widget should grab focus when it is clicked with the mouse.
927    ///
928    /// This property is only relevant for widgets that can take focus.
929    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
930        Self {
931            builder: self.builder.property("focus-on-click", focus_on_click),
932        }
933    }
934
935    /// Whether this widget itself will accept the input focus.
936    pub fn focusable(self, focusable: bool) -> Self {
937        Self {
938            builder: self.builder.property("focusable", focusable),
939        }
940    }
941
942    /// How to distribute horizontal space if widget gets extra space.
943    pub fn halign(self, halign: Align) -> Self {
944        Self {
945            builder: self.builder.property("halign", halign),
946        }
947    }
948
949    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
950    /// signal on @widget.
951    ///
952    /// A true value indicates that @widget can have a tooltip, in this case
953    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
954    /// determine whether it will provide a tooltip or not.
955    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
956        Self {
957            builder: self.builder.property("has-tooltip", has_tooltip),
958        }
959    }
960
961    /// Overrides for height request of the widget.
962    ///
963    /// If this is -1, the natural request will be used.
964    pub fn height_request(self, height_request: i32) -> Self {
965        Self {
966            builder: self.builder.property("height-request", height_request),
967        }
968    }
969
970    /// Whether to expand horizontally.
971    pub fn hexpand(self, hexpand: bool) -> Self {
972        Self {
973            builder: self.builder.property("hexpand", hexpand),
974        }
975    }
976
977    /// Whether to use the `hexpand` property.
978    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
979        Self {
980            builder: self.builder.property("hexpand-set", hexpand_set),
981        }
982    }
983
984    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
985    /// the preferred size of the widget, and allocate its children.
986    ///
987    /// This property is meant to be set by widget implementations,
988    /// typically in their instance init function.
989    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
990        Self {
991            builder: self
992                .builder
993                .property("layout-manager", layout_manager.clone().upcast()),
994        }
995    }
996
997    /// Makes this widget act like a modal dialog, with respect to
998    /// event delivery.
999    ///
1000    /// Global event controllers will not handle events with targets
1001    /// inside the widget, unless they are set up to ignore propagation
1002    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1003    #[cfg(feature = "v4_18")]
1004    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1005    pub fn limit_events(self, limit_events: bool) -> Self {
1006        Self {
1007            builder: self.builder.property("limit-events", limit_events),
1008        }
1009    }
1010
1011    /// Margin on bottom side of widget.
1012    ///
1013    /// This property adds margin outside of the widget's normal size
1014    /// request, the margin will be added in addition to the size from
1015    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1016    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1017        Self {
1018            builder: self.builder.property("margin-bottom", margin_bottom),
1019        }
1020    }
1021
1022    /// Margin on end of widget, horizontally.
1023    ///
1024    /// This property supports left-to-right and right-to-left text
1025    /// directions.
1026    ///
1027    /// This property adds margin outside of the widget's normal size
1028    /// request, the margin will be added in addition to the size from
1029    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1030    pub fn margin_end(self, margin_end: i32) -> Self {
1031        Self {
1032            builder: self.builder.property("margin-end", margin_end),
1033        }
1034    }
1035
1036    /// Margin on start of widget, horizontally.
1037    ///
1038    /// This property supports left-to-right and right-to-left text
1039    /// directions.
1040    ///
1041    /// This property adds margin outside of the widget's normal size
1042    /// request, the margin will be added in addition to the size from
1043    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1044    pub fn margin_start(self, margin_start: i32) -> Self {
1045        Self {
1046            builder: self.builder.property("margin-start", margin_start),
1047        }
1048    }
1049
1050    /// Margin on top side of widget.
1051    ///
1052    /// This property adds margin outside of the widget's normal size
1053    /// request, the margin will be added in addition to the size from
1054    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1055    pub fn margin_top(self, margin_top: i32) -> Self {
1056        Self {
1057            builder: self.builder.property("margin-top", margin_top),
1058        }
1059    }
1060
1061    /// The name of the widget.
1062    pub fn name(self, name: impl Into<glib::GString>) -> Self {
1063        Self {
1064            builder: self.builder.property("name", name.into()),
1065        }
1066    }
1067
1068    /// The requested opacity of the widget.
1069    pub fn opacity(self, opacity: f64) -> Self {
1070        Self {
1071            builder: self.builder.property("opacity", opacity),
1072        }
1073    }
1074
1075    /// How content outside the widget's content area is treated.
1076    ///
1077    /// This property is meant to be set by widget implementations,
1078    /// typically in their instance init function.
1079    pub fn overflow(self, overflow: Overflow) -> Self {
1080        Self {
1081            builder: self.builder.property("overflow", overflow),
1082        }
1083    }
1084
1085    /// Whether the widget will receive the default action when it is focused.
1086    pub fn receives_default(self, receives_default: bool) -> Self {
1087        Self {
1088            builder: self.builder.property("receives-default", receives_default),
1089        }
1090    }
1091
1092    /// Whether the widget responds to input.
1093    pub fn sensitive(self, sensitive: bool) -> Self {
1094        Self {
1095            builder: self.builder.property("sensitive", sensitive),
1096        }
1097    }
1098
1099    /// Sets the text of tooltip to be the given string, which is marked up
1100    /// with Pango markup.
1101    ///
1102    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1103    ///
1104    /// This is a convenience property which will take care of getting the
1105    /// tooltip shown if the given string is not `NULL`:
1106    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1107    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1108    /// the default signal handler.
1109    ///
1110    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1111    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1112    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1113        Self {
1114            builder: self
1115                .builder
1116                .property("tooltip-markup", tooltip_markup.into()),
1117        }
1118    }
1119
1120    /// Sets the text of tooltip to be the given string.
1121    ///
1122    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1123    ///
1124    /// This is a convenience property which will take care of getting the
1125    /// tooltip shown if the given string is not `NULL`:
1126    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1127    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1128    /// the default signal handler.
1129    ///
1130    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1131    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1132    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1133        Self {
1134            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1135        }
1136    }
1137
1138    /// How to distribute vertical space if widget gets extra space.
1139    pub fn valign(self, valign: Align) -> Self {
1140        Self {
1141            builder: self.builder.property("valign", valign),
1142        }
1143    }
1144
1145    /// Whether to expand vertically.
1146    pub fn vexpand(self, vexpand: bool) -> Self {
1147        Self {
1148            builder: self.builder.property("vexpand", vexpand),
1149        }
1150    }
1151
1152    /// Whether to use the `vexpand` property.
1153    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1154        Self {
1155            builder: self.builder.property("vexpand-set", vexpand_set),
1156        }
1157    }
1158
1159    /// Whether the widget is visible.
1160    pub fn visible(self, visible: bool) -> Self {
1161        Self {
1162            builder: self.builder.property("visible", visible),
1163        }
1164    }
1165
1166    /// Overrides for width request of the widget.
1167    ///
1168    /// If this is -1, the natural request will be used.
1169    pub fn width_request(self, width_request: i32) -> Self {
1170        Self {
1171            builder: self.builder.property("width-request", width_request),
1172        }
1173    }
1174
1175    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1176    ///
1177    /// The accessible role cannot be changed once set.
1178    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1179        Self {
1180            builder: self.builder.property("accessible-role", accessible_role),
1181        }
1182    }
1183
1184    /// The orientation of the orientable.
1185    pub fn orientation(self, orientation: Orientation) -> Self {
1186        Self {
1187            builder: self.builder.property("orientation", orientation),
1188        }
1189    }
1190
1191    // rustdoc-stripper-ignore-next
1192    /// Build the [`ProgressBar`].
1193    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1194    pub fn build(self) -> ProgressBar {
1195        assert_initialized_main_thread!();
1196        self.builder.build()
1197    }
1198}