pango/auto/
tab_array.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, TabAlign};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A [`TabArray`][crate::TabArray] contains an array of tab stops.
10    ///
11    /// [`TabArray`][crate::TabArray] can be used to set tab stops in a [`Layout`][crate::Layout].
12    /// Each tab stop has an alignment, a position, and optionally
13    /// a character to use as decimal point.
14    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
15    pub struct TabArray(Boxed<ffi::PangoTabArray>);
16
17    match fn {
18        copy => |ptr| ffi::pango_tab_array_copy(mut_override(ptr)),
19        free => |ptr| ffi::pango_tab_array_free(ptr),
20        type_ => || ffi::pango_tab_array_get_type(),
21    }
22}
23
24impl TabArray {
25    /// Creates an array of @initial_size tab stops.
26    ///
27    /// Tab stops are specified in pixel units if @positions_in_pixels is [`true`],
28    /// otherwise in Pango units. All stops are initially at position 0.
29    /// ## `initial_size`
30    /// Initial number of tab stops to allocate, can be 0
31    /// ## `positions_in_pixels`
32    /// whether positions are in pixel units
33    ///
34    /// # Returns
35    ///
36    /// the newly allocated [`TabArray`][crate::TabArray], which should
37    ///   be freed with `Pango::TabArray::free()`.
38    #[doc(alias = "pango_tab_array_new")]
39    pub fn new(initial_size: i32, positions_in_pixels: bool) -> TabArray {
40        unsafe {
41            from_glib_full(ffi::pango_tab_array_new(
42                initial_size,
43                positions_in_pixels.into_glib(),
44            ))
45        }
46    }
47
48    //#[doc(alias = "pango_tab_array_new_with_positions")]
49    //#[doc(alias = "new_with_positions")]
50    //pub fn with_positions(size: i32, positions_in_pixels: bool, first_alignment: TabAlign, first_position: i32, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> TabArray {
51    //    unsafe { TODO: call ffi:pango_tab_array_new_with_positions() }
52    //}
53
54    /// Gets the Unicode character to use as decimal point.
55    ///
56    /// This is only relevant for tabs with [`TabAlign::Decimal`][crate::TabAlign::Decimal] alignment,
57    /// which align content at the first occurrence of the decimal point
58    /// character.
59    ///
60    /// The default value of 0 means that Pango will use the
61    /// decimal point according to the current locale.
62    /// ## `tab_index`
63    /// the index of a tab stop
64    #[cfg(feature = "v1_50")]
65    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
66    #[doc(alias = "pango_tab_array_get_decimal_point")]
67    #[doc(alias = "get_decimal_point")]
68    pub fn decimal_point(&self, tab_index: i32) -> char {
69        unsafe {
70            std::convert::TryFrom::try_from(ffi::pango_tab_array_get_decimal_point(
71                mut_override(self.to_glib_none().0),
72                tab_index,
73            ))
74            .expect("conversion from an invalid Unicode value attempted")
75        }
76    }
77
78    /// Returns [`true`] if the tab positions are in pixels,
79    /// [`false`] if they are in Pango units.
80    ///
81    /// # Returns
82    ///
83    /// whether positions are in pixels.
84    #[doc(alias = "pango_tab_array_get_positions_in_pixels")]
85    #[doc(alias = "get_positions_in_pixels")]
86    pub fn is_positions_in_pixels(&self) -> bool {
87        unsafe {
88            from_glib(ffi::pango_tab_array_get_positions_in_pixels(mut_override(
89                self.to_glib_none().0,
90            )))
91        }
92    }
93
94    /// Gets the number of tab stops in @self.
95    ///
96    /// # Returns
97    ///
98    /// the number of tab stops in the array.
99    #[doc(alias = "pango_tab_array_get_size")]
100    #[doc(alias = "get_size")]
101    pub fn size(&self) -> i32 {
102        unsafe { ffi::pango_tab_array_get_size(mut_override(self.to_glib_none().0)) }
103    }
104
105    /// Gets the alignment and position of a tab stop.
106    /// ## `tab_index`
107    /// tab stop index
108    ///
109    /// # Returns
110    ///
111    ///
112    /// ## `alignment`
113    /// location to store alignment
114    ///
115    /// ## `location`
116    /// location to store tab position
117    #[doc(alias = "pango_tab_array_get_tab")]
118    #[doc(alias = "get_tab")]
119    pub fn tab(&self, tab_index: i32) -> (TabAlign, i32) {
120        unsafe {
121            let mut alignment = std::mem::MaybeUninit::uninit();
122            let mut location = std::mem::MaybeUninit::uninit();
123            ffi::pango_tab_array_get_tab(
124                mut_override(self.to_glib_none().0),
125                tab_index,
126                alignment.as_mut_ptr(),
127                location.as_mut_ptr(),
128            );
129            (from_glib(alignment.assume_init()), location.assume_init())
130        }
131    }
132
133    /// Resizes a tab array.
134    ///
135    /// You must subsequently initialize any tabs
136    /// that were added as a result of growing the array.
137    /// ## `new_size`
138    /// new size of the array
139    #[doc(alias = "pango_tab_array_resize")]
140    pub fn resize(&mut self, new_size: i32) {
141        unsafe {
142            ffi::pango_tab_array_resize(self.to_glib_none_mut().0, new_size);
143        }
144    }
145
146    /// Sets the Unicode character to use as decimal point.
147    ///
148    /// This is only relevant for tabs with [`TabAlign::Decimal`][crate::TabAlign::Decimal] alignment,
149    /// which align content at the first occurrence of the decimal point
150    /// character.
151    ///
152    /// By default, Pango uses the decimal point according
153    /// to the current locale.
154    /// ## `tab_index`
155    /// the index of a tab stop
156    /// ## `decimal_point`
157    /// the decimal point to use
158    #[cfg(feature = "v1_50")]
159    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
160    #[doc(alias = "pango_tab_array_set_decimal_point")]
161    pub fn set_decimal_point(&mut self, tab_index: i32, decimal_point: char) {
162        unsafe {
163            ffi::pango_tab_array_set_decimal_point(
164                self.to_glib_none_mut().0,
165                tab_index,
166                decimal_point.into_glib(),
167            );
168        }
169    }
170
171    /// Sets whether positions in this array are specified in
172    /// pixels.
173    /// ## `positions_in_pixels`
174    /// whether positions are in pixels
175    #[cfg(feature = "v1_50")]
176    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
177    #[doc(alias = "pango_tab_array_set_positions_in_pixels")]
178    pub fn set_positions_in_pixels(&mut self, positions_in_pixels: bool) {
179        unsafe {
180            ffi::pango_tab_array_set_positions_in_pixels(
181                self.to_glib_none_mut().0,
182                positions_in_pixels.into_glib(),
183            );
184        }
185    }
186
187    /// Sets the alignment and location of a tab stop.
188    /// ## `tab_index`
189    /// the index of a tab stop
190    /// ## `alignment`
191    /// tab alignment
192    /// ## `location`
193    /// tab location in Pango units
194    #[doc(alias = "pango_tab_array_set_tab")]
195    pub fn set_tab(&mut self, tab_index: i32, alignment: TabAlign, location: i32) {
196        unsafe {
197            ffi::pango_tab_array_set_tab(
198                self.to_glib_none_mut().0,
199                tab_index,
200                alignment.into_glib(),
201                location,
202            );
203        }
204    }
205
206    /// Utility function to ensure that the tab stops are in increasing order.
207    #[cfg(feature = "v1_50")]
208    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
209    #[doc(alias = "pango_tab_array_sort")]
210    pub fn sort(&mut self) {
211        unsafe {
212            ffi::pango_tab_array_sort(self.to_glib_none_mut().0);
213        }
214    }
215
216    /// Serializes a [`TabArray`][crate::TabArray] to a string.
217    ///
218    /// In the resulting string, serialized tabs are separated by newlines or commas.
219    ///
220    /// Individual tabs are serialized to a string of the form
221    ///
222    ///     [ALIGNMENT:]POSITION[:DECIMAL_POINT]
223    ///
224    /// Where ALIGNMENT is one of _left_, _right_, _center_ or _decimal_, and
225    /// POSITION is the position of the tab, optionally followed by the unit _px_.
226    /// If ALIGNMENT is omitted, it defaults to _left_. If ALIGNMENT is _decimal_,
227    /// the DECIMAL_POINT character may be specified as a Unicode codepoint.
228    ///
229    /// Note that all tabs in the array must use the same unit.
230    ///
231    /// A typical example:
232    ///
233    ///     100px 200px center:300px right:400px
234    ///
235    /// # Returns
236    ///
237    /// a newly allocated string
238    #[cfg(feature = "v1_50")]
239    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
240    #[doc(alias = "pango_tab_array_to_string")]
241    #[doc(alias = "to_string")]
242    pub fn to_str(&self) -> glib::GString {
243        unsafe {
244            from_glib_full(ffi::pango_tab_array_to_string(mut_override(
245                self.to_glib_none().0,
246            )))
247        }
248    }
249
250    /// Deserializes a [`TabArray`][crate::TabArray] from a string.
251    ///
252    /// This is the counterpart to [`to_str()`][Self::to_str()].
253    /// See that functions for details about the format.
254    /// ## `text`
255    /// a string
256    ///
257    /// # Returns
258    ///
259    /// a new [`TabArray`][crate::TabArray]
260    #[cfg(feature = "v1_50")]
261    #[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
262    #[doc(alias = "pango_tab_array_from_string")]
263    pub fn from_string(text: &str) -> Result<TabArray, glib::BoolError> {
264        unsafe {
265            Option::<_>::from_glib_full(ffi::pango_tab_array_from_string(text.to_glib_none().0))
266                .ok_or_else(|| glib::bool_error!("Can't parse a TabArray"))
267        }
268    }
269}
270
271#[cfg(feature = "v1_50")]
272#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
273impl std::fmt::Display for TabArray {
274    #[inline]
275    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
276        f.write_str(&self.to_str())
277    }
278}
279
280unsafe impl Send for TabArray {}
281unsafe impl Sync for TabArray {}