1use crate::{ffi, Texture};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 #[doc(alias = "GdkCursor")]
10 pub struct Cursor(Object<ffi::GdkCursor>);
11
12 match fn {
13 type_ => || ffi::gdk_cursor_get_type(),
14 }
15}
16
17impl Cursor {
18 #[doc(alias = "gdk_cursor_new_from_name")]
19 #[doc(alias = "new_from_name")]
20 pub fn from_name(name: &str, fallback: Option<&Cursor>) -> Option<Cursor> {
21 assert_initialized_main_thread!();
22 unsafe {
23 from_glib_full(ffi::gdk_cursor_new_from_name(
24 name.to_glib_none().0,
25 fallback.to_glib_none().0,
26 ))
27 }
28 }
29
30 #[doc(alias = "gdk_cursor_new_from_texture")]
31 #[doc(alias = "new_from_texture")]
32 pub fn from_texture(
33 texture: &impl IsA<Texture>,
34 hotspot_x: i32,
35 hotspot_y: i32,
36 fallback: Option<&Cursor>,
37 ) -> Cursor {
38 skip_assert_initialized!();
39 unsafe {
40 from_glib_full(ffi::gdk_cursor_new_from_texture(
41 texture.as_ref().to_glib_none().0,
42 hotspot_x,
43 hotspot_y,
44 fallback.to_glib_none().0,
45 ))
46 }
47 }
48
49 pub fn builder() -> CursorBuilder {
54 CursorBuilder::new()
55 }
56
57 #[doc(alias = "gdk_cursor_get_fallback")]
58 #[doc(alias = "get_fallback")]
59 #[must_use]
60 pub fn fallback(&self) -> Option<Cursor> {
61 unsafe { from_glib_none(ffi::gdk_cursor_get_fallback(self.to_glib_none().0)) }
62 }
63
64 #[doc(alias = "gdk_cursor_get_hotspot_x")]
65 #[doc(alias = "get_hotspot_x")]
66 #[doc(alias = "hotspot-x")]
67 pub fn hotspot_x(&self) -> i32 {
68 unsafe { ffi::gdk_cursor_get_hotspot_x(self.to_glib_none().0) }
69 }
70
71 #[doc(alias = "gdk_cursor_get_hotspot_y")]
72 #[doc(alias = "get_hotspot_y")]
73 #[doc(alias = "hotspot-y")]
74 pub fn hotspot_y(&self) -> i32 {
75 unsafe { ffi::gdk_cursor_get_hotspot_y(self.to_glib_none().0) }
76 }
77
78 #[doc(alias = "gdk_cursor_get_name")]
79 #[doc(alias = "get_name")]
80 pub fn name(&self) -> Option<glib::GString> {
81 unsafe { from_glib_none(ffi::gdk_cursor_get_name(self.to_glib_none().0)) }
82 }
83
84 #[doc(alias = "gdk_cursor_get_texture")]
85 #[doc(alias = "get_texture")]
86 pub fn texture(&self) -> Option<Texture> {
87 unsafe { from_glib_none(ffi::gdk_cursor_get_texture(self.to_glib_none().0)) }
88 }
89}
90
91#[must_use = "The builder must be built to be used"]
96pub struct CursorBuilder {
97 builder: glib::object::ObjectBuilder<'static, Cursor>,
98}
99
100impl CursorBuilder {
101 fn new() -> Self {
102 Self {
103 builder: glib::object::Object::builder(),
104 }
105 }
106
107 pub fn fallback(self, fallback: &Cursor) -> Self {
108 Self {
109 builder: self.builder.property("fallback", fallback.clone()),
110 }
111 }
112
113 pub fn hotspot_x(self, hotspot_x: i32) -> Self {
114 Self {
115 builder: self.builder.property("hotspot-x", hotspot_x),
116 }
117 }
118
119 pub fn hotspot_y(self, hotspot_y: i32) -> Self {
120 Self {
121 builder: self.builder.property("hotspot-y", hotspot_y),
122 }
123 }
124
125 pub fn name(self, name: impl Into<glib::GString>) -> Self {
126 Self {
127 builder: self.builder.property("name", name.into()),
128 }
129 }
130
131 pub fn texture(self, texture: &impl IsA<Texture>) -> Self {
132 Self {
133 builder: self.builder.property("texture", texture.clone().upcast()),
134 }
135 }
136
137 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
140 pub fn build(self) -> Cursor {
141 assert_initialized_main_thread!();
142 self.builder.build()
143 }
144}