gtk4/auto/
cell_renderer_pixbuf.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#![allow(deprecated)]
5
6use crate::{ffi, CellRenderer, CellRendererMode, IconSize};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// List views use widgets to display their contents. You
16    ///   should use [`Image`][crate::Image] for icons, and [`Picture`][crate::Picture] for images
17    /// Renders a pixbuf in a cell
18    ///
19    /// A [`CellRendererPixbuf`][crate::CellRendererPixbuf] can be used to render an image in a cell. It allows
20    /// to render either a given [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] (set via the
21    /// `GtkCellRendererPixbuf:pixbuf` property) or a named icon (set via the
22    /// `GtkCellRendererPixbuf:icon-name` property).
23    ///
24    /// To support the tree view, [`CellRendererPixbuf`][crate::CellRendererPixbuf] also supports rendering two
25    /// alternative pixbufs, when the `GtkCellRenderer:is-expander` property is [`true`].
26    /// If the `GtkCellRenderer:is-expanded property` is [`true`] and the
27    /// `GtkCellRendererPixbuf:pixbuf-expander-open` property is set to a pixbuf, it
28    /// renders that pixbuf, if the `GtkCellRenderer:is-expanded` property is [`false`]
29    /// and the `GtkCellRendererPixbuf:pixbuf-expander-closed` property is set to a
30    /// pixbuf, it renders that one.
31    ///
32    /// ## Properties
33    ///
34    ///
35    /// #### `gicon`
36    ///  The GIcon representing the icon to display.
37    /// If the icon theme is changed, the image will be updated
38    /// automatically.
39    ///
40    /// Readable | Writeable
41    ///
42    ///
43    /// #### `icon-name`
44    ///  The name of the themed icon to display.
45    /// This property only has an effect if not overridden by the "pixbuf" property.
46    ///
47    /// Readable | Writeable
48    ///
49    ///
50    /// #### `icon-size`
51    ///  The [`IconSize`][crate::IconSize] value that specifies the size of the rendered icon.
52    ///
53    /// Readable | Writeable
54    ///
55    ///
56    /// #### `pixbuf`
57    ///  Writeable
58    ///
59    ///
60    /// #### `pixbuf-expander-closed`
61    ///  Readable | Writeable
62    ///
63    ///
64    /// #### `pixbuf-expander-open`
65    ///  Readable | Writeable
66    ///
67    ///
68    /// #### `texture`
69    ///  Readable | Writeable
70    /// <details><summary><h4>CellRenderer</h4></summary>
71    ///
72    ///
73    /// #### `cell-background`
74    ///  Writeable
75    ///
76    ///
77    /// #### `cell-background-rgba`
78    ///  Cell background as a [`gdk::RGBA`][crate::gdk::RGBA]
79    ///
80    /// Readable | Writeable
81    ///
82    ///
83    /// #### `cell-background-set`
84    ///  Readable | Writeable
85    ///
86    ///
87    /// #### `editing`
88    ///  Readable
89    ///
90    ///
91    /// #### `height`
92    ///  Readable | Writeable
93    ///
94    ///
95    /// #### `is-expanded`
96    ///  Readable | Writeable
97    ///
98    ///
99    /// #### `is-expander`
100    ///  Readable | Writeable
101    ///
102    ///
103    /// #### `mode`
104    ///  Readable | Writeable
105    ///
106    ///
107    /// #### `sensitive`
108    ///  Readable | Writeable
109    ///
110    ///
111    /// #### `visible`
112    ///  Readable | Writeable
113    ///
114    ///
115    /// #### `width`
116    ///  Readable | Writeable
117    ///
118    ///
119    /// #### `xalign`
120    ///  Readable | Writeable
121    ///
122    ///
123    /// #### `xpad`
124    ///  Readable | Writeable
125    ///
126    ///
127    /// #### `yalign`
128    ///  Readable | Writeable
129    ///
130    ///
131    /// #### `ypad`
132    ///  Readable | Writeable
133    /// </details>
134    ///
135    /// # Implements
136    ///
137    /// [`CellRendererExt`][trait@crate::prelude::CellRendererExt], [`trait@glib::ObjectExt`], [`CellRendererExtManual`][trait@crate::prelude::CellRendererExtManual]
138    #[doc(alias = "GtkCellRendererPixbuf")]
139    pub struct CellRendererPixbuf(Object<ffi::GtkCellRendererPixbuf>) @extends CellRenderer;
140
141    match fn {
142        type_ => || ffi::gtk_cell_renderer_pixbuf_get_type(),
143    }
144}
145
146impl CellRendererPixbuf {
147    /// Creates a new [`CellRendererPixbuf`][crate::CellRendererPixbuf]. Adjust rendering
148    /// parameters using object properties. Object properties can be set
149    /// globally (with g_object_set()). Also, with [`TreeViewColumn`][crate::TreeViewColumn], you
150    /// can bind a property to a value in a [`TreeModel`][crate::TreeModel]. For example, you
151    /// can bind the “pixbuf” property on the cell renderer to a pixbuf value
152    /// in the model, thus rendering a different image in each row of the
153    /// [`TreeView`][crate::TreeView].
154    ///
155    /// # Deprecated since 4.10
156    ///
157    ///
158    /// # Returns
159    ///
160    /// the new cell renderer
161    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
162    #[allow(deprecated)]
163    #[doc(alias = "gtk_cell_renderer_pixbuf_new")]
164    pub fn new() -> CellRendererPixbuf {
165        assert_initialized_main_thread!();
166        unsafe { CellRenderer::from_glib_none(ffi::gtk_cell_renderer_pixbuf_new()).unsafe_cast() }
167    }
168
169    // rustdoc-stripper-ignore-next
170    /// Creates a new builder-pattern struct instance to construct [`CellRendererPixbuf`] objects.
171    ///
172    /// This method returns an instance of [`CellRendererPixbufBuilder`](crate::builders::CellRendererPixbufBuilder) which can be used to create [`CellRendererPixbuf`] objects.
173    pub fn builder() -> CellRendererPixbufBuilder {
174        CellRendererPixbufBuilder::new()
175    }
176
177    /// The GIcon representing the icon to display.
178    /// If the icon theme is changed, the image will be updated
179    /// automatically.
180    pub fn gicon(&self) -> Option<gio::Icon> {
181        ObjectExt::property(self, "gicon")
182    }
183
184    /// The GIcon representing the icon to display.
185    /// If the icon theme is changed, the image will be updated
186    /// automatically.
187    pub fn set_gicon<P: IsA<gio::Icon>>(&self, gicon: Option<&P>) {
188        ObjectExt::set_property(self, "gicon", gicon)
189    }
190
191    /// The name of the themed icon to display.
192    /// This property only has an effect if not overridden by the "pixbuf" property.
193    #[doc(alias = "icon-name")]
194    pub fn icon_name(&self) -> Option<glib::GString> {
195        ObjectExt::property(self, "icon-name")
196    }
197
198    /// The name of the themed icon to display.
199    /// This property only has an effect if not overridden by the "pixbuf" property.
200    #[doc(alias = "icon-name")]
201    pub fn set_icon_name(&self, icon_name: Option<&str>) {
202        ObjectExt::set_property(self, "icon-name", icon_name)
203    }
204
205    /// The [`IconSize`][crate::IconSize] value that specifies the size of the rendered icon.
206    #[doc(alias = "icon-size")]
207    pub fn icon_size(&self) -> IconSize {
208        ObjectExt::property(self, "icon-size")
209    }
210
211    /// The [`IconSize`][crate::IconSize] value that specifies the size of the rendered icon.
212    #[doc(alias = "icon-size")]
213    pub fn set_icon_size(&self, icon_size: IconSize) {
214        ObjectExt::set_property(self, "icon-size", icon_size)
215    }
216
217    pub fn set_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
218        ObjectExt::set_property(self, "pixbuf", pixbuf)
219    }
220
221    #[doc(alias = "pixbuf-expander-closed")]
222    pub fn pixbuf_expander_closed(&self) -> Option<gdk_pixbuf::Pixbuf> {
223        ObjectExt::property(self, "pixbuf-expander-closed")
224    }
225
226    #[doc(alias = "pixbuf-expander-closed")]
227    pub fn set_pixbuf_expander_closed(&self, pixbuf_expander_closed: Option<&gdk_pixbuf::Pixbuf>) {
228        ObjectExt::set_property(self, "pixbuf-expander-closed", pixbuf_expander_closed)
229    }
230
231    #[doc(alias = "pixbuf-expander-open")]
232    pub fn pixbuf_expander_open(&self) -> Option<gdk_pixbuf::Pixbuf> {
233        ObjectExt::property(self, "pixbuf-expander-open")
234    }
235
236    #[doc(alias = "pixbuf-expander-open")]
237    pub fn set_pixbuf_expander_open(&self, pixbuf_expander_open: Option<&gdk_pixbuf::Pixbuf>) {
238        ObjectExt::set_property(self, "pixbuf-expander-open", pixbuf_expander_open)
239    }
240
241    pub fn texture(&self) -> Option<gdk::Texture> {
242        ObjectExt::property(self, "texture")
243    }
244
245    pub fn set_texture<P: IsA<gdk::Texture>>(&self, texture: Option<&P>) {
246        ObjectExt::set_property(self, "texture", texture)
247    }
248
249    #[doc(alias = "gicon")]
250    pub fn connect_gicon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
251        unsafe extern "C" fn notify_gicon_trampoline<F: Fn(&CellRendererPixbuf) + 'static>(
252            this: *mut ffi::GtkCellRendererPixbuf,
253            _param_spec: glib::ffi::gpointer,
254            f: glib::ffi::gpointer,
255        ) {
256            let f: &F = &*(f as *const F);
257            f(&from_glib_borrow(this))
258        }
259        unsafe {
260            let f: Box_<F> = Box_::new(f);
261            connect_raw(
262                self.as_ptr() as *mut _,
263                b"notify::gicon\0".as_ptr() as *const _,
264                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
265                    notify_gicon_trampoline::<F> as *const (),
266                )),
267                Box_::into_raw(f),
268            )
269        }
270    }
271
272    #[doc(alias = "icon-name")]
273    pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
274        unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&CellRendererPixbuf) + 'static>(
275            this: *mut ffi::GtkCellRendererPixbuf,
276            _param_spec: glib::ffi::gpointer,
277            f: glib::ffi::gpointer,
278        ) {
279            let f: &F = &*(f as *const F);
280            f(&from_glib_borrow(this))
281        }
282        unsafe {
283            let f: Box_<F> = Box_::new(f);
284            connect_raw(
285                self.as_ptr() as *mut _,
286                b"notify::icon-name\0".as_ptr() as *const _,
287                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
288                    notify_icon_name_trampoline::<F> as *const (),
289                )),
290                Box_::into_raw(f),
291            )
292        }
293    }
294
295    #[doc(alias = "icon-size")]
296    pub fn connect_icon_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
297        unsafe extern "C" fn notify_icon_size_trampoline<F: Fn(&CellRendererPixbuf) + 'static>(
298            this: *mut ffi::GtkCellRendererPixbuf,
299            _param_spec: glib::ffi::gpointer,
300            f: glib::ffi::gpointer,
301        ) {
302            let f: &F = &*(f as *const F);
303            f(&from_glib_borrow(this))
304        }
305        unsafe {
306            let f: Box_<F> = Box_::new(f);
307            connect_raw(
308                self.as_ptr() as *mut _,
309                b"notify::icon-size\0".as_ptr() as *const _,
310                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
311                    notify_icon_size_trampoline::<F> as *const (),
312                )),
313                Box_::into_raw(f),
314            )
315        }
316    }
317
318    #[doc(alias = "pixbuf")]
319    pub fn connect_pixbuf_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
320        unsafe extern "C" fn notify_pixbuf_trampoline<F: Fn(&CellRendererPixbuf) + 'static>(
321            this: *mut ffi::GtkCellRendererPixbuf,
322            _param_spec: glib::ffi::gpointer,
323            f: glib::ffi::gpointer,
324        ) {
325            let f: &F = &*(f as *const F);
326            f(&from_glib_borrow(this))
327        }
328        unsafe {
329            let f: Box_<F> = Box_::new(f);
330            connect_raw(
331                self.as_ptr() as *mut _,
332                b"notify::pixbuf\0".as_ptr() as *const _,
333                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
334                    notify_pixbuf_trampoline::<F> as *const (),
335                )),
336                Box_::into_raw(f),
337            )
338        }
339    }
340
341    #[doc(alias = "pixbuf-expander-closed")]
342    pub fn connect_pixbuf_expander_closed_notify<F: Fn(&Self) + 'static>(
343        &self,
344        f: F,
345    ) -> SignalHandlerId {
346        unsafe extern "C" fn notify_pixbuf_expander_closed_trampoline<
347            F: Fn(&CellRendererPixbuf) + 'static,
348        >(
349            this: *mut ffi::GtkCellRendererPixbuf,
350            _param_spec: glib::ffi::gpointer,
351            f: glib::ffi::gpointer,
352        ) {
353            let f: &F = &*(f as *const F);
354            f(&from_glib_borrow(this))
355        }
356        unsafe {
357            let f: Box_<F> = Box_::new(f);
358            connect_raw(
359                self.as_ptr() as *mut _,
360                b"notify::pixbuf-expander-closed\0".as_ptr() as *const _,
361                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
362                    notify_pixbuf_expander_closed_trampoline::<F> as *const (),
363                )),
364                Box_::into_raw(f),
365            )
366        }
367    }
368
369    #[doc(alias = "pixbuf-expander-open")]
370    pub fn connect_pixbuf_expander_open_notify<F: Fn(&Self) + 'static>(
371        &self,
372        f: F,
373    ) -> SignalHandlerId {
374        unsafe extern "C" fn notify_pixbuf_expander_open_trampoline<
375            F: Fn(&CellRendererPixbuf) + 'static,
376        >(
377            this: *mut ffi::GtkCellRendererPixbuf,
378            _param_spec: glib::ffi::gpointer,
379            f: glib::ffi::gpointer,
380        ) {
381            let f: &F = &*(f as *const F);
382            f(&from_glib_borrow(this))
383        }
384        unsafe {
385            let f: Box_<F> = Box_::new(f);
386            connect_raw(
387                self.as_ptr() as *mut _,
388                b"notify::pixbuf-expander-open\0".as_ptr() as *const _,
389                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
390                    notify_pixbuf_expander_open_trampoline::<F> as *const (),
391                )),
392                Box_::into_raw(f),
393            )
394        }
395    }
396
397    #[doc(alias = "texture")]
398    pub fn connect_texture_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
399        unsafe extern "C" fn notify_texture_trampoline<F: Fn(&CellRendererPixbuf) + 'static>(
400            this: *mut ffi::GtkCellRendererPixbuf,
401            _param_spec: glib::ffi::gpointer,
402            f: glib::ffi::gpointer,
403        ) {
404            let f: &F = &*(f as *const F);
405            f(&from_glib_borrow(this))
406        }
407        unsafe {
408            let f: Box_<F> = Box_::new(f);
409            connect_raw(
410                self.as_ptr() as *mut _,
411                b"notify::texture\0".as_ptr() as *const _,
412                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
413                    notify_texture_trampoline::<F> as *const (),
414                )),
415                Box_::into_raw(f),
416            )
417        }
418    }
419}
420
421impl Default for CellRendererPixbuf {
422    fn default() -> Self {
423        Self::new()
424    }
425}
426
427// rustdoc-stripper-ignore-next
428/// A [builder-pattern] type to construct [`CellRendererPixbuf`] objects.
429///
430/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
431#[must_use = "The builder must be built to be used"]
432pub struct CellRendererPixbufBuilder {
433    builder: glib::object::ObjectBuilder<'static, CellRendererPixbuf>,
434}
435
436impl CellRendererPixbufBuilder {
437    fn new() -> Self {
438        Self {
439            builder: glib::object::Object::builder(),
440        }
441    }
442
443    /// The GIcon representing the icon to display.
444    /// If the icon theme is changed, the image will be updated
445    /// automatically.
446    pub fn gicon(self, gicon: &impl IsA<gio::Icon>) -> Self {
447        Self {
448            builder: self.builder.property("gicon", gicon.clone().upcast()),
449        }
450    }
451
452    /// The name of the themed icon to display.
453    /// This property only has an effect if not overridden by the "pixbuf" property.
454    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
455        Self {
456            builder: self.builder.property("icon-name", icon_name.into()),
457        }
458    }
459
460    /// The [`IconSize`][crate::IconSize] value that specifies the size of the rendered icon.
461    pub fn icon_size(self, icon_size: IconSize) -> Self {
462        Self {
463            builder: self.builder.property("icon-size", icon_size),
464        }
465    }
466
467    pub fn pixbuf(self, pixbuf: &gdk_pixbuf::Pixbuf) -> Self {
468        Self {
469            builder: self.builder.property("pixbuf", pixbuf.clone()),
470        }
471    }
472
473    pub fn pixbuf_expander_closed(self, pixbuf_expander_closed: &gdk_pixbuf::Pixbuf) -> Self {
474        Self {
475            builder: self
476                .builder
477                .property("pixbuf-expander-closed", pixbuf_expander_closed.clone()),
478        }
479    }
480
481    pub fn pixbuf_expander_open(self, pixbuf_expander_open: &gdk_pixbuf::Pixbuf) -> Self {
482        Self {
483            builder: self
484                .builder
485                .property("pixbuf-expander-open", pixbuf_expander_open.clone()),
486        }
487    }
488
489    pub fn texture(self, texture: &impl IsA<gdk::Texture>) -> Self {
490        Self {
491            builder: self.builder.property("texture", texture.clone().upcast()),
492        }
493    }
494
495    pub fn cell_background(self, cell_background: impl Into<glib::GString>) -> Self {
496        Self {
497            builder: self
498                .builder
499                .property("cell-background", cell_background.into()),
500        }
501    }
502
503    /// Cell background as a [`gdk::RGBA`][crate::gdk::RGBA]
504    pub fn cell_background_rgba(self, cell_background_rgba: &gdk::RGBA) -> Self {
505        Self {
506            builder: self
507                .builder
508                .property("cell-background-rgba", cell_background_rgba),
509        }
510    }
511
512    pub fn cell_background_set(self, cell_background_set: bool) -> Self {
513        Self {
514            builder: self
515                .builder
516                .property("cell-background-set", cell_background_set),
517        }
518    }
519
520    pub fn height(self, height: i32) -> Self {
521        Self {
522            builder: self.builder.property("height", height),
523        }
524    }
525
526    pub fn is_expanded(self, is_expanded: bool) -> Self {
527        Self {
528            builder: self.builder.property("is-expanded", is_expanded),
529        }
530    }
531
532    pub fn is_expander(self, is_expander: bool) -> Self {
533        Self {
534            builder: self.builder.property("is-expander", is_expander),
535        }
536    }
537
538    pub fn mode(self, mode: CellRendererMode) -> Self {
539        Self {
540            builder: self.builder.property("mode", mode),
541        }
542    }
543
544    pub fn sensitive(self, sensitive: bool) -> Self {
545        Self {
546            builder: self.builder.property("sensitive", sensitive),
547        }
548    }
549
550    pub fn visible(self, visible: bool) -> Self {
551        Self {
552            builder: self.builder.property("visible", visible),
553        }
554    }
555
556    pub fn width(self, width: i32) -> Self {
557        Self {
558            builder: self.builder.property("width", width),
559        }
560    }
561
562    pub fn xalign(self, xalign: f32) -> Self {
563        Self {
564            builder: self.builder.property("xalign", xalign),
565        }
566    }
567
568    pub fn xpad(self, xpad: u32) -> Self {
569        Self {
570            builder: self.builder.property("xpad", xpad),
571        }
572    }
573
574    pub fn yalign(self, yalign: f32) -> Self {
575        Self {
576            builder: self.builder.property("yalign", yalign),
577        }
578    }
579
580    pub fn ypad(self, ypad: u32) -> Self {
581        Self {
582            builder: self.builder.property("ypad", ypad),
583        }
584    }
585
586    // rustdoc-stripper-ignore-next
587    /// Build the [`CellRendererPixbuf`].
588    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
589    pub fn build(self) -> CellRendererPixbuf {
590        assert_initialized_main_thread!();
591        self.builder.build()
592    }
593}