1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

#[cfg(any(feature = "v4_6", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_6")))]
use crate::SymbolicPaintable;
use glib::{prelude::*, translate::*};
use std::fmt;

#[cfg(any(feature = "v4_6", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v4_6")))]
glib::wrapper! {
    /// Contains information found when looking up an icon in [`IconTheme`][crate::IconTheme].
    ///
    /// [`IconPaintable`][crate::IconPaintable] implements [`gdk::Paintable`][crate::gdk::Paintable].
    ///
    /// ## Properties
    ///
    ///
    /// #### `file`
    ///  The file representing the icon, if any.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `icon-name`
    ///  The icon name that was chosen during lookup.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `is-symbolic`
    ///  Whether the icon is symbolic or not.
    ///
    /// Readable | Writeable | Construct Only
    ///
    /// # Implements
    ///
    /// [`trait@glib::ObjectExt`], [`trait@gdk::prelude::PaintableExt`], [`SymbolicPaintableExt`][trait@crate::prelude::SymbolicPaintableExt]
    #[doc(alias = "GtkIconPaintable")]
    pub struct IconPaintable(Object<ffi::GtkIconPaintable>) @implements gdk::Paintable, SymbolicPaintable;

    match fn {
        type_ => || ffi::gtk_icon_paintable_get_type(),
    }
}

#[cfg(not(any(feature = "v4_6", feature = "dox")))]
glib::wrapper! {
    #[doc(alias = "GtkIconPaintable")]
    pub struct IconPaintable(Object<ffi::GtkIconPaintable>) @implements gdk::Paintable;

    match fn {
        type_ => || ffi::gtk_icon_paintable_get_type(),
    }
}

impl IconPaintable {
    /// Creates a [`IconPaintable`][crate::IconPaintable] for a file with a given size and scale.
    ///
    /// The icon can then be rendered by using it as a [`gdk::Paintable`][crate::gdk::Paintable].
    /// ## `file`
    /// a `GFile`
    /// ## `size`
    /// desired icon size
    /// ## `scale`
    /// the desired scale
    ///
    /// # Returns
    ///
    /// a [`IconPaintable`][crate::IconPaintable] containing
    ///   for the icon. Unref with g_object_unref()
    #[doc(alias = "gtk_icon_paintable_new_for_file")]
    #[doc(alias = "new_for_file")]
    pub fn for_file(file: &impl IsA<gio::File>, size: i32, scale: i32) -> IconPaintable {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_full(ffi::gtk_icon_paintable_new_for_file(
                file.as_ref().to_glib_none().0,
                size,
                scale,
            ))
        }
    }

    /// Gets the `GFile` that was used to load the icon.
    ///
    /// Returns [`None`] if the icon was not loaded from a file.
    ///
    /// # Returns
    ///
    /// the `GFile` for the icon
    #[doc(alias = "gtk_icon_paintable_get_file")]
    #[doc(alias = "get_file")]
    pub fn file(&self) -> Option<gio::File> {
        unsafe { from_glib_full(ffi::gtk_icon_paintable_get_file(self.to_glib_none().0)) }
    }

    /// Get the icon name being used for this icon.
    ///
    /// When an icon looked up in the icon theme was not available, the
    /// icon theme may use fallback icons - either those specified to
    /// gtk_icon_theme_lookup_icon() or the always-available
    /// "image-missing". The icon chosen is returned by this function.
    ///
    /// If the icon was created without an icon theme, this function
    /// returns [`None`].
    ///
    /// # Returns
    ///
    /// the themed icon-name for the
    ///   icon, or [`None`] if its not a themed icon.
    #[doc(alias = "gtk_icon_paintable_get_icon_name")]
    #[doc(alias = "get_icon_name")]
    pub fn icon_name(&self) -> Option<std::path::PathBuf> {
        unsafe { from_glib_none(ffi::gtk_icon_paintable_get_icon_name(self.to_glib_none().0)) }
    }

    /// Checks if the icon is symbolic or not.
    ///
    /// This currently uses only the file name and not the file contents
    /// for determining this. This behaviour may change in the future.
    ///
    /// Note that to render a symbolic [`IconPaintable`][crate::IconPaintable] properly (with
    /// recoloring), you have to set its icon name on a [`Image`][crate::Image].
    ///
    /// # Returns
    ///
    /// [`true`] if the icon is symbolic, [`false`] otherwise
    #[doc(alias = "gtk_icon_paintable_is_symbolic")]
    pub fn is_symbolic(&self) -> bool {
        unsafe { from_glib(ffi::gtk_icon_paintable_is_symbolic(self.to_glib_none().0)) }
    }
}

impl fmt::Display for IconPaintable {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("IconPaintable")
    }
}