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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::AttrType;
use crate::Attribute;
use glib::translate::*;
use std::mem;
#[cfg(any(feature = "v1_44", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_44")))]
glib::wrapper! {
/// A [`AttrIterator`][crate::AttrIterator] is used to iterate through a [`AttrList`][crate::AttrList].
///
/// A new iterator is created with [`AttrList::iterator()`][crate::AttrList::iterator()].
/// Once the iterator is created, it can be advanced through the style
/// changes in the text using [`next()`][Self::next()]. At each
/// style change, the range of the current style segment and the attributes
/// currently in effect can be queried.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct AttrIterator(Boxed<ffi::PangoAttrIterator>);
match fn {
copy => |ptr| ffi::pango_attr_iterator_copy(mut_override(ptr)),
free => |ptr| ffi::pango_attr_iterator_destroy(ptr),
type_ => || ffi::pango_attr_iterator_get_type(),
}
}
#[cfg(not(any(feature = "v1_44", feature = "dox")))]
glib::wrapper! {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct AttrIterator(Boxed<ffi::PangoAttrIterator>);
match fn {
copy => |ptr| ffi::pango_attr_iterator_copy(mut_override(ptr)),
free => |ptr| ffi::pango_attr_iterator_destroy(ptr),
}
}
impl AttrIterator {
/// Find the current attribute of a particular type
/// at the iterator location.
///
/// When multiple attributes of the same type overlap,
/// the attribute whose range starts closest to the
/// current location is used.
/// ## `type_`
/// the type of attribute to find
///
/// # Returns
///
/// the current
/// attribute of the given type, or [`None`] if no attribute
/// of that type applies to the current location.
#[doc(alias = "pango_attr_iterator_get")]
pub fn get(&mut self, type_: AttrType) -> Option<Attribute> {
unsafe {
from_glib_none(ffi::pango_attr_iterator_get(
self.to_glib_none_mut().0,
type_.into_glib(),
))
}
}
/// Gets a list of all attributes at the current position of the
/// iterator.
///
/// # Returns
///
///
/// a list of all attributes for the current range. To free
/// this value, call `Pango::Attribute::destroy()` on each
/// value and g_slist_free() on the list.
#[doc(alias = "pango_attr_iterator_get_attrs")]
#[doc(alias = "get_attrs")]
pub fn attrs(&mut self) -> Vec<Attribute> {
unsafe {
FromGlibPtrContainer::from_glib_full(ffi::pango_attr_iterator_get_attrs(
self.to_glib_none_mut().0,
))
}
}
/// Advance the iterator until the next change of style.
///
/// # Returns
///
/// [`false`] if the iterator is at the end
/// of the list, otherwise [`true`]
#[doc(alias = "pango_attr_iterator_next")]
pub fn next(&mut self) -> bool {
unsafe { from_glib(ffi::pango_attr_iterator_next(self.to_glib_none_mut().0)) }
}
/// Get the range of the current segment.
///
/// Note that the stored return values are signed, not unsigned
/// like the values in [`Attribute`][crate::Attribute]. To deal with this API
/// oversight, stored return values that wouldn't fit into
/// a signed integer are clamped to `G_MAXINT`.
///
/// # Returns
///
///
/// ## `start`
/// location to store the start of the range
///
/// ## `end`
/// location to store the end of the range
#[doc(alias = "pango_attr_iterator_range")]
pub fn range(&mut self) -> (i32, i32) {
unsafe {
let mut start = mem::MaybeUninit::uninit();
let mut end = mem::MaybeUninit::uninit();
ffi::pango_attr_iterator_range(
self.to_glib_none_mut().0,
start.as_mut_ptr(),
end.as_mut_ptr(),
);
let start = start.assume_init();
let end = end.assume_init();
(start, end)
}
}
}