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