Skip to main content

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::{CellRenderer, CellRendererMode, IconSize, ffi};
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
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            unsafe {
257                let f: &F = &*(f as *const F);
258                f(&from_glib_borrow(this))
259            }
260        }
261        unsafe {
262            let f: Box_<F> = Box_::new(f);
263            connect_raw(
264                self.as_ptr() as *mut _,
265                c"notify::gicon".as_ptr() as *const _,
266                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
267                    notify_gicon_trampoline::<F> as *const (),
268                )),
269                Box_::into_raw(f),
270            )
271        }
272    }
273
274    #[doc(alias = "icon-name")]
275    pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
276        unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&CellRendererPixbuf) + 'static>(
277            this: *mut ffi::GtkCellRendererPixbuf,
278            _param_spec: glib::ffi::gpointer,
279            f: glib::ffi::gpointer,
280        ) {
281            unsafe {
282                let f: &F = &*(f as *const F);
283                f(&from_glib_borrow(this))
284            }
285        }
286        unsafe {
287            let f: Box_<F> = Box_::new(f);
288            connect_raw(
289                self.as_ptr() as *mut _,
290                c"notify::icon-name".as_ptr() as *const _,
291                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
292                    notify_icon_name_trampoline::<F> as *const (),
293                )),
294                Box_::into_raw(f),
295            )
296        }
297    }
298
299    #[doc(alias = "icon-size")]
300    pub fn connect_icon_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
301        unsafe extern "C" fn notify_icon_size_trampoline<F: Fn(&CellRendererPixbuf) + 'static>(
302            this: *mut ffi::GtkCellRendererPixbuf,
303            _param_spec: glib::ffi::gpointer,
304            f: glib::ffi::gpointer,
305        ) {
306            unsafe {
307                let f: &F = &*(f as *const F);
308                f(&from_glib_borrow(this))
309            }
310        }
311        unsafe {
312            let f: Box_<F> = Box_::new(f);
313            connect_raw(
314                self.as_ptr() as *mut _,
315                c"notify::icon-size".as_ptr() as *const _,
316                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
317                    notify_icon_size_trampoline::<F> as *const (),
318                )),
319                Box_::into_raw(f),
320            )
321        }
322    }
323
324    #[doc(alias = "pixbuf")]
325    pub fn connect_pixbuf_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
326        unsafe extern "C" fn notify_pixbuf_trampoline<F: Fn(&CellRendererPixbuf) + 'static>(
327            this: *mut ffi::GtkCellRendererPixbuf,
328            _param_spec: glib::ffi::gpointer,
329            f: glib::ffi::gpointer,
330        ) {
331            unsafe {
332                let f: &F = &*(f as *const F);
333                f(&from_glib_borrow(this))
334            }
335        }
336        unsafe {
337            let f: Box_<F> = Box_::new(f);
338            connect_raw(
339                self.as_ptr() as *mut _,
340                c"notify::pixbuf".as_ptr() as *const _,
341                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
342                    notify_pixbuf_trampoline::<F> as *const (),
343                )),
344                Box_::into_raw(f),
345            )
346        }
347    }
348
349    #[doc(alias = "pixbuf-expander-closed")]
350    pub fn connect_pixbuf_expander_closed_notify<F: Fn(&Self) + 'static>(
351        &self,
352        f: F,
353    ) -> SignalHandlerId {
354        unsafe extern "C" fn notify_pixbuf_expander_closed_trampoline<
355            F: Fn(&CellRendererPixbuf) + 'static,
356        >(
357            this: *mut ffi::GtkCellRendererPixbuf,
358            _param_spec: glib::ffi::gpointer,
359            f: glib::ffi::gpointer,
360        ) {
361            unsafe {
362                let f: &F = &*(f as *const F);
363                f(&from_glib_borrow(this))
364            }
365        }
366        unsafe {
367            let f: Box_<F> = Box_::new(f);
368            connect_raw(
369                self.as_ptr() as *mut _,
370                c"notify::pixbuf-expander-closed".as_ptr() as *const _,
371                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
372                    notify_pixbuf_expander_closed_trampoline::<F> as *const (),
373                )),
374                Box_::into_raw(f),
375            )
376        }
377    }
378
379    #[doc(alias = "pixbuf-expander-open")]
380    pub fn connect_pixbuf_expander_open_notify<F: Fn(&Self) + 'static>(
381        &self,
382        f: F,
383    ) -> SignalHandlerId {
384        unsafe extern "C" fn notify_pixbuf_expander_open_trampoline<
385            F: Fn(&CellRendererPixbuf) + 'static,
386        >(
387            this: *mut ffi::GtkCellRendererPixbuf,
388            _param_spec: glib::ffi::gpointer,
389            f: glib::ffi::gpointer,
390        ) {
391            unsafe {
392                let f: &F = &*(f as *const F);
393                f(&from_glib_borrow(this))
394            }
395        }
396        unsafe {
397            let f: Box_<F> = Box_::new(f);
398            connect_raw(
399                self.as_ptr() as *mut _,
400                c"notify::pixbuf-expander-open".as_ptr() as *const _,
401                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
402                    notify_pixbuf_expander_open_trampoline::<F> as *const (),
403                )),
404                Box_::into_raw(f),
405            )
406        }
407    }
408
409    #[doc(alias = "texture")]
410    pub fn connect_texture_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
411        unsafe extern "C" fn notify_texture_trampoline<F: Fn(&CellRendererPixbuf) + 'static>(
412            this: *mut ffi::GtkCellRendererPixbuf,
413            _param_spec: glib::ffi::gpointer,
414            f: glib::ffi::gpointer,
415        ) {
416            unsafe {
417                let f: &F = &*(f as *const F);
418                f(&from_glib_borrow(this))
419            }
420        }
421        unsafe {
422            let f: Box_<F> = Box_::new(f);
423            connect_raw(
424                self.as_ptr() as *mut _,
425                c"notify::texture".as_ptr() as *const _,
426                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
427                    notify_texture_trampoline::<F> as *const (),
428                )),
429                Box_::into_raw(f),
430            )
431        }
432    }
433}
434
435impl Default for CellRendererPixbuf {
436    fn default() -> Self {
437        Self::new()
438    }
439}
440
441// rustdoc-stripper-ignore-next
442/// A [builder-pattern] type to construct [`CellRendererPixbuf`] objects.
443///
444/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
445#[must_use = "The builder must be built to be used"]
446pub struct CellRendererPixbufBuilder {
447    builder: glib::object::ObjectBuilder<'static, CellRendererPixbuf>,
448}
449
450impl CellRendererPixbufBuilder {
451    fn new() -> Self {
452        Self {
453            builder: glib::object::Object::builder(),
454        }
455    }
456
457    /// The GIcon representing the icon to display.
458    /// If the icon theme is changed, the image will be updated
459    /// automatically.
460    pub fn gicon(self, gicon: &impl IsA<gio::Icon>) -> Self {
461        Self {
462            builder: self.builder.property("gicon", gicon.clone().upcast()),
463        }
464    }
465
466    /// The name of the themed icon to display.
467    /// This property only has an effect if not overridden by the "pixbuf" property.
468    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
469        Self {
470            builder: self.builder.property("icon-name", icon_name.into()),
471        }
472    }
473
474    /// The [`IconSize`][crate::IconSize] value that specifies the size of the rendered icon.
475    pub fn icon_size(self, icon_size: IconSize) -> Self {
476        Self {
477            builder: self.builder.property("icon-size", icon_size),
478        }
479    }
480
481    pub fn pixbuf(self, pixbuf: &gdk_pixbuf::Pixbuf) -> Self {
482        Self {
483            builder: self.builder.property("pixbuf", pixbuf.clone()),
484        }
485    }
486
487    pub fn pixbuf_expander_closed(self, pixbuf_expander_closed: &gdk_pixbuf::Pixbuf) -> Self {
488        Self {
489            builder: self
490                .builder
491                .property("pixbuf-expander-closed", pixbuf_expander_closed.clone()),
492        }
493    }
494
495    pub fn pixbuf_expander_open(self, pixbuf_expander_open: &gdk_pixbuf::Pixbuf) -> Self {
496        Self {
497            builder: self
498                .builder
499                .property("pixbuf-expander-open", pixbuf_expander_open.clone()),
500        }
501    }
502
503    pub fn texture(self, texture: &impl IsA<gdk::Texture>) -> Self {
504        Self {
505            builder: self.builder.property("texture", texture.clone().upcast()),
506        }
507    }
508
509    pub fn cell_background(self, cell_background: impl Into<glib::GString>) -> Self {
510        Self {
511            builder: self
512                .builder
513                .property("cell-background", cell_background.into()),
514        }
515    }
516
517    /// Cell background as a [`gdk::RGBA`][crate::gdk::RGBA]
518    pub fn cell_background_rgba(self, cell_background_rgba: &gdk::RGBA) -> Self {
519        Self {
520            builder: self
521                .builder
522                .property("cell-background-rgba", cell_background_rgba),
523        }
524    }
525
526    pub fn cell_background_set(self, cell_background_set: bool) -> Self {
527        Self {
528            builder: self
529                .builder
530                .property("cell-background-set", cell_background_set),
531        }
532    }
533
534    pub fn height(self, height: i32) -> Self {
535        Self {
536            builder: self.builder.property("height", height),
537        }
538    }
539
540    pub fn is_expanded(self, is_expanded: bool) -> Self {
541        Self {
542            builder: self.builder.property("is-expanded", is_expanded),
543        }
544    }
545
546    pub fn is_expander(self, is_expander: bool) -> Self {
547        Self {
548            builder: self.builder.property("is-expander", is_expander),
549        }
550    }
551
552    pub fn mode(self, mode: CellRendererMode) -> Self {
553        Self {
554            builder: self.builder.property("mode", mode),
555        }
556    }
557
558    pub fn sensitive(self, sensitive: bool) -> Self {
559        Self {
560            builder: self.builder.property("sensitive", sensitive),
561        }
562    }
563
564    pub fn visible(self, visible: bool) -> Self {
565        Self {
566            builder: self.builder.property("visible", visible),
567        }
568    }
569
570    pub fn width(self, width: i32) -> Self {
571        Self {
572            builder: self.builder.property("width", width),
573        }
574    }
575
576    pub fn xalign(self, xalign: f32) -> Self {
577        Self {
578            builder: self.builder.property("xalign", xalign),
579        }
580    }
581
582    pub fn xpad(self, xpad: u32) -> Self {
583        Self {
584            builder: self.builder.property("xpad", xpad),
585        }
586    }
587
588    pub fn yalign(self, yalign: f32) -> Self {
589        Self {
590            builder: self.builder.property("yalign", yalign),
591        }
592    }
593
594    pub fn ypad(self, ypad: u32) -> Self {
595        Self {
596            builder: self.builder.property("ypad", ypad),
597        }
598    }
599
600    // rustdoc-stripper-ignore-next
601    /// Build the [`CellRendererPixbuf`].
602    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
603    pub fn build(self) -> CellRendererPixbuf {
604        assert_initialized_main_thread!();
605        self.builder.build()
606    }
607}