pango/auto/
layout_line.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 glib::translate::*;
6use pango_sys;
7use std::mem;
8use std::ptr;
9use Rectangle;
10
11glib_wrapper! {
12    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
13    pub struct LayoutLine(Shared<pango_sys::PangoLayoutLine>);
14
15    match fn {
16        ref => |ptr| pango_sys::pango_layout_line_ref(ptr),
17        unref => |ptr| pango_sys::pango_layout_line_unref(ptr),
18        get_type => || pango_sys::pango_layout_line_get_type(),
19    }
20}
21
22impl LayoutLine {
23    pub fn get_extents(&self) -> (Rectangle, Rectangle) {
24        unsafe {
25            let mut ink_rect = Rectangle::uninitialized();
26            let mut logical_rect = Rectangle::uninitialized();
27            pango_sys::pango_layout_line_get_extents(
28                self.to_glib_none().0,
29                ink_rect.to_glib_none_mut().0,
30                logical_rect.to_glib_none_mut().0,
31            );
32            (ink_rect, logical_rect)
33        }
34    }
35
36    pub fn get_pixel_extents(&self) -> (Rectangle, Rectangle) {
37        unsafe {
38            let mut ink_rect = Rectangle::uninitialized();
39            let mut logical_rect = Rectangle::uninitialized();
40            pango_sys::pango_layout_line_get_pixel_extents(
41                self.to_glib_none().0,
42                ink_rect.to_glib_none_mut().0,
43                logical_rect.to_glib_none_mut().0,
44            );
45            (ink_rect, logical_rect)
46        }
47    }
48
49    pub fn get_x_ranges(&self, start_index: i32, end_index: i32) -> Vec<i32> {
50        unsafe {
51            let mut ranges = ptr::null_mut();
52            let mut n_ranges = mem::uninitialized();
53            pango_sys::pango_layout_line_get_x_ranges(
54                self.to_glib_none().0,
55                start_index,
56                end_index,
57                &mut ranges,
58                &mut n_ranges,
59            );
60            FromGlibContainer::from_glib_full_num(ranges, n_ranges as usize)
61        }
62    }
63
64    pub fn index_to_x(&self, index_: i32, trailing: bool) -> i32 {
65        unsafe {
66            let mut x_pos = mem::uninitialized();
67            pango_sys::pango_layout_line_index_to_x(
68                self.to_glib_none().0,
69                index_,
70                trailing.to_glib(),
71                &mut x_pos,
72            );
73            x_pos
74        }
75    }
76
77    pub fn x_to_index(&self, x_pos: i32) -> Option<(i32, i32)> {
78        unsafe {
79            let mut index_ = mem::uninitialized();
80            let mut trailing = mem::uninitialized();
81            let ret = from_glib(pango_sys::pango_layout_line_x_to_index(
82                self.to_glib_none().0,
83                x_pos,
84                &mut index_,
85                &mut trailing,
86            ));
87            if ret {
88                Some((index_, trailing))
89            } else {
90                None
91            }
92        }
93    }
94}