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