1use crate::{
6 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
7 TreeListRow, Widget,
8};
9use glib::{
10 prelude::*,
11 signal::{connect_raw, SignalHandlerId},
12 translate::*,
13};
14use std::boxed::Box as Box_;
15
16glib::wrapper! {
17 #[doc(alias = "GtkTreeExpander")]
18 pub struct TreeExpander(Object<ffi::GtkTreeExpander, ffi::GtkTreeExpanderClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
19
20 match fn {
21 type_ => || ffi::gtk_tree_expander_get_type(),
22 }
23}
24
25impl TreeExpander {
26 #[doc(alias = "gtk_tree_expander_new")]
27 pub fn new() -> TreeExpander {
28 assert_initialized_main_thread!();
29 unsafe { Widget::from_glib_none(ffi::gtk_tree_expander_new()).unsafe_cast() }
30 }
31
32 pub fn builder() -> TreeExpanderBuilder {
37 TreeExpanderBuilder::new()
38 }
39
40 #[doc(alias = "gtk_tree_expander_get_child")]
41 #[doc(alias = "get_child")]
42 pub fn child(&self) -> Option<Widget> {
43 unsafe { from_glib_none(ffi::gtk_tree_expander_get_child(self.to_glib_none().0)) }
44 }
45
46 #[cfg(feature = "v4_10")]
47 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
48 #[doc(alias = "gtk_tree_expander_get_hide_expander")]
49 #[doc(alias = "get_hide_expander")]
50 #[doc(alias = "hide-expander")]
51 pub fn hides_expander(&self) -> bool {
52 unsafe {
53 from_glib(ffi::gtk_tree_expander_get_hide_expander(
54 self.to_glib_none().0,
55 ))
56 }
57 }
58
59 #[cfg(feature = "v4_10")]
60 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
61 #[doc(alias = "gtk_tree_expander_get_indent_for_depth")]
62 #[doc(alias = "get_indent_for_depth")]
63 #[doc(alias = "indent-for-depth")]
64 pub fn is_indent_for_depth(&self) -> bool {
65 unsafe {
66 from_glib(ffi::gtk_tree_expander_get_indent_for_depth(
67 self.to_glib_none().0,
68 ))
69 }
70 }
71
72 #[cfg(feature = "v4_6")]
73 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
74 #[doc(alias = "gtk_tree_expander_get_indent_for_icon")]
75 #[doc(alias = "get_indent_for_icon")]
76 #[doc(alias = "indent-for-icon")]
77 pub fn is_indent_for_icon(&self) -> bool {
78 unsafe {
79 from_glib(ffi::gtk_tree_expander_get_indent_for_icon(
80 self.to_glib_none().0,
81 ))
82 }
83 }
84
85 #[doc(alias = "gtk_tree_expander_get_item")]
86 #[doc(alias = "get_item")]
87 pub fn item(&self) -> Option<glib::Object> {
88 unsafe { from_glib_full(ffi::gtk_tree_expander_get_item(self.to_glib_none().0)) }
89 }
90
91 #[doc(alias = "gtk_tree_expander_get_list_row")]
92 #[doc(alias = "get_list_row")]
93 #[doc(alias = "list-row")]
94 pub fn list_row(&self) -> Option<TreeListRow> {
95 unsafe { from_glib_none(ffi::gtk_tree_expander_get_list_row(self.to_glib_none().0)) }
96 }
97
98 #[doc(alias = "gtk_tree_expander_set_child")]
99 #[doc(alias = "child")]
100 pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
101 unsafe {
102 ffi::gtk_tree_expander_set_child(
103 self.to_glib_none().0,
104 child.map(|p| p.as_ref()).to_glib_none().0,
105 );
106 }
107 }
108
109 #[cfg(feature = "v4_10")]
110 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
111 #[doc(alias = "gtk_tree_expander_set_hide_expander")]
112 #[doc(alias = "hide-expander")]
113 pub fn set_hide_expander(&self, hide_expander: bool) {
114 unsafe {
115 ffi::gtk_tree_expander_set_hide_expander(
116 self.to_glib_none().0,
117 hide_expander.into_glib(),
118 );
119 }
120 }
121
122 #[cfg(feature = "v4_10")]
123 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
124 #[doc(alias = "gtk_tree_expander_set_indent_for_depth")]
125 #[doc(alias = "indent-for-depth")]
126 pub fn set_indent_for_depth(&self, indent_for_depth: bool) {
127 unsafe {
128 ffi::gtk_tree_expander_set_indent_for_depth(
129 self.to_glib_none().0,
130 indent_for_depth.into_glib(),
131 );
132 }
133 }
134
135 #[cfg(feature = "v4_6")]
136 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
137 #[doc(alias = "gtk_tree_expander_set_indent_for_icon")]
138 #[doc(alias = "indent-for-icon")]
139 pub fn set_indent_for_icon(&self, indent_for_icon: bool) {
140 unsafe {
141 ffi::gtk_tree_expander_set_indent_for_icon(
142 self.to_glib_none().0,
143 indent_for_icon.into_glib(),
144 );
145 }
146 }
147
148 #[doc(alias = "gtk_tree_expander_set_list_row")]
149 #[doc(alias = "list-row")]
150 pub fn set_list_row(&self, list_row: Option<&TreeListRow>) {
151 unsafe {
152 ffi::gtk_tree_expander_set_list_row(self.to_glib_none().0, list_row.to_glib_none().0);
153 }
154 }
155
156 #[doc(alias = "child")]
157 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
158 unsafe extern "C" fn notify_child_trampoline<F: Fn(&TreeExpander) + 'static>(
159 this: *mut ffi::GtkTreeExpander,
160 _param_spec: glib::ffi::gpointer,
161 f: glib::ffi::gpointer,
162 ) {
163 let f: &F = &*(f as *const F);
164 f(&from_glib_borrow(this))
165 }
166 unsafe {
167 let f: Box_<F> = Box_::new(f);
168 connect_raw(
169 self.as_ptr() as *mut _,
170 c"notify::child".as_ptr() as *const _,
171 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
172 notify_child_trampoline::<F> as *const (),
173 )),
174 Box_::into_raw(f),
175 )
176 }
177 }
178
179 #[cfg(feature = "v4_10")]
180 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
181 #[doc(alias = "hide-expander")]
182 pub fn connect_hide_expander_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
183 unsafe extern "C" fn notify_hide_expander_trampoline<F: Fn(&TreeExpander) + 'static>(
184 this: *mut ffi::GtkTreeExpander,
185 _param_spec: glib::ffi::gpointer,
186 f: glib::ffi::gpointer,
187 ) {
188 let f: &F = &*(f as *const F);
189 f(&from_glib_borrow(this))
190 }
191 unsafe {
192 let f: Box_<F> = Box_::new(f);
193 connect_raw(
194 self.as_ptr() as *mut _,
195 c"notify::hide-expander".as_ptr() as *const _,
196 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
197 notify_hide_expander_trampoline::<F> as *const (),
198 )),
199 Box_::into_raw(f),
200 )
201 }
202 }
203
204 #[cfg(feature = "v4_10")]
205 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
206 #[doc(alias = "indent-for-depth")]
207 pub fn connect_indent_for_depth_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
208 unsafe extern "C" fn notify_indent_for_depth_trampoline<F: Fn(&TreeExpander) + 'static>(
209 this: *mut ffi::GtkTreeExpander,
210 _param_spec: glib::ffi::gpointer,
211 f: glib::ffi::gpointer,
212 ) {
213 let f: &F = &*(f as *const F);
214 f(&from_glib_borrow(this))
215 }
216 unsafe {
217 let f: Box_<F> = Box_::new(f);
218 connect_raw(
219 self.as_ptr() as *mut _,
220 c"notify::indent-for-depth".as_ptr() as *const _,
221 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
222 notify_indent_for_depth_trampoline::<F> as *const (),
223 )),
224 Box_::into_raw(f),
225 )
226 }
227 }
228
229 #[cfg(feature = "v4_6")]
230 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
231 #[doc(alias = "indent-for-icon")]
232 pub fn connect_indent_for_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
233 unsafe extern "C" fn notify_indent_for_icon_trampoline<F: Fn(&TreeExpander) + 'static>(
234 this: *mut ffi::GtkTreeExpander,
235 _param_spec: glib::ffi::gpointer,
236 f: glib::ffi::gpointer,
237 ) {
238 let f: &F = &*(f as *const F);
239 f(&from_glib_borrow(this))
240 }
241 unsafe {
242 let f: Box_<F> = Box_::new(f);
243 connect_raw(
244 self.as_ptr() as *mut _,
245 c"notify::indent-for-icon".as_ptr() as *const _,
246 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
247 notify_indent_for_icon_trampoline::<F> as *const (),
248 )),
249 Box_::into_raw(f),
250 )
251 }
252 }
253
254 #[doc(alias = "item")]
255 pub fn connect_item_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
256 unsafe extern "C" fn notify_item_trampoline<F: Fn(&TreeExpander) + 'static>(
257 this: *mut ffi::GtkTreeExpander,
258 _param_spec: glib::ffi::gpointer,
259 f: glib::ffi::gpointer,
260 ) {
261 let f: &F = &*(f as *const F);
262 f(&from_glib_borrow(this))
263 }
264 unsafe {
265 let f: Box_<F> = Box_::new(f);
266 connect_raw(
267 self.as_ptr() as *mut _,
268 c"notify::item".as_ptr() as *const _,
269 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
270 notify_item_trampoline::<F> as *const (),
271 )),
272 Box_::into_raw(f),
273 )
274 }
275 }
276
277 #[doc(alias = "list-row")]
278 pub fn connect_list_row_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
279 unsafe extern "C" fn notify_list_row_trampoline<F: Fn(&TreeExpander) + 'static>(
280 this: *mut ffi::GtkTreeExpander,
281 _param_spec: glib::ffi::gpointer,
282 f: glib::ffi::gpointer,
283 ) {
284 let f: &F = &*(f as *const F);
285 f(&from_glib_borrow(this))
286 }
287 unsafe {
288 let f: Box_<F> = Box_::new(f);
289 connect_raw(
290 self.as_ptr() as *mut _,
291 c"notify::list-row".as_ptr() as *const _,
292 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
293 notify_list_row_trampoline::<F> as *const (),
294 )),
295 Box_::into_raw(f),
296 )
297 }
298 }
299}
300
301impl Default for TreeExpander {
302 fn default() -> Self {
303 Self::new()
304 }
305}
306
307#[must_use = "The builder must be built to be used"]
312pub struct TreeExpanderBuilder {
313 builder: glib::object::ObjectBuilder<'static, TreeExpander>,
314}
315
316impl TreeExpanderBuilder {
317 fn new() -> Self {
318 Self {
319 builder: glib::object::Object::builder(),
320 }
321 }
322
323 pub fn child(self, child: &impl IsA<Widget>) -> Self {
324 Self {
325 builder: self.builder.property("child", child.clone().upcast()),
326 }
327 }
328
329 #[cfg(feature = "v4_10")]
330 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
331 pub fn hide_expander(self, hide_expander: bool) -> Self {
332 Self {
333 builder: self.builder.property("hide-expander", hide_expander),
334 }
335 }
336
337 #[cfg(feature = "v4_10")]
338 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
339 pub fn indent_for_depth(self, indent_for_depth: bool) -> Self {
340 Self {
341 builder: self.builder.property("indent-for-depth", indent_for_depth),
342 }
343 }
344
345 #[cfg(feature = "v4_6")]
346 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
347 pub fn indent_for_icon(self, indent_for_icon: bool) -> Self {
348 Self {
349 builder: self.builder.property("indent-for-icon", indent_for_icon),
350 }
351 }
352
353 pub fn list_row(self, list_row: &TreeListRow) -> Self {
354 Self {
355 builder: self.builder.property("list-row", list_row.clone()),
356 }
357 }
358
359 pub fn can_focus(self, can_focus: bool) -> Self {
360 Self {
361 builder: self.builder.property("can-focus", can_focus),
362 }
363 }
364
365 pub fn can_target(self, can_target: bool) -> Self {
366 Self {
367 builder: self.builder.property("can-target", can_target),
368 }
369 }
370
371 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
372 Self {
373 builder: self.builder.property("css-classes", css_classes.into()),
374 }
375 }
376
377 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
378 Self {
379 builder: self.builder.property("css-name", css_name.into()),
380 }
381 }
382
383 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
384 Self {
385 builder: self.builder.property("cursor", cursor.clone()),
386 }
387 }
388
389 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
390 Self {
391 builder: self.builder.property("focus-on-click", focus_on_click),
392 }
393 }
394
395 pub fn focusable(self, focusable: bool) -> Self {
396 Self {
397 builder: self.builder.property("focusable", focusable),
398 }
399 }
400
401 pub fn halign(self, halign: Align) -> Self {
402 Self {
403 builder: self.builder.property("halign", halign),
404 }
405 }
406
407 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
408 Self {
409 builder: self.builder.property("has-tooltip", has_tooltip),
410 }
411 }
412
413 pub fn height_request(self, height_request: i32) -> Self {
414 Self {
415 builder: self.builder.property("height-request", height_request),
416 }
417 }
418
419 pub fn hexpand(self, hexpand: bool) -> Self {
420 Self {
421 builder: self.builder.property("hexpand", hexpand),
422 }
423 }
424
425 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
426 Self {
427 builder: self.builder.property("hexpand-set", hexpand_set),
428 }
429 }
430
431 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
432 Self {
433 builder: self
434 .builder
435 .property("layout-manager", layout_manager.clone().upcast()),
436 }
437 }
438
439 #[cfg(feature = "v4_18")]
440 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
441 pub fn limit_events(self, limit_events: bool) -> Self {
442 Self {
443 builder: self.builder.property("limit-events", limit_events),
444 }
445 }
446
447 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
448 Self {
449 builder: self.builder.property("margin-bottom", margin_bottom),
450 }
451 }
452
453 pub fn margin_end(self, margin_end: i32) -> Self {
454 Self {
455 builder: self.builder.property("margin-end", margin_end),
456 }
457 }
458
459 pub fn margin_start(self, margin_start: i32) -> Self {
460 Self {
461 builder: self.builder.property("margin-start", margin_start),
462 }
463 }
464
465 pub fn margin_top(self, margin_top: i32) -> Self {
466 Self {
467 builder: self.builder.property("margin-top", margin_top),
468 }
469 }
470
471 pub fn name(self, name: impl Into<glib::GString>) -> Self {
472 Self {
473 builder: self.builder.property("name", name.into()),
474 }
475 }
476
477 pub fn opacity(self, opacity: f64) -> Self {
478 Self {
479 builder: self.builder.property("opacity", opacity),
480 }
481 }
482
483 pub fn overflow(self, overflow: Overflow) -> Self {
484 Self {
485 builder: self.builder.property("overflow", overflow),
486 }
487 }
488
489 pub fn receives_default(self, receives_default: bool) -> Self {
490 Self {
491 builder: self.builder.property("receives-default", receives_default),
492 }
493 }
494
495 pub fn sensitive(self, sensitive: bool) -> Self {
496 Self {
497 builder: self.builder.property("sensitive", sensitive),
498 }
499 }
500
501 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
502 Self {
503 builder: self
504 .builder
505 .property("tooltip-markup", tooltip_markup.into()),
506 }
507 }
508
509 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
510 Self {
511 builder: self.builder.property("tooltip-text", tooltip_text.into()),
512 }
513 }
514
515 pub fn valign(self, valign: Align) -> Self {
516 Self {
517 builder: self.builder.property("valign", valign),
518 }
519 }
520
521 pub fn vexpand(self, vexpand: bool) -> Self {
522 Self {
523 builder: self.builder.property("vexpand", vexpand),
524 }
525 }
526
527 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
528 Self {
529 builder: self.builder.property("vexpand-set", vexpand_set),
530 }
531 }
532
533 pub fn visible(self, visible: bool) -> Self {
534 Self {
535 builder: self.builder.property("visible", visible),
536 }
537 }
538
539 pub fn width_request(self, width_request: i32) -> Self {
540 Self {
541 builder: self.builder.property("width-request", width_request),
542 }
543 }
544
545 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
546 Self {
547 builder: self.builder.property("accessible-role", accessible_role),
548 }
549 }
550
551 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
554 pub fn build(self) -> TreeExpander {
555 assert_initialized_main_thread!();
556 self.builder.build()
557 }
558}