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
5use crate::ffi;
6#[cfg(feature = "v4_6")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
8use crate::SymbolicPaintable;
9use glib::{prelude::*, translate::*};
10
11#[cfg(feature = "v4_6")]
12#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
13glib::wrapper! {
14    /// Contains information found when looking up an icon in [`IconTheme`][crate::IconTheme].
15    ///
16    /// [`IconPaintable`][crate::IconPaintable] implements [`gdk::Paintable`][crate::gdk::Paintable].
17    ///
18    /// ## Properties
19    ///
20    ///
21    /// #### `file`
22    ///  The file representing the icon, if any.
23    ///
24    /// Readable | Writeable | Construct Only
25    ///
26    ///
27    /// #### `icon-name`
28    ///  The icon name that was chosen during lookup.
29    ///
30    /// Readable | Writeable | Construct Only
31    ///
32    ///
33    /// #### `is-symbolic`
34    ///  Whether the icon is symbolic or not.
35    ///
36    /// Readable | Writeable | Construct Only
37    ///
38    /// # Implements
39    ///
40    /// [`trait@glib::ObjectExt`], [`trait@gdk::prelude::PaintableExt`], [`SymbolicPaintableExt`][trait@crate::prelude::SymbolicPaintableExt]
41    #[doc(alias = "GtkIconPaintable")]
42    pub struct IconPaintable(Object<ffi::GtkIconPaintable>) @implements gdk::Paintable, SymbolicPaintable;
43
44    match fn {
45        type_ => || ffi::gtk_icon_paintable_get_type(),
46    }
47}
48
49#[cfg(not(any(feature = "v4_6")))]
50glib::wrapper! {
51    #[doc(alias = "GtkIconPaintable")]
52    pub struct IconPaintable(Object<ffi::GtkIconPaintable>) @implements gdk::Paintable;
53
54    match fn {
55        type_ => || ffi::gtk_icon_paintable_get_type(),
56    }
57}
58
59impl IconPaintable {
60    /// Creates a [`IconPaintable`][crate::IconPaintable] for a file with a given size and scale.
61    ///
62    /// The icon can then be rendered by using it as a [`gdk::Paintable`][crate::gdk::Paintable].
63    /// ## `file`
64    /// a `GFile`
65    /// ## `size`
66    /// desired icon size, in application pixels
67    /// ## `scale`
68    /// the desired scale
69    ///
70    /// # Returns
71    ///
72    /// a [`IconPaintable`][crate::IconPaintable] containing
73    ///   for the icon. Unref with g_object_unref()
74    #[doc(alias = "gtk_icon_paintable_new_for_file")]
75    #[doc(alias = "new_for_file")]
76    pub fn for_file(file: &impl IsA<gio::File>, size: i32, scale: i32) -> IconPaintable {
77        assert_initialized_main_thread!();
78        unsafe {
79            from_glib_full(ffi::gtk_icon_paintable_new_for_file(
80                file.as_ref().to_glib_none().0,
81                size,
82                scale,
83            ))
84        }
85    }
86
87    /// Gets the `GFile` that was used to load the icon.
88    ///
89    /// Returns [`None`] if the icon was not loaded from a file.
90    ///
91    /// # Returns
92    ///
93    /// the `GFile` for the icon
94    #[doc(alias = "gtk_icon_paintable_get_file")]
95    #[doc(alias = "get_file")]
96    pub fn file(&self) -> Option<gio::File> {
97        unsafe { from_glib_full(ffi::gtk_icon_paintable_get_file(self.to_glib_none().0)) }
98    }
99
100    /// Get the icon name being used for this icon.
101    ///
102    /// When an icon looked up in the icon theme was not available, the
103    /// icon theme may use fallback icons - either those specified to
104    /// gtk_icon_theme_lookup_icon() or the always-available
105    /// "image-missing". The icon chosen is returned by this function.
106    ///
107    /// If the icon was created without an icon theme, this function
108    /// returns [`None`].
109    ///
110    /// # Returns
111    ///
112    /// the themed icon-name for the
113    ///   icon, or [`None`] if its not a themed icon.
114    #[doc(alias = "gtk_icon_paintable_get_icon_name")]
115    #[doc(alias = "get_icon_name")]
116    #[doc(alias = "icon-name")]
117    pub fn icon_name(&self) -> Option<std::path::PathBuf> {
118        unsafe { from_glib_none(ffi::gtk_icon_paintable_get_icon_name(self.to_glib_none().0)) }
119    }
120
121    /// Checks if the icon is symbolic or not.
122    ///
123    /// This currently uses only the file name and not the file contents
124    /// for determining this. This behaviour may change in the future.
125    ///
126    /// Note that to render a symbolic [`IconPaintable`][crate::IconPaintable] properly (with
127    /// recoloring), you have to set its icon name on a [`Image`][crate::Image].
128    ///
129    /// # Returns
130    ///
131    /// [`true`] if the icon is symbolic, [`false`] otherwise
132    #[doc(alias = "gtk_icon_paintable_is_symbolic")]
133    #[doc(alias = "is-symbolic")]
134    pub fn is_symbolic(&self) -> bool {
135        unsafe { from_glib(ffi::gtk_icon_paintable_is_symbolic(self.to_glib_none().0)) }
136    }
137}