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::{Icon, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
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 /// Writable | Construct Only
31 ///
32 ///
33 /// #### `names`
34 /// A [`None`]-terminated array of icon names.
35 ///
36 /// Readable | Writable | Construct Only
37 ///
38 ///
39 /// #### `use-default-fallbacks`
40 ///
41 /// {
42 /// "gnome-dev-cdrom-audio",
43 /// "gnome-dev-cdrom",
44 /// "gnome-dev",
45 /// "gnome",
46 /// NULL
47 /// };
48 /// ]|
49 ///
50 /// Readable | Writable | Construct Only
51 ///
52 /// # Implements
53 ///
54 /// [`trait@glib::ObjectExt`], [`IconExt`][trait@crate::prelude::IconExt]
55 #[doc(alias = "GThemedIcon")]
56 pub struct ThemedIcon(Object<ffi::GThemedIcon, ffi::GThemedIconClass>) @implements Icon;
57
58 match fn {
59 type_ => || ffi::g_themed_icon_get_type(),
60 }
61}
62
63impl ThemedIcon {
64 /// Creates a new themed icon for @iconname.
65 /// ## `iconname`
66 /// a string containing an icon name.
67 ///
68 /// # Returns
69 ///
70 /// a new #GThemedIcon.
71 #[doc(alias = "g_themed_icon_new")]
72 pub fn new(iconname: &str) -> ThemedIcon {
73 unsafe { from_glib_full(ffi::g_themed_icon_new(iconname.to_glib_none().0)) }
74 }
75
76 /// Creates a new themed icon for @iconnames.
77 /// ## `iconnames`
78 /// an array of strings containing icon names.
79 ///
80 /// # Returns
81 ///
82 /// a new #GThemedIcon
83 #[doc(alias = "g_themed_icon_new_from_names")]
84 #[doc(alias = "new_from_names")]
85 pub fn from_names(iconnames: &[&str]) -> ThemedIcon {
86 let len = iconnames.len() as _;
87 unsafe {
88 from_glib_full(ffi::g_themed_icon_new_from_names(
89 iconnames.to_glib_none().0,
90 len,
91 ))
92 }
93 }
94
95 ///
96 /// const char *names[] = {
97 /// "gnome-dev-cdrom-audio",
98 /// "gnome-dev-cdrom",
99 /// "gnome-dev",
100 /// "gnome"
101 /// };
102 ///
103 /// icon1 = g_themed_icon_new_from_names (names, 4);
104 /// icon2 = g_themed_icon_new_with_default_fallbacks ("gnome-dev-cdrom-audio");
105 /// ]|
106 /// ## `iconname`
107 /// a string containing an icon name
108 ///
109 /// # Returns
110 ///
111 /// a new #GThemedIcon.
112 #[doc(alias = "g_themed_icon_new_with_default_fallbacks")]
113 #[doc(alias = "new_with_default_fallbacks")]
114 pub fn with_default_fallbacks(iconname: &str) -> ThemedIcon {
115 unsafe {
116 from_glib_full(ffi::g_themed_icon_new_with_default_fallbacks(
117 iconname.to_glib_none().0,
118 ))
119 }
120 }
121
122 /// Append a name to the list of icons from within @self.
123 ///
124 /// Note that doing so invalidates the hash computed by prior calls
125 /// to g_icon_hash().
126 /// ## `iconname`
127 /// name of icon to append to list of icons from within @self.
128 #[doc(alias = "g_themed_icon_append_name")]
129 pub fn append_name(&self, iconname: &str) {
130 unsafe {
131 ffi::g_themed_icon_append_name(self.to_glib_none().0, iconname.to_glib_none().0);
132 }
133 }
134
135 /// Gets the names of icons from within @self.
136 ///
137 /// # Returns
138 ///
139 /// a list of icon names.
140 #[doc(alias = "g_themed_icon_get_names")]
141 #[doc(alias = "get_names")]
142 pub fn names(&self) -> Vec<glib::GString> {
143 unsafe {
144 FromGlibPtrContainer::from_glib_none(ffi::g_themed_icon_get_names(
145 self.to_glib_none().0,
146 ))
147 }
148 }
149
150 /// Prepend a name to the list of icons from within @self.
151 ///
152 /// Note that doing so invalidates the hash computed by prior calls
153 /// to g_icon_hash().
154 /// ## `iconname`
155 /// name of icon to prepend to list of icons from within @self.
156 #[doc(alias = "g_themed_icon_prepend_name")]
157 pub fn prepend_name(&self, iconname: &str) {
158 unsafe {
159 ffi::g_themed_icon_prepend_name(self.to_glib_none().0, iconname.to_glib_none().0);
160 }
161 }
162
163 ///
164 /// {
165 /// "gnome-dev-cdrom-audio",
166 /// "gnome-dev-cdrom",
167 /// "gnome-dev",
168 /// "gnome",
169 /// NULL
170 /// };
171 /// ]|
172 #[doc(alias = "use-default-fallbacks")]
173 pub fn uses_default_fallbacks(&self) -> bool {
174 ObjectExt::property(self, "use-default-fallbacks")
175 }
176
177 #[doc(alias = "names")]
178 pub fn connect_names_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
179 unsafe extern "C" fn notify_names_trampoline<F: Fn(&ThemedIcon) + 'static>(
180 this: *mut ffi::GThemedIcon,
181 _param_spec: glib::ffi::gpointer,
182 f: glib::ffi::gpointer,
183 ) {
184 unsafe {
185 let f: &F = &*(f as *const F);
186 f(&from_glib_borrow(this))
187 }
188 }
189 unsafe {
190 let f: Box_<F> = Box_::new(f);
191 connect_raw(
192 self.as_ptr() as *mut _,
193 c"notify::names".as_ptr(),
194 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
195 notify_names_trampoline::<F> as *const (),
196 )),
197 Box_::into_raw(f),
198 )
199 }
200 }
201}