[go: up one dir, main page]

gtk4/auto/
icon_theme.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, IconLookupFlags, IconPaintable, TextDirection};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "GtkIconTheme")]
16    pub struct IconTheme(Object<ffi::GtkIconTheme>);
17
18    match fn {
19        type_ => || ffi::gtk_icon_theme_get_type(),
20    }
21}
22
23impl IconTheme {
24    #[doc(alias = "gtk_icon_theme_new")]
25    pub fn new() -> IconTheme {
26        assert_initialized_main_thread!();
27        unsafe { from_glib_full(ffi::gtk_icon_theme_new()) }
28    }
29
30    // rustdoc-stripper-ignore-next
31    /// Creates a new builder-pattern struct instance to construct [`IconTheme`] objects.
32    ///
33    /// This method returns an instance of [`IconThemeBuilder`](crate::builders::IconThemeBuilder) which can be used to create [`IconTheme`] objects.
34    pub fn builder() -> IconThemeBuilder {
35        IconThemeBuilder::new()
36    }
37
38    #[doc(alias = "gtk_icon_theme_add_resource_path")]
39    pub fn add_resource_path(&self, path: &str) {
40        unsafe {
41            ffi::gtk_icon_theme_add_resource_path(self.to_glib_none().0, path.to_glib_none().0);
42        }
43    }
44
45    #[doc(alias = "gtk_icon_theme_add_search_path")]
46    pub fn add_search_path(&self, path: impl AsRef<std::path::Path>) {
47        unsafe {
48            ffi::gtk_icon_theme_add_search_path(
49                self.to_glib_none().0,
50                path.as_ref().to_glib_none().0,
51            );
52        }
53    }
54
55    #[doc(alias = "gtk_icon_theme_get_display")]
56    #[doc(alias = "get_display")]
57    pub fn display(&self) -> Option<gdk::Display> {
58        unsafe { from_glib_none(ffi::gtk_icon_theme_get_display(self.to_glib_none().0)) }
59    }
60
61    #[doc(alias = "gtk_icon_theme_get_icon_names")]
62    #[doc(alias = "get_icon_names")]
63    #[doc(alias = "icon-names")]
64    pub fn icon_names(&self) -> Vec<glib::GString> {
65        unsafe {
66            FromGlibPtrContainer::from_glib_full(ffi::gtk_icon_theme_get_icon_names(
67                self.to_glib_none().0,
68            ))
69        }
70    }
71
72    #[doc(alias = "gtk_icon_theme_get_resource_path")]
73    #[doc(alias = "get_resource_path")]
74    #[doc(alias = "resource-path")]
75    pub fn resource_path(&self) -> Vec<glib::GString> {
76        unsafe {
77            FromGlibPtrContainer::from_glib_full(ffi::gtk_icon_theme_get_resource_path(
78                self.to_glib_none().0,
79            ))
80        }
81    }
82
83    #[doc(alias = "gtk_icon_theme_get_search_path")]
84    #[doc(alias = "get_search_path")]
85    #[doc(alias = "search-path")]
86    pub fn search_path(&self) -> Vec<std::path::PathBuf> {
87        unsafe {
88            FromGlibPtrContainer::from_glib_full(ffi::gtk_icon_theme_get_search_path(
89                self.to_glib_none().0,
90            ))
91        }
92    }
93
94    #[doc(alias = "gtk_icon_theme_get_theme_name")]
95    #[doc(alias = "get_theme_name")]
96    #[doc(alias = "theme-name")]
97    pub fn theme_name(&self) -> glib::GString {
98        unsafe { from_glib_full(ffi::gtk_icon_theme_get_theme_name(self.to_glib_none().0)) }
99    }
100
101    #[cfg(feature = "v4_2")]
102    #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
103    #[doc(alias = "gtk_icon_theme_has_gicon")]
104    pub fn has_gicon(&self, gicon: &impl IsA<gio::Icon>) -> bool {
105        unsafe {
106            from_glib(ffi::gtk_icon_theme_has_gicon(
107                self.to_glib_none().0,
108                gicon.as_ref().to_glib_none().0,
109            ))
110        }
111    }
112
113    #[doc(alias = "gtk_icon_theme_has_icon")]
114    pub fn has_icon(&self, icon_name: &str) -> bool {
115        unsafe {
116            from_glib(ffi::gtk_icon_theme_has_icon(
117                self.to_glib_none().0,
118                icon_name.to_glib_none().0,
119            ))
120        }
121    }
122
123    #[doc(alias = "gtk_icon_theme_lookup_by_gicon")]
124    pub fn lookup_by_gicon(
125        &self,
126        icon: &impl IsA<gio::Icon>,
127        size: i32,
128        scale: i32,
129        direction: TextDirection,
130        flags: IconLookupFlags,
131    ) -> IconPaintable {
132        unsafe {
133            from_glib_full(ffi::gtk_icon_theme_lookup_by_gicon(
134                self.to_glib_none().0,
135                icon.as_ref().to_glib_none().0,
136                size,
137                scale,
138                direction.into_glib(),
139                flags.into_glib(),
140            ))
141        }
142    }
143
144    #[doc(alias = "gtk_icon_theme_lookup_icon")]
145    pub fn lookup_icon(
146        &self,
147        icon_name: &str,
148        fallbacks: &[&str],
149        size: i32,
150        scale: i32,
151        direction: TextDirection,
152        flags: IconLookupFlags,
153    ) -> IconPaintable {
154        unsafe {
155            from_glib_full(ffi::gtk_icon_theme_lookup_icon(
156                self.to_glib_none().0,
157                icon_name.to_glib_none().0,
158                fallbacks.to_glib_none().0,
159                size,
160                scale,
161                direction.into_glib(),
162                flags.into_glib(),
163            ))
164        }
165    }
166
167    #[doc(alias = "gtk_icon_theme_set_resource_path")]
168    #[doc(alias = "resource-path")]
169    pub fn set_resource_path(&self, path: &[&str]) {
170        unsafe {
171            ffi::gtk_icon_theme_set_resource_path(self.to_glib_none().0, path.to_glib_none().0);
172        }
173    }
174
175    #[doc(alias = "gtk_icon_theme_set_search_path")]
176    #[doc(alias = "search-path")]
177    pub fn set_search_path(&self, path: &[&std::path::Path]) {
178        unsafe {
179            ffi::gtk_icon_theme_set_search_path(self.to_glib_none().0, path.to_glib_none().0);
180        }
181    }
182
183    #[doc(alias = "gtk_icon_theme_set_theme_name")]
184    #[doc(alias = "theme-name")]
185    pub fn set_theme_name(&self, theme_name: Option<&str>) {
186        unsafe {
187            ffi::gtk_icon_theme_set_theme_name(self.to_glib_none().0, theme_name.to_glib_none().0);
188        }
189    }
190
191    pub fn set_display<P: IsA<gdk::Display>>(&self, display: Option<&P>) {
192        ObjectExt::set_property(self, "display", display)
193    }
194
195    #[doc(alias = "gtk_icon_theme_get_for_display")]
196    #[doc(alias = "get_for_display")]
197    pub fn for_display(display: &impl IsA<gdk::Display>) -> IconTheme {
198        assert_initialized_main_thread!();
199        unsafe {
200            from_glib_none(ffi::gtk_icon_theme_get_for_display(
201                display.as_ref().to_glib_none().0,
202            ))
203        }
204    }
205
206    #[doc(alias = "changed")]
207    pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
208        unsafe extern "C" fn changed_trampoline<F: Fn(&IconTheme) + 'static>(
209            this: *mut ffi::GtkIconTheme,
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                c"changed".as_ptr() as *const _,
220                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221                    changed_trampoline::<F> as *const (),
222                )),
223                Box_::into_raw(f),
224            )
225        }
226    }
227
228    #[doc(alias = "display")]
229    pub fn connect_display_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
230        unsafe extern "C" fn notify_display_trampoline<F: Fn(&IconTheme) + 'static>(
231            this: *mut ffi::GtkIconTheme,
232            _param_spec: glib::ffi::gpointer,
233            f: glib::ffi::gpointer,
234        ) {
235            let f: &F = &*(f as *const F);
236            f(&from_glib_borrow(this))
237        }
238        unsafe {
239            let f: Box_<F> = Box_::new(f);
240            connect_raw(
241                self.as_ptr() as *mut _,
242                c"notify::display".as_ptr() as *const _,
243                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
244                    notify_display_trampoline::<F> as *const (),
245                )),
246                Box_::into_raw(f),
247            )
248        }
249    }
250
251    #[doc(alias = "icon-names")]
252    pub fn connect_icon_names_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
253        unsafe extern "C" fn notify_icon_names_trampoline<F: Fn(&IconTheme) + 'static>(
254            this: *mut ffi::GtkIconTheme,
255            _param_spec: glib::ffi::gpointer,
256            f: glib::ffi::gpointer,
257        ) {
258            let f: &F = &*(f as *const F);
259            f(&from_glib_borrow(this))
260        }
261        unsafe {
262            let f: Box_<F> = Box_::new(f);
263            connect_raw(
264                self.as_ptr() as *mut _,
265                c"notify::icon-names".as_ptr() as *const _,
266                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
267                    notify_icon_names_trampoline::<F> as *const (),
268                )),
269                Box_::into_raw(f),
270            )
271        }
272    }
273
274    #[doc(alias = "resource-path")]
275    pub fn connect_resource_path_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
276        unsafe extern "C" fn notify_resource_path_trampoline<F: Fn(&IconTheme) + 'static>(
277            this: *mut ffi::GtkIconTheme,
278            _param_spec: glib::ffi::gpointer,
279            f: glib::ffi::gpointer,
280        ) {
281            let f: &F = &*(f as *const F);
282            f(&from_glib_borrow(this))
283        }
284        unsafe {
285            let f: Box_<F> = Box_::new(f);
286            connect_raw(
287                self.as_ptr() as *mut _,
288                c"notify::resource-path".as_ptr() as *const _,
289                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
290                    notify_resource_path_trampoline::<F> as *const (),
291                )),
292                Box_::into_raw(f),
293            )
294        }
295    }
296
297    #[doc(alias = "search-path")]
298    pub fn connect_search_path_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
299        unsafe extern "C" fn notify_search_path_trampoline<F: Fn(&IconTheme) + 'static>(
300            this: *mut ffi::GtkIconTheme,
301            _param_spec: glib::ffi::gpointer,
302            f: glib::ffi::gpointer,
303        ) {
304            let f: &F = &*(f as *const F);
305            f(&from_glib_borrow(this))
306        }
307        unsafe {
308            let f: Box_<F> = Box_::new(f);
309            connect_raw(
310                self.as_ptr() as *mut _,
311                c"notify::search-path".as_ptr() as *const _,
312                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
313                    notify_search_path_trampoline::<F> as *const (),
314                )),
315                Box_::into_raw(f),
316            )
317        }
318    }
319
320    #[doc(alias = "theme-name")]
321    pub fn connect_theme_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
322        unsafe extern "C" fn notify_theme_name_trampoline<F: Fn(&IconTheme) + 'static>(
323            this: *mut ffi::GtkIconTheme,
324            _param_spec: glib::ffi::gpointer,
325            f: glib::ffi::gpointer,
326        ) {
327            let f: &F = &*(f as *const F);
328            f(&from_glib_borrow(this))
329        }
330        unsafe {
331            let f: Box_<F> = Box_::new(f);
332            connect_raw(
333                self.as_ptr() as *mut _,
334                c"notify::theme-name".as_ptr() as *const _,
335                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
336                    notify_theme_name_trampoline::<F> as *const (),
337                )),
338                Box_::into_raw(f),
339            )
340        }
341    }
342}
343
344impl Default for IconTheme {
345    fn default() -> Self {
346        Self::new()
347    }
348}
349
350// rustdoc-stripper-ignore-next
351/// A [builder-pattern] type to construct [`IconTheme`] objects.
352///
353/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
354#[must_use = "The builder must be built to be used"]
355pub struct IconThemeBuilder {
356    builder: glib::object::ObjectBuilder<'static, IconTheme>,
357}
358
359impl IconThemeBuilder {
360    fn new() -> Self {
361        Self {
362            builder: glib::object::Object::builder(),
363        }
364    }
365
366    pub fn display(self, display: &impl IsA<gdk::Display>) -> Self {
367        Self {
368            builder: self.builder.property("display", display.clone().upcast()),
369        }
370    }
371
372    pub fn resource_path(self, resource_path: impl Into<glib::StrV>) -> Self {
373        Self {
374            builder: self.builder.property("resource-path", resource_path.into()),
375        }
376    }
377
378    pub fn search_path(self, search_path: impl Into<glib::StrV>) -> Self {
379        Self {
380            builder: self.builder.property("search-path", search_path.into()),
381        }
382    }
383
384    pub fn theme_name(self, theme_name: impl Into<glib::GString>) -> Self {
385        Self {
386            builder: self.builder.property("theme-name", theme_name.into()),
387        }
388    }
389
390    // rustdoc-stripper-ignore-next
391    /// Build the [`IconTheme`].
392    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
393    pub fn build(self) -> IconTheme {
394        assert_initialized_main_thread!();
395        self.builder.build()
396    }
397}