pango/auto/item.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;
6#[cfg(feature = "v1_44")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
8use crate::AttrIterator;
9use glib::translate::*;
10
11glib::wrapper! {
12 /// The [`Item`][crate::Item] structure stores information about a segment of text.
13 ///
14 /// You typically obtain `PangoItems` by itemizing a piece of text
15 /// with [`itemize()`][crate::itemize()].
16 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
17 pub struct Item(Boxed<ffi::PangoItem>);
18
19 match fn {
20 copy => |ptr| ffi::pango_item_copy(mut_override(ptr)),
21 free => |ptr| ffi::pango_item_free(ptr),
22 type_ => || ffi::pango_item_get_type(),
23 }
24}
25
26impl Item {
27 /// Creates a new [`Item`][crate::Item] structure initialized to default values.
28 ///
29 /// # Returns
30 ///
31 /// the newly allocated [`Item`][crate::Item], which should
32 /// be freed with `Pango::Item::free()`.
33 #[doc(alias = "pango_item_new")]
34 pub fn new() -> Item {
35 unsafe { from_glib_full(ffi::pango_item_new()) }
36 }
37
38 /// Add attributes to a [`Item`][crate::Item].
39 ///
40 /// The idea is that you have attributes that don't affect itemization,
41 /// such as font features, so you filter them out using
42 /// [`AttrList::filter()`][crate::AttrList::filter()], itemize your text, then reapply the
43 /// attributes to the resulting items using this function.
44 ///
45 /// The @iter should be positioned before the range of the item,
46 /// and will be advanced past it. This function is meant to be called
47 /// in a loop over the items resulting from itemization, while passing
48 /// the iter to each call.
49 /// ## `iter`
50 /// a [`AttrIterator`][crate::AttrIterator]
51 #[cfg(feature = "v1_44")]
52 #[cfg_attr(docsrs, doc(cfg(feature = "v1_44")))]
53 #[doc(alias = "pango_item_apply_attrs")]
54 pub fn apply_attrs(&mut self, iter: &mut AttrIterator) {
55 unsafe {
56 ffi::pango_item_apply_attrs(self.to_glib_none_mut().0, iter.to_glib_none_mut().0);
57 }
58 }
59
60 /// Returns the character offset of the item from the beginning
61 /// of the itemized text.
62 ///
63 /// If the item has not been obtained from Pango's itemization
64 /// machinery, then the character offset is not available. In
65 /// that case, this function returns -1.
66 ///
67 /// # Returns
68 ///
69 /// the character offset of the item from the beginning
70 /// of the itemized text, or -1
71 #[cfg(feature = "v1_54")]
72 #[cfg_attr(docsrs, doc(cfg(feature = "v1_54")))]
73 #[doc(alias = "pango_item_get_char_offset")]
74 #[doc(alias = "get_char_offset")]
75 pub fn char_offset(&self) -> i32 {
76 unsafe { ffi::pango_item_get_char_offset(mut_override(self.to_glib_none().0)) }
77 }
78
79 /// Modifies @self to cover only the text after @split_index, and
80 /// returns a new item that covers the text before @split_index that
81 /// used to be in @self.
82 ///
83 /// You can think of @split_index as the length of the returned item.
84 /// @split_index may not be 0, and it may not be greater than or equal
85 /// to the length of @self (that is, there must be at least one byte
86 /// assigned to each item, you can't create a zero-length item).
87 /// @split_offset is the length of the first item in chars, and must be
88 /// provided because the text used to generate the item isn't available,
89 /// so `pango_item_split()` can't count the char length of the split items
90 /// itself.
91 /// ## `split_index`
92 /// byte index of position to split item, relative to the
93 /// start of the item
94 /// ## `split_offset`
95 /// number of chars between start of @self and @split_index
96 ///
97 /// # Returns
98 ///
99 /// new item representing text before @split_index, which
100 /// should be freed with `Pango::Item::free()`.
101 #[doc(alias = "pango_item_split")]
102 #[must_use]
103 pub fn split(&mut self, split_index: i32, split_offset: i32) -> Item {
104 unsafe {
105 from_glib_full(ffi::pango_item_split(
106 self.to_glib_none_mut().0,
107 split_index,
108 split_offset,
109 ))
110 }
111 }
112}
113
114impl Default for Item {
115 fn default() -> Self {
116 Self::new()
117 }
118}