1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::{TabAlign, TabArray};
use glib::{translate::*, Slice};
impl TabArray {
#[doc(alias = "pango_tab_array_get_tabs")]
#[doc(alias = "get_tabs")]
pub fn tabs(&self) -> (Vec<TabAlign>, Slice<i32>) {
let size = self.size() as usize;
unsafe {
let mut alignments = std::mem::MaybeUninit::uninit();
let mut locations = std::mem::MaybeUninit::uninit();
ffi::pango_tab_array_get_tabs(
mut_override(self.to_glib_none().0),
alignments.as_mut_ptr(),
locations.as_mut_ptr(),
);
let locations = Slice::from_glib_container_num_copy(locations.assume_init(), size);
let alignments = alignments.assume_init();
let mut alignments_vec = Vec::with_capacity(locations.len());
for i in 0..locations.len() {
alignments_vec.push(from_glib(*alignments.add(i)));
}
(alignments_vec, locations)
}
}
}
#[cfg(any(feature = "v1_50", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_50")))]
impl std::str::FromStr for TabArray {
type Err = glib::BoolError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::from_string(s)
}
}
#[cfg(test)]
mod tests {
use crate::{TabAlign, TabArray};
#[test]
fn tab_array_tabs() {
let mut array = TabArray::new(4, false);
for i in 0..4 {
array.set_tab(i, TabAlign::Left, i * 10);
}
let (alignments, locations) = array.tabs();
assert_eq!(alignments.len(), 4);
assert_eq!(locations.len(), 4);
for i in 0..alignments.len() {
assert_eq!(alignments[i], TabAlign::Left);
assert_eq!(locations[i], i as i32 * 10);
}
}
}