gtk4/auto/
event_controller_focus.rs1use crate::{ffi, EventController, PropagationLimit, PropagationPhase};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "GtkEventControllerFocus")]
16 pub struct EventControllerFocus(Object<ffi::GtkEventControllerFocus, ffi::GtkEventControllerFocusClass>) @extends EventController;
17
18 match fn {
19 type_ => || ffi::gtk_event_controller_focus_get_type(),
20 }
21}
22
23impl EventControllerFocus {
24 #[doc(alias = "gtk_event_controller_focus_new")]
25 pub fn new() -> EventControllerFocus {
26 assert_initialized_main_thread!();
27 unsafe {
28 EventController::from_glib_full(ffi::gtk_event_controller_focus_new()).unsafe_cast()
29 }
30 }
31
32 pub fn builder() -> EventControllerFocusBuilder {
37 EventControllerFocusBuilder::new()
38 }
39
40 #[doc(alias = "gtk_event_controller_focus_contains_focus")]
41 #[doc(alias = "contains-focus")]
42 pub fn contains_focus(&self) -> bool {
43 unsafe {
44 from_glib(ffi::gtk_event_controller_focus_contains_focus(
45 self.to_glib_none().0,
46 ))
47 }
48 }
49
50 #[doc(alias = "gtk_event_controller_focus_is_focus")]
51 #[doc(alias = "is-focus")]
52 pub fn is_focus(&self) -> bool {
53 unsafe {
54 from_glib(ffi::gtk_event_controller_focus_is_focus(
55 self.to_glib_none().0,
56 ))
57 }
58 }
59
60 #[doc(alias = "enter")]
61 pub fn connect_enter<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
62 unsafe extern "C" fn enter_trampoline<F: Fn(&EventControllerFocus) + 'static>(
63 this: *mut ffi::GtkEventControllerFocus,
64 f: glib::ffi::gpointer,
65 ) {
66 let f: &F = &*(f as *const F);
67 f(&from_glib_borrow(this))
68 }
69 unsafe {
70 let f: Box_<F> = Box_::new(f);
71 connect_raw(
72 self.as_ptr() as *mut _,
73 c"enter".as_ptr() as *const _,
74 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
75 enter_trampoline::<F> as *const (),
76 )),
77 Box_::into_raw(f),
78 )
79 }
80 }
81
82 #[doc(alias = "leave")]
83 pub fn connect_leave<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
84 unsafe extern "C" fn leave_trampoline<F: Fn(&EventControllerFocus) + 'static>(
85 this: *mut ffi::GtkEventControllerFocus,
86 f: glib::ffi::gpointer,
87 ) {
88 let f: &F = &*(f as *const F);
89 f(&from_glib_borrow(this))
90 }
91 unsafe {
92 let f: Box_<F> = Box_::new(f);
93 connect_raw(
94 self.as_ptr() as *mut _,
95 c"leave".as_ptr() as *const _,
96 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
97 leave_trampoline::<F> as *const (),
98 )),
99 Box_::into_raw(f),
100 )
101 }
102 }
103
104 #[doc(alias = "contains-focus")]
105 pub fn connect_contains_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
106 unsafe extern "C" fn notify_contains_focus_trampoline<
107 F: Fn(&EventControllerFocus) + 'static,
108 >(
109 this: *mut ffi::GtkEventControllerFocus,
110 _param_spec: glib::ffi::gpointer,
111 f: glib::ffi::gpointer,
112 ) {
113 let f: &F = &*(f as *const F);
114 f(&from_glib_borrow(this))
115 }
116 unsafe {
117 let f: Box_<F> = Box_::new(f);
118 connect_raw(
119 self.as_ptr() as *mut _,
120 c"notify::contains-focus".as_ptr() as *const _,
121 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
122 notify_contains_focus_trampoline::<F> as *const (),
123 )),
124 Box_::into_raw(f),
125 )
126 }
127 }
128
129 #[doc(alias = "is-focus")]
130 pub fn connect_is_focus_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
131 unsafe extern "C" fn notify_is_focus_trampoline<F: Fn(&EventControllerFocus) + 'static>(
132 this: *mut ffi::GtkEventControllerFocus,
133 _param_spec: glib::ffi::gpointer,
134 f: glib::ffi::gpointer,
135 ) {
136 let f: &F = &*(f as *const F);
137 f(&from_glib_borrow(this))
138 }
139 unsafe {
140 let f: Box_<F> = Box_::new(f);
141 connect_raw(
142 self.as_ptr() as *mut _,
143 c"notify::is-focus".as_ptr() as *const _,
144 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
145 notify_is_focus_trampoline::<F> as *const (),
146 )),
147 Box_::into_raw(f),
148 )
149 }
150 }
151}
152
153impl Default for EventControllerFocus {
154 fn default() -> Self {
155 Self::new()
156 }
157}
158
159#[must_use = "The builder must be built to be used"]
164pub struct EventControllerFocusBuilder {
165 builder: glib::object::ObjectBuilder<'static, EventControllerFocus>,
166}
167
168impl EventControllerFocusBuilder {
169 fn new() -> Self {
170 Self {
171 builder: glib::object::Object::builder(),
172 }
173 }
174
175 pub fn name(self, name: impl Into<glib::GString>) -> Self {
176 Self {
177 builder: self.builder.property("name", name.into()),
178 }
179 }
180
181 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
182 Self {
183 builder: self
184 .builder
185 .property("propagation-limit", propagation_limit),
186 }
187 }
188
189 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
190 Self {
191 builder: self
192 .builder
193 .property("propagation-phase", propagation_phase),
194 }
195 }
196
197 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
200 pub fn build(self) -> EventControllerFocus {
201 assert_initialized_main_thread!();
202 self.builder.build()
203 }
204}