Skip to main content

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