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