gtk4/auto/
icon_paintable.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;
7#[cfg(feature = "v4_6")]
8#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
9use crate::SymbolicPaintable;
10use glib::{
11    prelude::*,
12    signal::{connect_raw, SignalHandlerId},
13    translate::*,
14};
15use std::boxed::Box as Box_;
16
17#[cfg(feature = "v4_6")]
18#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
19glib::wrapper! {
20    /// Contains information found when looking up an icon in [`IconTheme`][crate::IconTheme]
21    /// or loading it from a file.
22    ///
23    /// [`IconPaintable`][crate::IconPaintable] implements [`gdk::Paintable`][crate::gdk::Paintable] and [`SymbolicPaintable`][crate::SymbolicPaintable].
24    ///
25    /// ## Properties
26    ///
27    ///
28    /// #### `file`
29    ///  The file representing the icon, if any.
30    ///
31    /// Readable | Writeable | Construct Only
32    ///
33    ///
34    /// #### `icon-name`
35    ///  The icon name that was chosen during lookup.
36    ///
37    /// Readable | Writeable | Construct Only
38    ///
39    ///
40    /// #### `is-symbolic`
41    ///  Whether the icon is symbolic or not.
42    ///
43    /// Readable | Writeable
44    ///
45    ///
46    /// #### `scale`
47    ///  Readable | Writeable
48    ///
49    ///
50    /// #### `size`
51    ///  Readable | Writeable
52    ///
53    /// # Implements
54    ///
55    /// [`trait@glib::ObjectExt`], [`trait@gdk::prelude::PaintableExt`], [`SymbolicPaintableExt`][trait@crate::prelude::SymbolicPaintableExt]
56    #[doc(alias = "GtkIconPaintable")]
57    pub struct IconPaintable(Object<ffi::GtkIconPaintable, ffi::GtkIconPaintableClass>) @implements gdk::Paintable, SymbolicPaintable;
58
59    match fn {
60        type_ => || ffi::gtk_icon_paintable_get_type(),
61    }
62}
63
64#[cfg(not(any(feature = "v4_6")))]
65glib::wrapper! {
66    #[doc(alias = "GtkIconPaintable")]
67    pub struct IconPaintable(Object<ffi::GtkIconPaintable, ffi::GtkIconPaintableClass>) @implements gdk::Paintable;
68
69    match fn {
70        type_ => || ffi::gtk_icon_paintable_get_type(),
71    }
72}
73
74impl IconPaintable {
75    /// Creates a [`IconPaintable`][crate::IconPaintable] for a file with a given size and scale.
76    ///
77    /// The icon can then be rendered by using it as a [`gdk::Paintable`][crate::gdk::Paintable].
78    /// ## `file`
79    /// a `GFile`
80    /// ## `size`
81    /// desired icon size, in application pixels
82    /// ## `scale`
83    /// the desired scale
84    ///
85    /// # Returns
86    ///
87    /// a [`IconPaintable`][crate::IconPaintable] containing
88    ///   for the icon. Unref with g_object_unref()
89    #[doc(alias = "gtk_icon_paintable_new_for_file")]
90    #[doc(alias = "new_for_file")]
91    pub fn for_file(file: &impl IsA<gio::File>, size: i32, scale: i32) -> IconPaintable {
92        assert_initialized_main_thread!();
93        unsafe {
94            from_glib_full(ffi::gtk_icon_paintable_new_for_file(
95                file.as_ref().to_glib_none().0,
96                size,
97                scale,
98            ))
99        }
100    }
101
102    /// Gets the `GFile` that was used to load the icon.
103    ///
104    /// Returns [`None`] if the icon was not loaded from a file.
105    ///
106    /// # Returns
107    ///
108    /// the `GFile` for the icon
109    #[doc(alias = "gtk_icon_paintable_get_file")]
110    #[doc(alias = "get_file")]
111    pub fn file(&self) -> Option<gio::File> {
112        unsafe { from_glib_full(ffi::gtk_icon_paintable_get_file(self.to_glib_none().0)) }
113    }
114
115    /// Get the icon name being used for this icon.
116    ///
117    /// When an icon looked up in the icon theme was not available, the
118    /// icon theme may use fallback icons - either those specified to
119    /// gtk_icon_theme_lookup_icon() or the always-available
120    /// "image-missing". The icon chosen is returned by this function.
121    ///
122    /// If the icon was created without an icon theme, this function
123    /// returns [`None`].
124    ///
125    /// # Deprecated since 4.20
126    ///
127    ///
128    /// # Returns
129    ///
130    /// the themed icon-name for the
131    ///   icon, or [`None`] if its not a themed icon.
132    #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
133    #[allow(deprecated)]
134    #[doc(alias = "gtk_icon_paintable_get_icon_name")]
135    #[doc(alias = "get_icon_name")]
136    #[doc(alias = "icon-name")]
137    pub fn icon_name(&self) -> Option<std::path::PathBuf> {
138        unsafe { from_glib_none(ffi::gtk_icon_paintable_get_icon_name(self.to_glib_none().0)) }
139    }
140
141    /// Checks if the icon is symbolic or not.
142    ///
143    /// This currently uses only the file name and not the file contents
144    /// for determining this. This behaviour may change in the future.
145    ///
146    /// # Deprecated since 4.20
147    ///
148    ///
149    /// # Returns
150    ///
151    /// true if the icon is symbolic, false otherwise
152    #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
153    #[allow(deprecated)]
154    #[doc(alias = "gtk_icon_paintable_is_symbolic")]
155    #[doc(alias = "is-symbolic")]
156    pub fn is_symbolic(&self) -> bool {
157        unsafe { from_glib(ffi::gtk_icon_paintable_is_symbolic(self.to_glib_none().0)) }
158    }
159
160    /// Whether the icon is symbolic or not.
161    ///
162    /// # Deprecated since 4.20
163    ///
164    #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
165    #[doc(alias = "is-symbolic")]
166    pub fn set_is_symbolic(&self, is_symbolic: bool) {
167        ObjectExt::set_property(self, "is-symbolic", is_symbolic)
168    }
169
170    pub fn scale(&self) -> i32 {
171        ObjectExt::property(self, "scale")
172    }
173
174    pub fn set_scale(&self, scale: i32) {
175        ObjectExt::set_property(self, "scale", scale)
176    }
177
178    pub fn size(&self) -> i32 {
179        ObjectExt::property(self, "size")
180    }
181
182    pub fn set_size(&self, size: i32) {
183        ObjectExt::set_property(self, "size", size)
184    }
185
186    #[cfg_attr(feature = "v4_20", deprecated = "Since 4.20")]
187    #[doc(alias = "is-symbolic")]
188    pub fn connect_is_symbolic_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
189        unsafe extern "C" fn notify_is_symbolic_trampoline<F: Fn(&IconPaintable) + 'static>(
190            this: *mut ffi::GtkIconPaintable,
191            _param_spec: glib::ffi::gpointer,
192            f: glib::ffi::gpointer,
193        ) {
194            let f: &F = &*(f as *const F);
195            f(&from_glib_borrow(this))
196        }
197        unsafe {
198            let f: Box_<F> = Box_::new(f);
199            connect_raw(
200                self.as_ptr() as *mut _,
201                c"notify::is-symbolic".as_ptr() as *const _,
202                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
203                    notify_is_symbolic_trampoline::<F> as *const (),
204                )),
205                Box_::into_raw(f),
206            )
207        }
208    }
209
210    #[doc(alias = "scale")]
211    pub fn connect_scale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
212        unsafe extern "C" fn notify_scale_trampoline<F: Fn(&IconPaintable) + 'static>(
213            this: *mut ffi::GtkIconPaintable,
214            _param_spec: glib::ffi::gpointer,
215            f: glib::ffi::gpointer,
216        ) {
217            let f: &F = &*(f as *const F);
218            f(&from_glib_borrow(this))
219        }
220        unsafe {
221            let f: Box_<F> = Box_::new(f);
222            connect_raw(
223                self.as_ptr() as *mut _,
224                c"notify::scale".as_ptr() as *const _,
225                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
226                    notify_scale_trampoline::<F> as *const (),
227                )),
228                Box_::into_raw(f),
229            )
230        }
231    }
232
233    #[doc(alias = "size")]
234    pub fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
235        unsafe extern "C" fn notify_size_trampoline<F: Fn(&IconPaintable) + 'static>(
236            this: *mut ffi::GtkIconPaintable,
237            _param_spec: glib::ffi::gpointer,
238            f: glib::ffi::gpointer,
239        ) {
240            let f: &F = &*(f as *const F);
241            f(&from_glib_borrow(this))
242        }
243        unsafe {
244            let f: Box_<F> = Box_::new(f);
245            connect_raw(
246                self.as_ptr() as *mut _,
247                c"notify::size".as_ptr() as *const _,
248                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
249                    notify_size_trampoline::<F> as *const (),
250                )),
251                Box_::into_raw(f),
252            )
253        }
254    }
255}