Skip to main content

gtk/auto/
cell_renderer_progress.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::{CellRenderer, CellRendererMode, Orientable, Orientation};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14    /// [`CellRendererProgress`][crate::CellRendererProgress] renders a numeric value as a progress par in a cell.
15    /// Additionally, it can display a text on top of the progress bar.
16    ///
17    /// The [`CellRendererProgress`][crate::CellRendererProgress] cell renderer was added in GTK+ 2.6.
18    ///
19    /// ## Properties
20    ///
21    ///
22    /// #### `inverted`
23    ///  Readable | Writeable
24    ///
25    ///
26    /// #### `pulse`
27    ///  Setting this to a non-negative value causes the cell renderer to
28    /// enter "activity mode", where a block bounces back and forth to
29    /// indicate that some progress is made, without specifying exactly how
30    /// much.
31    ///
32    /// Each increment of the property causes the block to move by a little
33    /// bit.
34    ///
35    /// To indicate that the activity has not started yet, set the property
36    /// to zero. To indicate completion, set the property to `G_MAXINT`.
37    ///
38    /// Readable | Writeable
39    ///
40    ///
41    /// #### `text`
42    ///  The "text" property determines the label which will be drawn
43    /// over the progress bar. Setting this property to [`None`] causes the default
44    /// label to be displayed. Setting this property to an empty string causes
45    /// no label to be displayed.
46    ///
47    /// Readable | Writeable
48    ///
49    ///
50    /// #### `text-xalign`
51    ///  The "text-xalign" property controls the horizontal alignment of the
52    /// text in the progress bar. Valid values range from 0 (left) to 1
53    /// (right). Reserved for RTL layouts.
54    ///
55    /// Readable | Writeable
56    ///
57    ///
58    /// #### `text-yalign`
59    ///  The "text-yalign" property controls the vertical alignment of the
60    /// text in the progress bar. Valid values range from 0 (top) to 1
61    /// (bottom).
62    ///
63    /// Readable | Writeable
64    ///
65    ///
66    /// #### `value`
67    ///  The "value" property determines the percentage to which the
68    /// progress bar will be "filled in".
69    ///
70    /// Readable | Writeable
71    /// <details><summary><h4>CellRenderer</h4></summary>
72    ///
73    ///
74    /// #### `cell-background`
75    ///  Writeable
76    ///
77    ///
78    /// #### `cell-background-gdk`
79    ///  Cell background as a `GdkColor`
80    ///
81    /// Readable | Writeable
82    ///
83    ///
84    /// #### `cell-background-rgba`
85    ///  Cell background as a [`gdk::RGBA`][crate::gdk::RGBA]
86    ///
87    /// Readable | Writeable
88    ///
89    ///
90    /// #### `cell-background-set`
91    ///  Readable | Writeable
92    ///
93    ///
94    /// #### `editing`
95    ///  Readable
96    ///
97    ///
98    /// #### `height`
99    ///  Readable | Writeable
100    ///
101    ///
102    /// #### `is-expanded`
103    ///  Readable | Writeable
104    ///
105    ///
106    /// #### `is-expander`
107    ///  Readable | Writeable
108    ///
109    ///
110    /// #### `mode`
111    ///  Readable | Writeable
112    ///
113    ///
114    /// #### `sensitive`
115    ///  Readable | Writeable
116    ///
117    ///
118    /// #### `visible`
119    ///  Readable | Writeable
120    ///
121    ///
122    /// #### `width`
123    ///  Readable | Writeable
124    ///
125    ///
126    /// #### `xalign`
127    ///  Readable | Writeable
128    ///
129    ///
130    /// #### `xpad`
131    ///  Readable | Writeable
132    ///
133    ///
134    /// #### `yalign`
135    ///  Readable | Writeable
136    ///
137    ///
138    /// #### `ypad`
139    ///  Readable | Writeable
140    /// </details>
141    /// <details><summary><h4>Orientable</h4></summary>
142    ///
143    ///
144    /// #### `orientation`
145    ///  The orientation of the orientable.
146    ///
147    /// Readable | Writeable
148    /// </details>
149    ///
150    /// # Implements
151    ///
152    /// [`CellRendererProgressExt`][trait@crate::prelude::CellRendererProgressExt], [`CellRendererExt`][trait@crate::prelude::CellRendererExt], [`trait@glib::ObjectExt`], [`OrientableExt`][trait@crate::prelude::OrientableExt]
153    #[doc(alias = "GtkCellRendererProgress")]
154    pub struct CellRendererProgress(Object<ffi::GtkCellRendererProgress, ffi::GtkCellRendererProgressClass>) @extends CellRenderer, @implements Orientable;
155
156    match fn {
157        type_ => || ffi::gtk_cell_renderer_progress_get_type(),
158    }
159}
160
161impl CellRendererProgress {
162    pub const NONE: Option<&'static CellRendererProgress> = None;
163
164    /// Creates a new [`CellRendererProgress`][crate::CellRendererProgress].
165    ///
166    /// # Returns
167    ///
168    /// the new cell renderer
169    #[doc(alias = "gtk_cell_renderer_progress_new")]
170    pub fn new() -> CellRendererProgress {
171        assert_initialized_main_thread!();
172        unsafe { CellRenderer::from_glib_none(ffi::gtk_cell_renderer_progress_new()).unsafe_cast() }
173    }
174
175    // rustdoc-stripper-ignore-next
176    /// Creates a new builder-pattern struct instance to construct [`CellRendererProgress`] objects.
177    ///
178    /// This method returns an instance of [`CellRendererProgressBuilder`](crate::builders::CellRendererProgressBuilder) which can be used to create [`CellRendererProgress`] objects.
179    pub fn builder() -> CellRendererProgressBuilder {
180        CellRendererProgressBuilder::new()
181    }
182}
183
184impl Default for CellRendererProgress {
185    fn default() -> Self {
186        Self::new()
187    }
188}
189
190// rustdoc-stripper-ignore-next
191/// A [builder-pattern] type to construct [`CellRendererProgress`] objects.
192///
193/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
194#[must_use = "The builder must be built to be used"]
195pub struct CellRendererProgressBuilder {
196    builder: glib::object::ObjectBuilder<'static, CellRendererProgress>,
197}
198
199impl CellRendererProgressBuilder {
200    fn new() -> Self {
201        Self {
202            builder: glib::object::Object::builder(),
203        }
204    }
205
206    pub fn inverted(self, inverted: bool) -> Self {
207        Self {
208            builder: self.builder.property("inverted", inverted),
209        }
210    }
211
212    /// Setting this to a non-negative value causes the cell renderer to
213    /// enter "activity mode", where a block bounces back and forth to
214    /// indicate that some progress is made, without specifying exactly how
215    /// much.
216    ///
217    /// Each increment of the property causes the block to move by a little
218    /// bit.
219    ///
220    /// To indicate that the activity has not started yet, set the property
221    /// to zero. To indicate completion, set the property to `G_MAXINT`.
222    pub fn pulse(self, pulse: i32) -> Self {
223        Self {
224            builder: self.builder.property("pulse", pulse),
225        }
226    }
227
228    /// The "text" property determines the label which will be drawn
229    /// over the progress bar. Setting this property to [`None`] causes the default
230    /// label to be displayed. Setting this property to an empty string causes
231    /// no label to be displayed.
232    pub fn text(self, text: impl Into<glib::GString>) -> Self {
233        Self {
234            builder: self.builder.property("text", text.into()),
235        }
236    }
237
238    /// The "text-xalign" property controls the horizontal alignment of the
239    /// text in the progress bar. Valid values range from 0 (left) to 1
240    /// (right). Reserved for RTL layouts.
241    pub fn text_xalign(self, text_xalign: f32) -> Self {
242        Self {
243            builder: self.builder.property("text-xalign", text_xalign),
244        }
245    }
246
247    /// The "text-yalign" property controls the vertical alignment of the
248    /// text in the progress bar. Valid values range from 0 (top) to 1
249    /// (bottom).
250    pub fn text_yalign(self, text_yalign: f32) -> Self {
251        Self {
252            builder: self.builder.property("text-yalign", text_yalign),
253        }
254    }
255
256    /// The "value" property determines the percentage to which the
257    /// progress bar will be "filled in".
258    pub fn value(self, value: i32) -> Self {
259        Self {
260            builder: self.builder.property("value", value),
261        }
262    }
263
264    pub fn cell_background(self, cell_background: impl Into<glib::GString>) -> Self {
265        Self {
266            builder: self
267                .builder
268                .property("cell-background", cell_background.into()),
269        }
270    }
271
272    /// Cell background as a [`gdk::RGBA`][crate::gdk::RGBA]
273    pub fn cell_background_rgba(self, cell_background_rgba: &gdk::RGBA) -> Self {
274        Self {
275            builder: self
276                .builder
277                .property("cell-background-rgba", cell_background_rgba),
278        }
279    }
280
281    pub fn cell_background_set(self, cell_background_set: bool) -> Self {
282        Self {
283            builder: self
284                .builder
285                .property("cell-background-set", cell_background_set),
286        }
287    }
288
289    pub fn height(self, height: i32) -> Self {
290        Self {
291            builder: self.builder.property("height", height),
292        }
293    }
294
295    pub fn is_expanded(self, is_expanded: bool) -> Self {
296        Self {
297            builder: self.builder.property("is-expanded", is_expanded),
298        }
299    }
300
301    pub fn is_expander(self, is_expander: bool) -> Self {
302        Self {
303            builder: self.builder.property("is-expander", is_expander),
304        }
305    }
306
307    pub fn mode(self, mode: CellRendererMode) -> Self {
308        Self {
309            builder: self.builder.property("mode", mode),
310        }
311    }
312
313    pub fn sensitive(self, sensitive: bool) -> Self {
314        Self {
315            builder: self.builder.property("sensitive", sensitive),
316        }
317    }
318
319    pub fn visible(self, visible: bool) -> Self {
320        Self {
321            builder: self.builder.property("visible", visible),
322        }
323    }
324
325    pub fn width(self, width: i32) -> Self {
326        Self {
327            builder: self.builder.property("width", width),
328        }
329    }
330
331    pub fn xalign(self, xalign: f32) -> Self {
332        Self {
333            builder: self.builder.property("xalign", xalign),
334        }
335    }
336
337    pub fn xpad(self, xpad: u32) -> Self {
338        Self {
339            builder: self.builder.property("xpad", xpad),
340        }
341    }
342
343    pub fn yalign(self, yalign: f32) -> Self {
344        Self {
345            builder: self.builder.property("yalign", yalign),
346        }
347    }
348
349    pub fn ypad(self, ypad: u32) -> Self {
350        Self {
351            builder: self.builder.property("ypad", ypad),
352        }
353    }
354
355    /// The orientation of the orientable.
356    pub fn orientation(self, orientation: Orientation) -> Self {
357        Self {
358            builder: self.builder.property("orientation", orientation),
359        }
360    }
361
362    // rustdoc-stripper-ignore-next
363    /// Build the [`CellRendererProgress`].
364    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
365    pub fn build(self) -> CellRendererProgress {
366        self.builder.build()
367    }
368}
369
370mod sealed {
371    pub trait Sealed {}
372    impl<T: super::IsA<super::CellRendererProgress>> Sealed for T {}
373}
374
375/// Trait containing all [`struct@CellRendererProgress`] methods.
376///
377/// # Implementors
378///
379/// [`CellRendererProgress`][struct@crate::CellRendererProgress]
380pub trait CellRendererProgressExt: IsA<CellRendererProgress> + sealed::Sealed + 'static {
381    fn is_inverted(&self) -> bool {
382        ObjectExt::property(self.as_ref(), "inverted")
383    }
384
385    fn set_inverted(&self, inverted: bool) {
386        ObjectExt::set_property(self.as_ref(), "inverted", inverted)
387    }
388
389    /// Setting this to a non-negative value causes the cell renderer to
390    /// enter "activity mode", where a block bounces back and forth to
391    /// indicate that some progress is made, without specifying exactly how
392    /// much.
393    ///
394    /// Each increment of the property causes the block to move by a little
395    /// bit.
396    ///
397    /// To indicate that the activity has not started yet, set the property
398    /// to zero. To indicate completion, set the property to `G_MAXINT`.
399    fn pulse(&self) -> i32 {
400        ObjectExt::property(self.as_ref(), "pulse")
401    }
402
403    /// Setting this to a non-negative value causes the cell renderer to
404    /// enter "activity mode", where a block bounces back and forth to
405    /// indicate that some progress is made, without specifying exactly how
406    /// much.
407    ///
408    /// Each increment of the property causes the block to move by a little
409    /// bit.
410    ///
411    /// To indicate that the activity has not started yet, set the property
412    /// to zero. To indicate completion, set the property to `G_MAXINT`.
413    fn set_pulse(&self, pulse: i32) {
414        ObjectExt::set_property(self.as_ref(), "pulse", pulse)
415    }
416
417    /// The "text" property determines the label which will be drawn
418    /// over the progress bar. Setting this property to [`None`] causes the default
419    /// label to be displayed. Setting this property to an empty string causes
420    /// no label to be displayed.
421    fn text(&self) -> Option<glib::GString> {
422        ObjectExt::property(self.as_ref(), "text")
423    }
424
425    /// The "text" property determines the label which will be drawn
426    /// over the progress bar. Setting this property to [`None`] causes the default
427    /// label to be displayed. Setting this property to an empty string causes
428    /// no label to be displayed.
429    fn set_text(&self, text: Option<&str>) {
430        ObjectExt::set_property(self.as_ref(), "text", text)
431    }
432
433    /// The "text-xalign" property controls the horizontal alignment of the
434    /// text in the progress bar. Valid values range from 0 (left) to 1
435    /// (right). Reserved for RTL layouts.
436    #[doc(alias = "text-xalign")]
437    fn text_xalign(&self) -> f32 {
438        ObjectExt::property(self.as_ref(), "text-xalign")
439    }
440
441    /// The "text-xalign" property controls the horizontal alignment of the
442    /// text in the progress bar. Valid values range from 0 (left) to 1
443    /// (right). Reserved for RTL layouts.
444    #[doc(alias = "text-xalign")]
445    fn set_text_xalign(&self, text_xalign: f32) {
446        ObjectExt::set_property(self.as_ref(), "text-xalign", text_xalign)
447    }
448
449    /// The "text-yalign" property controls the vertical alignment of the
450    /// text in the progress bar. Valid values range from 0 (top) to 1
451    /// (bottom).
452    #[doc(alias = "text-yalign")]
453    fn text_yalign(&self) -> f32 {
454        ObjectExt::property(self.as_ref(), "text-yalign")
455    }
456
457    /// The "text-yalign" property controls the vertical alignment of the
458    /// text in the progress bar. Valid values range from 0 (top) to 1
459    /// (bottom).
460    #[doc(alias = "text-yalign")]
461    fn set_text_yalign(&self, text_yalign: f32) {
462        ObjectExt::set_property(self.as_ref(), "text-yalign", text_yalign)
463    }
464
465    /// The "value" property determines the percentage to which the
466    /// progress bar will be "filled in".
467    fn value(&self) -> i32 {
468        ObjectExt::property(self.as_ref(), "value")
469    }
470
471    /// The "value" property determines the percentage to which the
472    /// progress bar will be "filled in".
473    fn set_value(&self, value: i32) {
474        ObjectExt::set_property(self.as_ref(), "value", value)
475    }
476
477    #[doc(alias = "inverted")]
478    fn connect_inverted_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
479        unsafe extern "C" fn notify_inverted_trampoline<
480            P: IsA<CellRendererProgress>,
481            F: Fn(&P) + 'static,
482        >(
483            this: *mut ffi::GtkCellRendererProgress,
484            _param_spec: glib::ffi::gpointer,
485            f: glib::ffi::gpointer,
486        ) {
487            let f: &F = &*(f as *const F);
488            f(CellRendererProgress::from_glib_borrow(this).unsafe_cast_ref())
489        }
490        unsafe {
491            let f: Box_<F> = Box_::new(f);
492            connect_raw(
493                self.as_ptr() as *mut _,
494                b"notify::inverted\0".as_ptr() as *const _,
495                Some(transmute::<_, unsafe extern "C" fn()>(
496                    notify_inverted_trampoline::<Self, F> as *const (),
497                )),
498                Box_::into_raw(f),
499            )
500        }
501    }
502
503    #[doc(alias = "pulse")]
504    fn connect_pulse_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
505        unsafe extern "C" fn notify_pulse_trampoline<
506            P: IsA<CellRendererProgress>,
507            F: Fn(&P) + 'static,
508        >(
509            this: *mut ffi::GtkCellRendererProgress,
510            _param_spec: glib::ffi::gpointer,
511            f: glib::ffi::gpointer,
512        ) {
513            let f: &F = &*(f as *const F);
514            f(CellRendererProgress::from_glib_borrow(this).unsafe_cast_ref())
515        }
516        unsafe {
517            let f: Box_<F> = Box_::new(f);
518            connect_raw(
519                self.as_ptr() as *mut _,
520                b"notify::pulse\0".as_ptr() as *const _,
521                Some(transmute::<_, unsafe extern "C" fn()>(
522                    notify_pulse_trampoline::<Self, F> as *const (),
523                )),
524                Box_::into_raw(f),
525            )
526        }
527    }
528
529    #[doc(alias = "text")]
530    fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
531        unsafe extern "C" fn notify_text_trampoline<
532            P: IsA<CellRendererProgress>,
533            F: Fn(&P) + 'static,
534        >(
535            this: *mut ffi::GtkCellRendererProgress,
536            _param_spec: glib::ffi::gpointer,
537            f: glib::ffi::gpointer,
538        ) {
539            let f: &F = &*(f as *const F);
540            f(CellRendererProgress::from_glib_borrow(this).unsafe_cast_ref())
541        }
542        unsafe {
543            let f: Box_<F> = Box_::new(f);
544            connect_raw(
545                self.as_ptr() as *mut _,
546                b"notify::text\0".as_ptr() as *const _,
547                Some(transmute::<_, unsafe extern "C" fn()>(
548                    notify_text_trampoline::<Self, F> as *const (),
549                )),
550                Box_::into_raw(f),
551            )
552        }
553    }
554
555    #[doc(alias = "text-xalign")]
556    fn connect_text_xalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
557        unsafe extern "C" fn notify_text_xalign_trampoline<
558            P: IsA<CellRendererProgress>,
559            F: Fn(&P) + 'static,
560        >(
561            this: *mut ffi::GtkCellRendererProgress,
562            _param_spec: glib::ffi::gpointer,
563            f: glib::ffi::gpointer,
564        ) {
565            let f: &F = &*(f as *const F);
566            f(CellRendererProgress::from_glib_borrow(this).unsafe_cast_ref())
567        }
568        unsafe {
569            let f: Box_<F> = Box_::new(f);
570            connect_raw(
571                self.as_ptr() as *mut _,
572                b"notify::text-xalign\0".as_ptr() as *const _,
573                Some(transmute::<_, unsafe extern "C" fn()>(
574                    notify_text_xalign_trampoline::<Self, F> as *const (),
575                )),
576                Box_::into_raw(f),
577            )
578        }
579    }
580
581    #[doc(alias = "text-yalign")]
582    fn connect_text_yalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
583        unsafe extern "C" fn notify_text_yalign_trampoline<
584            P: IsA<CellRendererProgress>,
585            F: Fn(&P) + 'static,
586        >(
587            this: *mut ffi::GtkCellRendererProgress,
588            _param_spec: glib::ffi::gpointer,
589            f: glib::ffi::gpointer,
590        ) {
591            let f: &F = &*(f as *const F);
592            f(CellRendererProgress::from_glib_borrow(this).unsafe_cast_ref())
593        }
594        unsafe {
595            let f: Box_<F> = Box_::new(f);
596            connect_raw(
597                self.as_ptr() as *mut _,
598                b"notify::text-yalign\0".as_ptr() as *const _,
599                Some(transmute::<_, unsafe extern "C" fn()>(
600                    notify_text_yalign_trampoline::<Self, F> as *const (),
601                )),
602                Box_::into_raw(f),
603            )
604        }
605    }
606
607    #[doc(alias = "value")]
608    fn connect_value_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
609        unsafe extern "C" fn notify_value_trampoline<
610            P: IsA<CellRendererProgress>,
611            F: Fn(&P) + 'static,
612        >(
613            this: *mut ffi::GtkCellRendererProgress,
614            _param_spec: glib::ffi::gpointer,
615            f: glib::ffi::gpointer,
616        ) {
617            let f: &F = &*(f as *const F);
618            f(CellRendererProgress::from_glib_borrow(this).unsafe_cast_ref())
619        }
620        unsafe {
621            let f: Box_<F> = Box_::new(f);
622            connect_raw(
623                self.as_ptr() as *mut _,
624                b"notify::value\0".as_ptr() as *const _,
625                Some(transmute::<_, unsafe extern "C" fn()>(
626                    notify_value_trampoline::<Self, F> as *const (),
627                )),
628                Box_::into_raw(f),
629            )
630        }
631    }
632}
633
634impl<O: IsA<CellRendererProgress>> CellRendererProgressExt for O {}
635
636impl fmt::Display for CellRendererProgress {
637    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
638        f.write_str("CellRendererProgress")
639    }
640}