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