gdk/functions.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5#[repr(packed)]
6pub struct GRange(pub i32, pub i32);
7
8/// Obtains a clip region which contains the areas where the given
9/// ranges of text would be drawn. `x_origin` and `y_origin` are the top left
10/// position of the layout. `index_ranges`
11/// should contain ranges of bytes in the layout’s text. The clip
12/// region will include space to the left or right of the line (to the
13/// layout bounding box) if you have indexes above or below the indexes
14/// contained inside the line. This is to draw the selection all the way
15/// to the side of the layout. However, the clip region is in line coordinates,
16/// not layout coordinates.
17///
18/// Note that the regions returned correspond to logical extents of the text
19/// ranges, not ink extents. So the drawn line may in fact touch areas out of
20/// the clip region. The clip region is mainly useful for highlightling parts
21/// of text, such as when text is selected.
22/// ## `line`
23/// a [`pango::LayoutLine`][crate::pango::LayoutLine]
24/// ## `x_origin`
25/// X pixel where you intend to draw the layout line with this clip
26/// ## `y_origin`
27/// baseline pixel where you intend to draw the layout line with this clip
28/// ## `index_ranges`
29/// array of byte indexes into the layout,
30/// where even members of array are start indexes and odd elements
31/// are end indexes
32/// ## `n_ranges`
33/// number of ranges in `index_ranges`, i.e. half the size of `index_ranges`
34///
35/// # Returns
36///
37/// a clip region containing the given ranges
38#[doc(alias = "gdk_pango_layout_line_get_clip_region")]
39pub fn pango_layout_line_get_clip_region(
40 line: &pango::LayoutLine,
41 x_origin: i32,
42 y_origin: i32,
43 index_ranges: &[GRange],
44) -> Option<cairo::Region> {
45 assert_initialized_main_thread!();
46
47 let ptr: *const i32 = index_ranges.as_ptr() as _;
48 unsafe {
49 from_glib_full(ffi::gdk_pango_layout_line_get_clip_region(
50 line.to_glib_none().0,
51 x_origin,
52 y_origin,
53 mut_override(ptr),
54 index_ranges.len() as i32,
55 ))
56 }
57}
58
59#[doc(alias = "gdk_pango_layout_get_clip_region")]
60pub fn pango_layout_get_clip_region(
61 layout: &pango::Layout,
62 x_origin: i32,
63 y_origin: i32,
64 index_ranges: &[GRange],
65) -> Option<cairo::Region> {
66 assert_initialized_main_thread!();
67
68 let ptr: *const i32 = index_ranges.as_ptr() as _;
69 unsafe {
70 from_glib_full(ffi::gdk_pango_layout_get_clip_region(
71 layout.to_glib_none().0,
72 x_origin,
73 y_origin,
74 ptr,
75 index_ranges.len() as i32,
76 ))
77 }
78}
79
80#[doc(alias = "gdk_setting_get")]
81pub fn setting_get(name: &str) -> Option<glib::Value> {
82 assert_initialized_main_thread!();
83 unsafe {
84 let mut value = glib::Value::uninitialized();
85 let done: bool = from_glib(ffi::gdk_setting_get(
86 name.to_glib_none().0,
87 value.to_glib_none_mut().0,
88 ));
89 if done {
90 Some(value)
91 } else {
92 None
93 }
94 }
95}
96
97#[doc(alias = "gdk_property_change")]
98pub fn property_change(
99 window: &super::Window,
100 property: &super::Atom,
101 type_: &super::Atom,
102 format: i32,
103 mode: super::PropMode,
104 data: super::ChangeData,
105) {
106 skip_assert_initialized!();
107 let nelements = data.len();
108 unsafe {
109 ffi::gdk_property_change(
110 window.to_glib_none().0,
111 property.to_glib_none().0,
112 type_.to_glib_none().0,
113 format,
114 mode.into_glib(),
115 data.to_glib(),
116 nelements as i32,
117 );
118 }
119}