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
5#[cfg(feature = "v1_44")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
7use crate::Attribute;
8use crate::ffi;
9use glib::translate::*;
10
11glib::wrapper! {
12 /// A [`AttrList`][crate::AttrList] represents a list of attributes that apply to a section
13 /// of text.
14 ///
15 /// The attributes in a [`AttrList`][crate::AttrList] are, in general, allowed to overlap in
16 /// an arbitrary fashion. However, if the attributes are manipulated only through
17 /// [`change()`][Self::change()], the overlap between properties will meet
18 /// stricter criteria.
19 ///
20 /// Since the [`AttrList`][crate::AttrList] structure is stored as a linear list, it is not
21 /// suitable for storing attributes for large amounts of text. In general, you
22 /// should not use a single [`AttrList`][crate::AttrList] for more than one paragraph of text.
23 #[derive(Debug)]
24 pub struct AttrList(Shared<ffi::PangoAttrList>);
25
26 match fn {
27 ref => |ptr| ffi::pango_attr_list_ref(ptr),
28 unref => |ptr| ffi::pango_attr_list_unref(ptr),
29 type_ => || ffi::pango_attr_list_get_type(),
30 }
31}
32
33impl AttrList {
34 /// Create a new empty attribute list with a reference
35 /// count of one.
36 ///
37 /// # Returns
38 ///
39 /// the newly allocated
40 /// [`AttrList`][crate::AttrList], which should be freed with
41 /// `Pango::AttrList::unref()`
42 #[doc(alias = "pango_attr_list_new")]
43 pub fn new() -> AttrList {
44 unsafe { from_glib_full(ffi::pango_attr_list_new()) }
45 }
46
47 #[doc(alias = "pango_attr_list_copy")]
48 #[must_use]
49 pub fn copy(&self) -> Option<AttrList> {
50 unsafe { from_glib_full(ffi::pango_attr_list_copy(self.to_glib_none().0)) }
51 }
52
53 /// Gets a list of all attributes in @self.
54 ///
55 /// # Returns
56 ///
57 ///
58 /// a list of all attributes in @self. To free this value,
59 /// call `Pango::Attribute::destroy()` on each value and
60 /// g_slist_free() on the list.
61 #[cfg(feature = "v1_44")]
62 #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
63 #[doc(alias = "pango_attr_list_get_attributes")]
64 #[doc(alias = "get_attributes")]
65 pub fn attributes(&self) -> Vec<Attribute> {
66 unsafe {
67 FromGlibPtrContainer::from_glib_full(ffi::pango_attr_list_get_attributes(
68 self.to_glib_none().0,
69 ))
70 }
71 }
72
73 /// Serializes a [`AttrList`][crate::AttrList] to a string.
74 ///
75 /// In the resulting string, serialized attributes are separated by newlines or commas.
76 /// Individual attributes are serialized to a string of the form
77 ///
78 /// [START END] TYPE VALUE
79 ///
80 /// Where START and END are the indices (with -1 being accepted in place
81 /// of MAXUINT), TYPE is the nickname of the attribute value type, e.g.
82 /// _weight_ or _stretch_, and the value is serialized according to its type:
83 ///
84 /// Optionally, START and END can be omitted to indicate unlimited extent.
85 ///
86 /// - enum values as nick or numeric value
87 /// - boolean values as _true_ or _false_
88 /// - integers and floats as numbers
89 /// - strings as string, optionally quoted
90 /// - font features as quoted string
91 /// - PangoLanguage as string
92 /// - PangoFontDescription as serialized by [`FontDescription::to_str()`][crate::FontDescription::to_str()], quoted
93 /// - PangoColor as serialized by [`Color::to_str()`][crate::Color::to_str()]
94 ///
95 /// Examples:
96 ///
97 /// 0 10 foreground red, 5 15 weight bold, 0 200 font-desc "Sans 10"
98 ///
99 /// 0 -1 weight 700
100 /// 0 100 family Times
101 ///
102 /// weight bold
103 ///
104 /// To parse the returned value, use [`from_string()`][Self::from_string()].
105 ///
106 /// Note that shape attributes can not be serialized.
107 ///
108 /// # Returns
109 ///
110 /// a newly allocated string
111 #[cfg(feature = "v1_50")]
112 #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
113 #[doc(alias = "pango_attr_list_to_string")]
114 #[doc(alias = "to_string")]
115 pub fn to_str(&self) -> glib::GString {
116 unsafe { from_glib_full(ffi::pango_attr_list_to_string(self.to_glib_none().0)) }
117 }
118
119 /// Deserializes a [`AttrList`][crate::AttrList] from a string.
120 ///
121 /// This is the counterpart to [`to_str()`][Self::to_str()].
122 /// See that functions for details about the format.
123 /// ## `text`
124 /// a string
125 ///
126 /// # Returns
127 ///
128 /// a new [`AttrList`][crate::AttrList]
129 #[cfg(feature = "v1_50")]
130 #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
131 #[doc(alias = "pango_attr_list_from_string")]
132 pub fn from_string(text: &str) -> Result<AttrList, glib::BoolError> {
133 unsafe {
134 Option::<_>::from_glib_full(ffi::pango_attr_list_from_string(text.to_glib_none().0))
135 .ok_or_else(|| glib::bool_error!("Can't parse AttrList"))
136 }
137 }
138}
139
140impl Default for AttrList {
141 fn default() -> Self {
142 Self::new()
143 }
144}
145
146#[cfg(feature = "v1_50")]
147#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
148impl std::fmt::Display for AttrList {
149 #[inline]
150 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
151 f.write_str(&self.to_str())
152 }
153}