gio/auto/themed_icon.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, Icon};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// `GThemedIcon` is an implementation of [`Icon`][crate::Icon] that supports icon
15 /// themes.
16 ///
17 /// `GThemedIcon` contains a list of all of the icons present in an icon
18 /// theme, so that icons can be looked up quickly. `GThemedIcon` does
19 /// not provide actual pixmaps for icons, just the icon names.
20 /// Ideally something like `Gtk::IconTheme::choose_icon()` should be used to
21 /// resolve the list of names so that fallback icons work nicely with
22 /// themes that inherit other themes.
23 ///
24 /// ## Properties
25 ///
26 ///
27 /// #### `name`
28 /// The icon name.
29 ///
30 /// Writeable | Construct Only
31 ///
32 ///
33 /// #### `names`
34 /// A [`None`]-terminated array of icon names.
35 ///
36 /// Readable | Writeable | Construct Only
37 ///
38 ///
39 /// #### `use-default-fallbacks`
40 /// Whether to use the default fallbacks found by shortening the icon name
41 /// at '-' characters. If the "names" array has more than one element,
42 /// ignores any past the first.
43 ///
44 /// For example, if the icon name was "gnome-dev-cdrom-audio", the array
45 /// would become
46 ///
47 ///
48 /// **⚠️ The following code is in C ⚠️**
49 ///
50 /// ```C
51 /// {
52 /// "gnome-dev-cdrom-audio",
53 /// "gnome-dev-cdrom",
54 /// "gnome-dev",
55 /// "gnome",
56 /// NULL
57 /// };
58 /// ```
59 ///
60 /// Readable | Writeable | Construct Only
61 ///
62 /// # Implements
63 ///
64 /// [`trait@glib::ObjectExt`], [`IconExt`][trait@crate::prelude::IconExt]
65 #[doc(alias = "GThemedIcon")]
66 pub struct ThemedIcon(Object<ffi::GThemedIcon, ffi::GThemedIconClass>) @implements Icon;
67
68 match fn {
69 type_ => || ffi::g_themed_icon_get_type(),
70 }
71}
72
73impl ThemedIcon {
74 /// Creates a new themed icon for @iconname.
75 /// ## `iconname`
76 /// a string containing an icon name.
77 ///
78 /// # Returns
79 ///
80 /// a new #GThemedIcon.
81 #[doc(alias = "g_themed_icon_new")]
82 pub fn new(iconname: &str) -> ThemedIcon {
83 unsafe { from_glib_full(ffi::g_themed_icon_new(iconname.to_glib_none().0)) }
84 }
85
86 /// Creates a new themed icon for @iconnames.
87 /// ## `iconnames`
88 /// an array of strings containing icon names.
89 ///
90 /// # Returns
91 ///
92 /// a new #GThemedIcon
93 #[doc(alias = "g_themed_icon_new_from_names")]
94 #[doc(alias = "new_from_names")]
95 pub fn from_names(iconnames: &[&str]) -> ThemedIcon {
96 let len = iconnames.len() as _;
97 unsafe {
98 from_glib_full(ffi::g_themed_icon_new_from_names(
99 iconnames.to_glib_none().0,
100 len,
101 ))
102 }
103 }
104
105 /// Creates a new themed icon for @iconname, and all the names
106 /// that can be created by shortening @iconname at '-' characters.
107 ///
108 /// In the following example, @icon1 and @icon2 are equivalent:
109 ///
110 ///
111 /// **⚠️ The following code is in C ⚠️**
112 ///
113 /// ```C
114 /// const char *names[] = {
115 /// "gnome-dev-cdrom-audio",
116 /// "gnome-dev-cdrom",
117 /// "gnome-dev",
118 /// "gnome"
119 /// };
120 ///
121 /// icon1 = g_themed_icon_new_from_names (names, 4);
122 /// icon2 = g_themed_icon_new_with_default_fallbacks ("gnome-dev-cdrom-audio");
123 /// ```
124 /// ## `iconname`
125 /// a string containing an icon name
126 ///
127 /// # Returns
128 ///
129 /// a new #GThemedIcon.
130 #[doc(alias = "g_themed_icon_new_with_default_fallbacks")]
131 #[doc(alias = "new_with_default_fallbacks")]
132 pub fn with_default_fallbacks(iconname: &str) -> ThemedIcon {
133 unsafe {
134 from_glib_full(ffi::g_themed_icon_new_with_default_fallbacks(
135 iconname.to_glib_none().0,
136 ))
137 }
138 }
139
140 /// Append a name to the list of icons from within @self.
141 ///
142 /// Note that doing so invalidates the hash computed by prior calls
143 /// to g_icon_hash().
144 /// ## `iconname`
145 /// name of icon to append to list of icons from within @self.
146 #[doc(alias = "g_themed_icon_append_name")]
147 pub fn append_name(&self, iconname: &str) {
148 unsafe {
149 ffi::g_themed_icon_append_name(self.to_glib_none().0, iconname.to_glib_none().0);
150 }
151 }
152
153 /// Gets the names of icons from within @self.
154 ///
155 /// # Returns
156 ///
157 /// a list of icon names.
158 #[doc(alias = "g_themed_icon_get_names")]
159 #[doc(alias = "get_names")]
160 pub fn names(&self) -> Vec<glib::GString> {
161 unsafe {
162 FromGlibPtrContainer::from_glib_none(ffi::g_themed_icon_get_names(
163 self.to_glib_none().0,
164 ))
165 }
166 }
167
168 /// Prepend a name to the list of icons from within @self.
169 ///
170 /// Note that doing so invalidates the hash computed by prior calls
171 /// to g_icon_hash().
172 /// ## `iconname`
173 /// name of icon to prepend to list of icons from within @self.
174 #[doc(alias = "g_themed_icon_prepend_name")]
175 pub fn prepend_name(&self, iconname: &str) {
176 unsafe {
177 ffi::g_themed_icon_prepend_name(self.to_glib_none().0, iconname.to_glib_none().0);
178 }
179 }
180
181 /// Whether to use the default fallbacks found by shortening the icon name
182 /// at '-' characters. If the "names" array has more than one element,
183 /// ignores any past the first.
184 ///
185 /// For example, if the icon name was "gnome-dev-cdrom-audio", the array
186 /// would become
187 ///
188 ///
189 /// **⚠️ The following code is in C ⚠️**
190 ///
191 /// ```C
192 /// {
193 /// "gnome-dev-cdrom-audio",
194 /// "gnome-dev-cdrom",
195 /// "gnome-dev",
196 /// "gnome",
197 /// NULL
198 /// };
199 /// ```
200 #[doc(alias = "use-default-fallbacks")]
201 pub fn uses_default_fallbacks(&self) -> bool {
202 ObjectExt::property(self, "use-default-fallbacks")
203 }
204
205 #[doc(alias = "names")]
206 pub fn connect_names_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
207 unsafe extern "C" fn notify_names_trampoline<F: Fn(&ThemedIcon) + 'static>(
208 this: *mut ffi::GThemedIcon,
209 _param_spec: glib::ffi::gpointer,
210 f: glib::ffi::gpointer,
211 ) {
212 let f: &F = &*(f as *const F);
213 f(&from_glib_borrow(this))
214 }
215 unsafe {
216 let f: Box_<F> = Box_::new(f);
217 connect_raw(
218 self.as_ptr() as *mut _,
219 b"notify::names\0".as_ptr() as *const _,
220 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221 notify_names_trampoline::<F> as *const (),
222 )),
223 Box_::into_raw(f),
224 )
225 }
226 }
227}