Skip to main content

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::{Attribute, ffi};
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            unsafe {
40                let attribute = from_glib_borrow(attribute);
41                let callback = user_data as *mut P;
42                (*callback)(&attribute).into_glib()
43            }
44        }
45        let func = Some(func_func::<P> as _);
46        let super_callback0: &mut P = &mut func_data;
47        unsafe {
48            from_glib_full(ffi::pango_attr_list_filter(
49                self.to_glib_none().0,
50                func,
51                super_callback0 as *mut _ as *mut _,
52            ))
53        }
54    }
55
56    #[cfg(feature = "v1_44")]
57    #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
58    #[doc(alias = "pango_attr_list_get_attributes")]
59    #[doc(alias = "get_attributes")]
60    pub fn attributes(&self) -> Vec<Attribute> {
61        unsafe {
62            FromGlibPtrContainer::from_glib_full(ffi::pango_attr_list_get_attributes(
63                self.to_glib_none().0,
64            ))
65        }
66    }
67
68    #[doc(alias = "pango_attr_list_splice")]
69    pub fn splice(&self, other: &AttrList, pos: i32, len: i32) {
70        unsafe {
71            ffi::pango_attr_list_splice(self.to_glib_none().0, other.to_glib_none().0, pos, len);
72        }
73    }
74
75    #[cfg(feature = "v1_50")]
76    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
77    #[doc(alias = "pango_attr_list_to_string")]
78    #[doc(alias = "to_string")]
79    pub fn to_str(&self) -> glib::GString {
80        unsafe { from_glib_full(ffi::pango_attr_list_to_string(self.to_glib_none().0)) }
81    }
82
83    #[cfg(feature = "v1_44")]
84    #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
85    #[doc(alias = "pango_attr_list_update")]
86    pub fn update(&self, pos: i32, remove: i32, add: i32) {
87        unsafe {
88            ffi::pango_attr_list_update(self.to_glib_none().0, pos, remove, add);
89        }
90    }
91
92    #[cfg(feature = "v1_50")]
93    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
94    #[doc(alias = "pango_attr_list_from_string")]
95    pub fn from_string(text: &str) -> Result<AttrList, glib::BoolError> {
96        unsafe {
97            Option::<_>::from_glib_full(ffi::pango_attr_list_from_string(text.to_glib_none().0))
98                .ok_or_else(|| glib::bool_error!("Can't parse AttrList"))
99        }
100    }
101}
102
103impl Default for AttrList {
104    fn default() -> Self {
105        Self::new()
106    }
107}
108
109#[cfg(feature = "v1_50")]
110#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
111impl std::fmt::Display for AttrList {
112    #[inline]
113    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
114        f.write_str(&self.to_str())
115    }
116}