gtk4/
icon_theme.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{translate::*, Slice};
4
5use crate::IconTheme;
6
7impl IconTheme {
8    /// Returns an array of integers describing the sizes at which
9    /// the icon is available without scaling.
10    ///
11    /// A size of -1 means that the icon is available in a scalable
12    /// format. The array is zero-terminated.
13    /// ## `icon_name`
14    /// the name of an icon
15    ///
16    /// # Returns
17    ///
18    /// A newly
19    ///   allocated array describing the sizes at which the icon is
20    ///   available. The array should be freed with g_free() when it is no
21    ///   longer needed.
22    #[doc(alias = "gtk_icon_theme_get_icon_sizes")]
23    #[doc(alias = "get_icon_sizes")]
24    pub fn icon_sizes(&self, icon_name: impl IntoGStr) -> Slice<i32> {
25        unsafe {
26            let sizes_ptr = icon_name.run_with_gstr(|icon_name| {
27                crate::ffi::gtk_icon_theme_get_icon_sizes(self.to_glib_none().0, icon_name.as_ptr())
28            });
29            let mut len = 0;
30            if !sizes_ptr.is_null() {
31                while std::ptr::read(sizes_ptr.add(len)) != 0 {
32                    len += 1;
33                }
34            }
35            Slice::from_glib_full_num(sizes_ptr, len)
36        }
37    }
38}