pango/auto/
attr_list.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, Attribute};
6use glib::translate::*;
7
8glib::wrapper! {
9    #[derive(Debug)]
10    pub struct AttrList(Shared<ffi::PangoAttrList>);
11
12    match fn {
13        ref => |ptr| ffi::pango_attr_list_ref(ptr),
14        unref => |ptr| ffi::pango_attr_list_unref(ptr),
15        type_ => || ffi::pango_attr_list_get_type(),
16    }
17}
18
19impl AttrList {
20    #[doc(alias = "pango_attr_list_new")]
21    pub fn new() -> AttrList {
22        unsafe { from_glib_full(ffi::pango_attr_list_new()) }
23    }
24
25    #[doc(alias = "pango_attr_list_copy")]
26    #[must_use]
27    pub fn copy(&self) -> Option<AttrList> {
28        unsafe { from_glib_full(ffi::pango_attr_list_copy(self.to_glib_none().0)) }
29    }
30
31    #[doc(alias = "pango_attr_list_filter")]
32    #[must_use]
33    pub fn filter<P: FnMut(&Attribute) -> bool>(&self, func: P) -> Option<AttrList> {
34        let mut func_data: P = func;
35        unsafe extern "C" fn func_func<P: FnMut(&Attribute) -> bool>(
36            attribute: *mut ffi::PangoAttribute,
37            user_data: glib::ffi::gpointer,
38        ) -> glib::ffi::gboolean {
39            let attribute = from_glib_borrow(attribute);
40            let callback = user_data as *mut P;
41            (*callback)(&attribute).into_glib()
42        }
43        let func = Some(func_func::<P> as _);
44        let super_callback0: &mut P = &mut func_data;
45        unsafe {
46            from_glib_full(ffi::pango_attr_list_filter(
47                self.to_glib_none().0,
48                func,
49                super_callback0 as *mut _ as *mut _,
50            ))
51        }
52    }
53
54    #[cfg(feature = "v1_44")]
55    #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
56    #[doc(alias = "pango_attr_list_get_attributes")]
57    #[doc(alias = "get_attributes")]
58    pub fn attributes(&self) -> Vec<Attribute> {
59        unsafe {
60            FromGlibPtrContainer::from_glib_full(ffi::pango_attr_list_get_attributes(
61                self.to_glib_none().0,
62            ))
63        }
64    }
65
66    #[doc(alias = "pango_attr_list_splice")]
67    pub fn splice(&self, other: &AttrList, pos: i32, len: i32) {
68        unsafe {
69            ffi::pango_attr_list_splice(self.to_glib_none().0, other.to_glib_none().0, pos, len);
70        }
71    }
72
73    #[cfg(feature = "v1_50")]
74    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
75    #[doc(alias = "pango_attr_list_to_string")]
76    #[doc(alias = "to_string")]
77    pub fn to_str(&self) -> glib::GString {
78        unsafe { from_glib_full(ffi::pango_attr_list_to_string(self.to_glib_none().0)) }
79    }
80
81    #[cfg(feature = "v1_44")]
82    #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
83    #[doc(alias = "pango_attr_list_update")]
84    pub fn update(&self, pos: i32, remove: i32, add: i32) {
85        unsafe {
86            ffi::pango_attr_list_update(self.to_glib_none().0, pos, remove, add);
87        }
88    }
89
90    #[cfg(feature = "v1_50")]
91    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
92    #[doc(alias = "pango_attr_list_from_string")]
93    pub fn from_string(text: &str) -> Result<AttrList, glib::BoolError> {
94        unsafe {
95            Option::<_>::from_glib_full(ffi::pango_attr_list_from_string(text.to_glib_none().0))
96                .ok_or_else(|| glib::bool_error!("Can't parse AttrList"))
97        }
98    }
99}
100
101impl Default for AttrList {
102    fn default() -> Self {
103        Self::new()
104    }
105}
106
107#[cfg(feature = "v1_50")]
108#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
109impl std::fmt::Display for AttrList {
110    #[inline]
111    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
112        f.write_str(&self.to_str())
113    }
114}