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, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
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 | Writable
72    ///
73    ///
74    /// #### `fraction`
75    ///  Readable | Writable
76    ///
77    ///
78    /// #### `inverted`
79    ///  Readable | Writable
80    ///
81    ///
82    /// #### `pulse-step`
83    ///  Readable | Writable
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 | Writable
98    ///
99    ///
100    /// #### `text`
101    ///  Readable | Writable
102    /// <details><summary><h4>Widget</h4></summary>
103    ///
104    ///
105    /// #### `app-paintable`
106    ///  Readable | Writable
107    ///
108    ///
109    /// #### `can-default`
110    ///  Readable | Writable
111    ///
112    ///
113    /// #### `can-focus`
114    ///  Readable | Writable
115    ///
116    ///
117    /// #### `composite-child`
118    ///  Readable
119    ///
120    ///
121    /// #### `double-buffered`
122    ///  Whether the widget is double buffered.
123    ///
124    /// Readable | Writable
125    ///
126    ///
127    /// #### `events`
128    ///  Readable | Writable
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 | Writable
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 | Writable
146    ///
147    ///
148    /// #### `halign`
149    ///  How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
150    ///
151    /// Readable | Writable
152    ///
153    ///
154    /// #### `has-default`
155    ///  Readable | Writable
156    ///
157    ///
158    /// #### `has-focus`
159    ///  Readable | Writable
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 | Writable
174    ///
175    ///
176    /// #### `height-request`
177    ///  Readable | Writable
178    ///
179    ///
180    /// #### `hexpand`
181    ///  Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
182    ///
183    /// Readable | Writable
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 | Writable
190    ///
191    ///
192    /// #### `is-focus`
193    ///  Readable | Writable
194    ///
195    ///
196    /// #### `margin`
197    ///  Sets all four sides' margin at once. If read, returns max
198    /// margin on any side.
199    ///
200    /// Readable | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
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 | Writable
263    ///
264    ///
265    /// #### `name`
266    ///  Readable | Writable
267    ///
268    ///
269    /// #### `no-show-all`
270    ///  Readable | Writable
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 | Writable
280    ///
281    ///
282    /// #### `parent`
283    ///  Readable | Writable
284    ///
285    ///
286    /// #### `receives-default`
287    ///  Readable | Writable
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 | Writable
299    ///
300    ///
301    /// #### `style`
302    ///  The style of the widget, which contains information about how it will look (colors, etc).
303    ///
304    /// Readable | Writable
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 | Writable
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 | Writable
337    ///
338    ///
339    /// #### `valign`
340    ///  How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
341    ///
342    /// Readable | Writable
343    ///
344    ///
345    /// #### `vexpand`
346    ///  Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
347    ///
348    /// Readable | Writable
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 | Writable
355    ///
356    ///
357    /// #### `visible`
358    ///  Readable | Writable
359    ///
360    ///
361    /// #### `width-request`
362    ///  Readable | Writable
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 | Writable
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        assert_initialized_main_thread!();
766        self.builder.build()
767    }
768}
769
770/// Trait containing all [`struct@ProgressBar`] methods.
771///
772/// # Implementors
773///
774/// [`ProgressBar`][struct@crate::ProgressBar]
775pub trait ProgressBarExt: IsA<ProgressBar> + 'static {
776    /// Returns the ellipsizing position of the progress bar.
777    /// See [`set_ellipsize()`][Self::set_ellipsize()].
778    ///
779    /// # Returns
780    ///
781    /// [`pango::EllipsizeMode`][crate::pango::EllipsizeMode]
782    #[doc(alias = "gtk_progress_bar_get_ellipsize")]
783    #[doc(alias = "get_ellipsize")]
784    fn ellipsize(&self) -> pango::EllipsizeMode {
785        unsafe {
786            from_glib(ffi::gtk_progress_bar_get_ellipsize(
787                self.as_ref().to_glib_none().0,
788            ))
789        }
790    }
791
792    /// Returns the current fraction of the task that’s been completed.
793    ///
794    /// # Returns
795    ///
796    /// a fraction from 0.0 to 1.0
797    #[doc(alias = "gtk_progress_bar_get_fraction")]
798    #[doc(alias = "get_fraction")]
799    fn fraction(&self) -> f64 {
800        unsafe { ffi::gtk_progress_bar_get_fraction(self.as_ref().to_glib_none().0) }
801    }
802
803    /// Gets the value set by [`set_inverted()`][Self::set_inverted()].
804    ///
805    /// # Returns
806    ///
807    /// [`true`] if the progress bar is inverted
808    #[doc(alias = "gtk_progress_bar_get_inverted")]
809    #[doc(alias = "get_inverted")]
810    #[doc(alias = "inverted")]
811    fn is_inverted(&self) -> bool {
812        unsafe {
813            from_glib(ffi::gtk_progress_bar_get_inverted(
814                self.as_ref().to_glib_none().0,
815            ))
816        }
817    }
818
819    /// Retrieves the pulse step set with [`set_pulse_step()`][Self::set_pulse_step()].
820    ///
821    /// # Returns
822    ///
823    /// a fraction from 0.0 to 1.0
824    #[doc(alias = "gtk_progress_bar_get_pulse_step")]
825    #[doc(alias = "get_pulse_step")]
826    #[doc(alias = "pulse-step")]
827    fn pulse_step(&self) -> f64 {
828        unsafe { ffi::gtk_progress_bar_get_pulse_step(self.as_ref().to_glib_none().0) }
829    }
830
831    /// Gets the value of the [`show-text`][struct@crate::ProgressBar#show-text] property.
832    /// See [`set_show_text()`][Self::set_show_text()].
833    ///
834    /// # Returns
835    ///
836    /// [`true`] if text is shown in the progress bar
837    #[doc(alias = "gtk_progress_bar_get_show_text")]
838    #[doc(alias = "get_show_text")]
839    #[doc(alias = "show-text")]
840    fn shows_text(&self) -> bool {
841        unsafe {
842            from_glib(ffi::gtk_progress_bar_get_show_text(
843                self.as_ref().to_glib_none().0,
844            ))
845        }
846    }
847
848    /// Retrieves the text that is displayed with the progress bar,
849    /// if any, otherwise [`None`]. The return value is a reference
850    /// to the text, not a copy of it, so will become invalid
851    /// if you change the text in the progress bar.
852    ///
853    /// # Returns
854    ///
855    /// text, or [`None`]; this string is owned by the widget
856    /// and should not be modified or freed.
857    #[doc(alias = "gtk_progress_bar_get_text")]
858    #[doc(alias = "get_text")]
859    fn text(&self) -> Option<glib::GString> {
860        unsafe {
861            from_glib_none(ffi::gtk_progress_bar_get_text(
862                self.as_ref().to_glib_none().0,
863            ))
864        }
865    }
866
867    /// Indicates that some progress has been made, but you don’t know how much.
868    /// Causes the progress bar to enter “activity mode,” where a block
869    /// bounces back and forth. Each call to [`pulse()`][Self::pulse()]
870    /// causes the block to move by a little bit (the amount of movement
871    /// per pulse is determined by [`set_pulse_step()`][Self::set_pulse_step()]).
872    #[doc(alias = "gtk_progress_bar_pulse")]
873    fn pulse(&self) {
874        unsafe {
875            ffi::gtk_progress_bar_pulse(self.as_ref().to_glib_none().0);
876        }
877    }
878
879    /// Sets the mode used to ellipsize (add an ellipsis: "...") the
880    /// text if there is not enough space to render the entire string.
881    /// ## `mode`
882    /// a [`pango::EllipsizeMode`][crate::pango::EllipsizeMode]
883    #[doc(alias = "gtk_progress_bar_set_ellipsize")]
884    #[doc(alias = "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    #[doc(alias = "fraction")]
898    fn set_fraction(&self, fraction: f64) {
899        unsafe {
900            ffi::gtk_progress_bar_set_fraction(self.as_ref().to_glib_none().0, fraction);
901        }
902    }
903
904    /// Progress bars normally grow from top to bottom or left to right.
905    /// Inverted progress bars grow in the opposite direction.
906    /// ## `inverted`
907    /// [`true`] to invert the progress bar
908    #[doc(alias = "gtk_progress_bar_set_inverted")]
909    #[doc(alias = "inverted")]
910    fn set_inverted(&self, inverted: bool) {
911        unsafe {
912            ffi::gtk_progress_bar_set_inverted(
913                self.as_ref().to_glib_none().0,
914                inverted.into_glib(),
915            );
916        }
917    }
918
919    /// Sets the fraction of total progress bar length to move the
920    /// bouncing block for each call to [`pulse()`][Self::pulse()].
921    /// ## `fraction`
922    /// fraction between 0.0 and 1.0
923    #[doc(alias = "gtk_progress_bar_set_pulse_step")]
924    #[doc(alias = "pulse-step")]
925    fn set_pulse_step(&self, fraction: f64) {
926        unsafe {
927            ffi::gtk_progress_bar_set_pulse_step(self.as_ref().to_glib_none().0, fraction);
928        }
929    }
930
931    /// Sets whether the progress bar will show text next to the bar.
932    /// The shown text is either the value of the [`text`][struct@crate::ProgressBar#text]
933    /// property or, if that is [`None`], the [`fraction`][struct@crate::ProgressBar#fraction] value,
934    /// as a percentage.
935    ///
936    /// To make a progress bar that is styled and sized suitably for containing
937    /// text (even if the actual text is blank), set [`show-text`][struct@crate::ProgressBar#show-text] to
938    /// [`true`] and [`text`][struct@crate::ProgressBar#text] to the empty string (not [`None`]).
939    /// ## `show_text`
940    /// whether to show text
941    #[doc(alias = "gtk_progress_bar_set_show_text")]
942    #[doc(alias = "show-text")]
943    fn set_show_text(&self, show_text: bool) {
944        unsafe {
945            ffi::gtk_progress_bar_set_show_text(
946                self.as_ref().to_glib_none().0,
947                show_text.into_glib(),
948            );
949        }
950    }
951
952    /// Causes the given `text` to appear next to the progress bar.
953    ///
954    /// If `text` is [`None`] and [`show-text`][struct@crate::ProgressBar#show-text] is [`true`], the current
955    /// value of [`fraction`][struct@crate::ProgressBar#fraction] will be displayed as a percentage.
956    ///
957    /// If `text` is non-[`None`] and [`show-text`][struct@crate::ProgressBar#show-text] is [`true`], the text
958    /// will be displayed. In this case, it will not display the progress
959    /// percentage. If `text` is the empty string, the progress bar will still
960    /// be styled and sized suitably for containing text, as long as
961    /// [`show-text`][struct@crate::ProgressBar#show-text] is [`true`].
962    /// ## `text`
963    /// a UTF-8 string, or [`None`]
964    #[doc(alias = "gtk_progress_bar_set_text")]
965    #[doc(alias = "text")]
966    fn set_text(&self, text: Option<&str>) {
967        unsafe {
968            ffi::gtk_progress_bar_set_text(self.as_ref().to_glib_none().0, text.to_glib_none().0);
969        }
970    }
971
972    #[doc(alias = "ellipsize")]
973    fn connect_ellipsize_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
974        unsafe extern "C" fn notify_ellipsize_trampoline<
975            P: IsA<ProgressBar>,
976            F: Fn(&P) + 'static,
977        >(
978            this: *mut ffi::GtkProgressBar,
979            _param_spec: glib::ffi::gpointer,
980            f: glib::ffi::gpointer,
981        ) {
982            unsafe {
983                let f: &F = &*(f as *const F);
984                f(ProgressBar::from_glib_borrow(this).unsafe_cast_ref())
985            }
986        }
987        unsafe {
988            let f: Box_<F> = Box_::new(f);
989            connect_raw(
990                self.as_ptr() as *mut _,
991                c"notify::ellipsize".as_ptr(),
992                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
993                    notify_ellipsize_trampoline::<Self, F> as *const (),
994                )),
995                Box_::into_raw(f),
996            )
997        }
998    }
999
1000    #[doc(alias = "fraction")]
1001    fn connect_fraction_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1002        unsafe extern "C" fn notify_fraction_trampoline<
1003            P: IsA<ProgressBar>,
1004            F: Fn(&P) + 'static,
1005        >(
1006            this: *mut ffi::GtkProgressBar,
1007            _param_spec: glib::ffi::gpointer,
1008            f: glib::ffi::gpointer,
1009        ) {
1010            unsafe {
1011                let f: &F = &*(f as *const F);
1012                f(ProgressBar::from_glib_borrow(this).unsafe_cast_ref())
1013            }
1014        }
1015        unsafe {
1016            let f: Box_<F> = Box_::new(f);
1017            connect_raw(
1018                self.as_ptr() as *mut _,
1019                c"notify::fraction".as_ptr(),
1020                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1021                    notify_fraction_trampoline::<Self, F> as *const (),
1022                )),
1023                Box_::into_raw(f),
1024            )
1025        }
1026    }
1027
1028    #[doc(alias = "inverted")]
1029    fn connect_inverted_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1030        unsafe extern "C" fn notify_inverted_trampoline<
1031            P: IsA<ProgressBar>,
1032            F: Fn(&P) + 'static,
1033        >(
1034            this: *mut ffi::GtkProgressBar,
1035            _param_spec: glib::ffi::gpointer,
1036            f: glib::ffi::gpointer,
1037        ) {
1038            unsafe {
1039                let f: &F = &*(f as *const F);
1040                f(ProgressBar::from_glib_borrow(this).unsafe_cast_ref())
1041            }
1042        }
1043        unsafe {
1044            let f: Box_<F> = Box_::new(f);
1045            connect_raw(
1046                self.as_ptr() as *mut _,
1047                c"notify::inverted".as_ptr(),
1048                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1049                    notify_inverted_trampoline::<Self, F> as *const (),
1050                )),
1051                Box_::into_raw(f),
1052            )
1053        }
1054    }
1055
1056    #[doc(alias = "pulse-step")]
1057    fn connect_pulse_step_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1058        unsafe extern "C" fn notify_pulse_step_trampoline<
1059            P: IsA<ProgressBar>,
1060            F: Fn(&P) + 'static,
1061        >(
1062            this: *mut ffi::GtkProgressBar,
1063            _param_spec: glib::ffi::gpointer,
1064            f: glib::ffi::gpointer,
1065        ) {
1066            unsafe {
1067                let f: &F = &*(f as *const F);
1068                f(ProgressBar::from_glib_borrow(this).unsafe_cast_ref())
1069            }
1070        }
1071        unsafe {
1072            let f: Box_<F> = Box_::new(f);
1073            connect_raw(
1074                self.as_ptr() as *mut _,
1075                c"notify::pulse-step".as_ptr(),
1076                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1077                    notify_pulse_step_trampoline::<Self, F> as *const (),
1078                )),
1079                Box_::into_raw(f),
1080            )
1081        }
1082    }
1083
1084    #[doc(alias = "show-text")]
1085    fn connect_show_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1086        unsafe extern "C" fn notify_show_text_trampoline<
1087            P: IsA<ProgressBar>,
1088            F: Fn(&P) + 'static,
1089        >(
1090            this: *mut ffi::GtkProgressBar,
1091            _param_spec: glib::ffi::gpointer,
1092            f: glib::ffi::gpointer,
1093        ) {
1094            unsafe {
1095                let f: &F = &*(f as *const F);
1096                f(ProgressBar::from_glib_borrow(this).unsafe_cast_ref())
1097            }
1098        }
1099        unsafe {
1100            let f: Box_<F> = Box_::new(f);
1101            connect_raw(
1102                self.as_ptr() as *mut _,
1103                c"notify::show-text".as_ptr(),
1104                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1105                    notify_show_text_trampoline::<Self, F> as *const (),
1106                )),
1107                Box_::into_raw(f),
1108            )
1109        }
1110    }
1111
1112    #[doc(alias = "text")]
1113    fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1114        unsafe extern "C" fn notify_text_trampoline<P: IsA<ProgressBar>, F: Fn(&P) + 'static>(
1115            this: *mut ffi::GtkProgressBar,
1116            _param_spec: glib::ffi::gpointer,
1117            f: glib::ffi::gpointer,
1118        ) {
1119            unsafe {
1120                let f: &F = &*(f as *const F);
1121                f(ProgressBar::from_glib_borrow(this).unsafe_cast_ref())
1122            }
1123        }
1124        unsafe {
1125            let f: Box_<F> = Box_::new(f);
1126            connect_raw(
1127                self.as_ptr() as *mut _,
1128                c"notify::text".as_ptr(),
1129                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1130                    notify_text_trampoline::<Self, F> as *const (),
1131                )),
1132                Box_::into_raw(f),
1133            )
1134        }
1135    }
1136}
1137
1138impl<O: IsA<ProgressBar>> ProgressBarExt for O {}