1use crate::{
6 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Overflow,
7 Widget,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "GtkExpander")]
19 pub struct Expander(Object<ffi::GtkExpander>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
20
21 match fn {
22 type_ => || ffi::gtk_expander_get_type(),
23 }
24}
25
26impl Expander {
27 #[doc(alias = "gtk_expander_new")]
28 pub fn new(label: Option<&str>) -> Expander {
29 assert_initialized_main_thread!();
30 unsafe {
31 Widget::from_glib_none(ffi::gtk_expander_new(label.to_glib_none().0)).unsafe_cast()
32 }
33 }
34
35 #[doc(alias = "gtk_expander_new_with_mnemonic")]
36 #[doc(alias = "new_with_mnemonic")]
37 pub fn with_mnemonic(label: &str) -> Expander {
38 assert_initialized_main_thread!();
39 unsafe {
40 Widget::from_glib_none(ffi::gtk_expander_new_with_mnemonic(label.to_glib_none().0))
41 .unsafe_cast()
42 }
43 }
44
45 pub fn builder() -> ExpanderBuilder {
50 ExpanderBuilder::new()
51 }
52
53 #[doc(alias = "gtk_expander_get_child")]
54 #[doc(alias = "get_child")]
55 pub fn child(&self) -> Option<Widget> {
56 unsafe { from_glib_none(ffi::gtk_expander_get_child(self.to_glib_none().0)) }
57 }
58
59 #[doc(alias = "gtk_expander_get_expanded")]
60 #[doc(alias = "get_expanded")]
61 #[doc(alias = "expanded")]
62 pub fn is_expanded(&self) -> bool {
63 unsafe { from_glib(ffi::gtk_expander_get_expanded(self.to_glib_none().0)) }
64 }
65
66 #[doc(alias = "gtk_expander_get_label")]
67 #[doc(alias = "get_label")]
68 pub fn label(&self) -> Option<glib::GString> {
69 unsafe { from_glib_none(ffi::gtk_expander_get_label(self.to_glib_none().0)) }
70 }
71
72 #[doc(alias = "gtk_expander_get_label_widget")]
73 #[doc(alias = "get_label_widget")]
74 #[doc(alias = "label-widget")]
75 pub fn label_widget(&self) -> Option<Widget> {
76 unsafe { from_glib_none(ffi::gtk_expander_get_label_widget(self.to_glib_none().0)) }
77 }
78
79 #[doc(alias = "gtk_expander_get_resize_toplevel")]
80 #[doc(alias = "get_resize_toplevel")]
81 #[doc(alias = "resize-toplevel")]
82 pub fn resizes_toplevel(&self) -> bool {
83 unsafe { from_glib(ffi::gtk_expander_get_resize_toplevel(self.to_glib_none().0)) }
84 }
85
86 #[doc(alias = "gtk_expander_get_use_markup")]
87 #[doc(alias = "get_use_markup")]
88 #[doc(alias = "use-markup")]
89 pub fn uses_markup(&self) -> bool {
90 unsafe { from_glib(ffi::gtk_expander_get_use_markup(self.to_glib_none().0)) }
91 }
92
93 #[doc(alias = "gtk_expander_get_use_underline")]
94 #[doc(alias = "get_use_underline")]
95 #[doc(alias = "use-underline")]
96 pub fn uses_underline(&self) -> bool {
97 unsafe { from_glib(ffi::gtk_expander_get_use_underline(self.to_glib_none().0)) }
98 }
99
100 #[doc(alias = "gtk_expander_set_child")]
101 #[doc(alias = "child")]
102 pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
103 unsafe {
104 ffi::gtk_expander_set_child(
105 self.to_glib_none().0,
106 child.map(|p| p.as_ref()).to_glib_none().0,
107 );
108 }
109 }
110
111 #[doc(alias = "gtk_expander_set_expanded")]
112 #[doc(alias = "expanded")]
113 pub fn set_expanded(&self, expanded: bool) {
114 unsafe {
115 ffi::gtk_expander_set_expanded(self.to_glib_none().0, expanded.into_glib());
116 }
117 }
118
119 #[doc(alias = "gtk_expander_set_label")]
120 #[doc(alias = "label")]
121 pub fn set_label(&self, label: Option<&str>) {
122 unsafe {
123 ffi::gtk_expander_set_label(self.to_glib_none().0, label.to_glib_none().0);
124 }
125 }
126
127 #[doc(alias = "gtk_expander_set_label_widget")]
128 #[doc(alias = "label-widget")]
129 pub fn set_label_widget(&self, label_widget: Option<&impl IsA<Widget>>) {
130 unsafe {
131 ffi::gtk_expander_set_label_widget(
132 self.to_glib_none().0,
133 label_widget.map(|p| p.as_ref()).to_glib_none().0,
134 );
135 }
136 }
137
138 #[doc(alias = "gtk_expander_set_resize_toplevel")]
139 #[doc(alias = "resize-toplevel")]
140 pub fn set_resize_toplevel(&self, resize_toplevel: bool) {
141 unsafe {
142 ffi::gtk_expander_set_resize_toplevel(
143 self.to_glib_none().0,
144 resize_toplevel.into_glib(),
145 );
146 }
147 }
148
149 #[doc(alias = "gtk_expander_set_use_markup")]
150 #[doc(alias = "use-markup")]
151 pub fn set_use_markup(&self, use_markup: bool) {
152 unsafe {
153 ffi::gtk_expander_set_use_markup(self.to_glib_none().0, use_markup.into_glib());
154 }
155 }
156
157 #[doc(alias = "gtk_expander_set_use_underline")]
158 #[doc(alias = "use-underline")]
159 pub fn set_use_underline(&self, use_underline: bool) {
160 unsafe {
161 ffi::gtk_expander_set_use_underline(self.to_glib_none().0, use_underline.into_glib());
162 }
163 }
164
165 #[doc(alias = "activate")]
166 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
167 unsafe extern "C" fn activate_trampoline<F: Fn(&Expander) + 'static>(
168 this: *mut ffi::GtkExpander,
169 f: glib::ffi::gpointer,
170 ) {
171 let f: &F = &*(f as *const F);
172 f(&from_glib_borrow(this))
173 }
174 unsafe {
175 let f: Box_<F> = Box_::new(f);
176 connect_raw(
177 self.as_ptr() as *mut _,
178 c"activate".as_ptr() as *const _,
179 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
180 activate_trampoline::<F> as *const (),
181 )),
182 Box_::into_raw(f),
183 )
184 }
185 }
186
187 pub fn emit_activate(&self) {
188 self.emit_by_name::<()>("activate", &[]);
189 }
190
191 #[doc(alias = "child")]
192 pub fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
193 unsafe extern "C" fn notify_child_trampoline<F: Fn(&Expander) + 'static>(
194 this: *mut ffi::GtkExpander,
195 _param_spec: glib::ffi::gpointer,
196 f: glib::ffi::gpointer,
197 ) {
198 let f: &F = &*(f as *const F);
199 f(&from_glib_borrow(this))
200 }
201 unsafe {
202 let f: Box_<F> = Box_::new(f);
203 connect_raw(
204 self.as_ptr() as *mut _,
205 c"notify::child".as_ptr() as *const _,
206 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
207 notify_child_trampoline::<F> as *const (),
208 )),
209 Box_::into_raw(f),
210 )
211 }
212 }
213
214 #[doc(alias = "expanded")]
215 pub fn connect_expanded_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
216 unsafe extern "C" fn notify_expanded_trampoline<F: Fn(&Expander) + 'static>(
217 this: *mut ffi::GtkExpander,
218 _param_spec: glib::ffi::gpointer,
219 f: glib::ffi::gpointer,
220 ) {
221 let f: &F = &*(f as *const F);
222 f(&from_glib_borrow(this))
223 }
224 unsafe {
225 let f: Box_<F> = Box_::new(f);
226 connect_raw(
227 self.as_ptr() as *mut _,
228 c"notify::expanded".as_ptr() as *const _,
229 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
230 notify_expanded_trampoline::<F> as *const (),
231 )),
232 Box_::into_raw(f),
233 )
234 }
235 }
236
237 #[doc(alias = "label")]
238 pub fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
239 unsafe extern "C" fn notify_label_trampoline<F: Fn(&Expander) + 'static>(
240 this: *mut ffi::GtkExpander,
241 _param_spec: glib::ffi::gpointer,
242 f: glib::ffi::gpointer,
243 ) {
244 let f: &F = &*(f as *const F);
245 f(&from_glib_borrow(this))
246 }
247 unsafe {
248 let f: Box_<F> = Box_::new(f);
249 connect_raw(
250 self.as_ptr() as *mut _,
251 c"notify::label".as_ptr() as *const _,
252 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
253 notify_label_trampoline::<F> as *const (),
254 )),
255 Box_::into_raw(f),
256 )
257 }
258 }
259
260 #[doc(alias = "label-widget")]
261 pub fn connect_label_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
262 unsafe extern "C" fn notify_label_widget_trampoline<F: Fn(&Expander) + 'static>(
263 this: *mut ffi::GtkExpander,
264 _param_spec: glib::ffi::gpointer,
265 f: glib::ffi::gpointer,
266 ) {
267 let f: &F = &*(f as *const F);
268 f(&from_glib_borrow(this))
269 }
270 unsafe {
271 let f: Box_<F> = Box_::new(f);
272 connect_raw(
273 self.as_ptr() as *mut _,
274 c"notify::label-widget".as_ptr() as *const _,
275 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
276 notify_label_widget_trampoline::<F> as *const (),
277 )),
278 Box_::into_raw(f),
279 )
280 }
281 }
282
283 #[doc(alias = "resize-toplevel")]
284 pub fn connect_resize_toplevel_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
285 unsafe extern "C" fn notify_resize_toplevel_trampoline<F: Fn(&Expander) + 'static>(
286 this: *mut ffi::GtkExpander,
287 _param_spec: glib::ffi::gpointer,
288 f: glib::ffi::gpointer,
289 ) {
290 let f: &F = &*(f as *const F);
291 f(&from_glib_borrow(this))
292 }
293 unsafe {
294 let f: Box_<F> = Box_::new(f);
295 connect_raw(
296 self.as_ptr() as *mut _,
297 c"notify::resize-toplevel".as_ptr() as *const _,
298 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
299 notify_resize_toplevel_trampoline::<F> as *const (),
300 )),
301 Box_::into_raw(f),
302 )
303 }
304 }
305
306 #[doc(alias = "use-markup")]
307 pub fn connect_use_markup_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
308 unsafe extern "C" fn notify_use_markup_trampoline<F: Fn(&Expander) + 'static>(
309 this: *mut ffi::GtkExpander,
310 _param_spec: glib::ffi::gpointer,
311 f: glib::ffi::gpointer,
312 ) {
313 let f: &F = &*(f as *const F);
314 f(&from_glib_borrow(this))
315 }
316 unsafe {
317 let f: Box_<F> = Box_::new(f);
318 connect_raw(
319 self.as_ptr() as *mut _,
320 c"notify::use-markup".as_ptr() as *const _,
321 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
322 notify_use_markup_trampoline::<F> as *const (),
323 )),
324 Box_::into_raw(f),
325 )
326 }
327 }
328
329 #[doc(alias = "use-underline")]
330 pub fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
331 unsafe extern "C" fn notify_use_underline_trampoline<F: Fn(&Expander) + 'static>(
332 this: *mut ffi::GtkExpander,
333 _param_spec: glib::ffi::gpointer,
334 f: glib::ffi::gpointer,
335 ) {
336 let f: &F = &*(f as *const F);
337 f(&from_glib_borrow(this))
338 }
339 unsafe {
340 let f: Box_<F> = Box_::new(f);
341 connect_raw(
342 self.as_ptr() as *mut _,
343 c"notify::use-underline".as_ptr() as *const _,
344 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
345 notify_use_underline_trampoline::<F> as *const (),
346 )),
347 Box_::into_raw(f),
348 )
349 }
350 }
351}
352
353impl Default for Expander {
354 fn default() -> Self {
355 glib::object::Object::new::<Self>()
356 }
357}
358
359#[must_use = "The builder must be built to be used"]
364pub struct ExpanderBuilder {
365 builder: glib::object::ObjectBuilder<'static, Expander>,
366}
367
368impl ExpanderBuilder {
369 fn new() -> Self {
370 Self {
371 builder: glib::object::Object::builder(),
372 }
373 }
374
375 pub fn child(self, child: &impl IsA<Widget>) -> Self {
376 Self {
377 builder: self.builder.property("child", child.clone().upcast()),
378 }
379 }
380
381 pub fn expanded(self, expanded: bool) -> Self {
382 Self {
383 builder: self.builder.property("expanded", expanded),
384 }
385 }
386
387 pub fn label(self, label: impl Into<glib::GString>) -> Self {
388 Self {
389 builder: self.builder.property("label", label.into()),
390 }
391 }
392
393 pub fn label_widget(self, label_widget: &impl IsA<Widget>) -> Self {
394 Self {
395 builder: self
396 .builder
397 .property("label-widget", label_widget.clone().upcast()),
398 }
399 }
400
401 pub fn resize_toplevel(self, resize_toplevel: bool) -> Self {
402 Self {
403 builder: self.builder.property("resize-toplevel", resize_toplevel),
404 }
405 }
406
407 pub fn use_markup(self, use_markup: bool) -> Self {
408 Self {
409 builder: self.builder.property("use-markup", use_markup),
410 }
411 }
412
413 pub fn use_underline(self, use_underline: bool) -> Self {
414 Self {
415 builder: self.builder.property("use-underline", use_underline),
416 }
417 }
418
419 pub fn can_focus(self, can_focus: bool) -> Self {
420 Self {
421 builder: self.builder.property("can-focus", can_focus),
422 }
423 }
424
425 pub fn can_target(self, can_target: bool) -> Self {
426 Self {
427 builder: self.builder.property("can-target", can_target),
428 }
429 }
430
431 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
432 Self {
433 builder: self.builder.property("css-classes", css_classes.into()),
434 }
435 }
436
437 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
438 Self {
439 builder: self.builder.property("css-name", css_name.into()),
440 }
441 }
442
443 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
444 Self {
445 builder: self.builder.property("cursor", cursor.clone()),
446 }
447 }
448
449 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
450 Self {
451 builder: self.builder.property("focus-on-click", focus_on_click),
452 }
453 }
454
455 pub fn focusable(self, focusable: bool) -> Self {
456 Self {
457 builder: self.builder.property("focusable", focusable),
458 }
459 }
460
461 pub fn halign(self, halign: Align) -> Self {
462 Self {
463 builder: self.builder.property("halign", halign),
464 }
465 }
466
467 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
468 Self {
469 builder: self.builder.property("has-tooltip", has_tooltip),
470 }
471 }
472
473 pub fn height_request(self, height_request: i32) -> Self {
474 Self {
475 builder: self.builder.property("height-request", height_request),
476 }
477 }
478
479 pub fn hexpand(self, hexpand: bool) -> Self {
480 Self {
481 builder: self.builder.property("hexpand", hexpand),
482 }
483 }
484
485 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
486 Self {
487 builder: self.builder.property("hexpand-set", hexpand_set),
488 }
489 }
490
491 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
492 Self {
493 builder: self
494 .builder
495 .property("layout-manager", layout_manager.clone().upcast()),
496 }
497 }
498
499 #[cfg(feature = "v4_18")]
500 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
501 pub fn limit_events(self, limit_events: bool) -> Self {
502 Self {
503 builder: self.builder.property("limit-events", limit_events),
504 }
505 }
506
507 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
508 Self {
509 builder: self.builder.property("margin-bottom", margin_bottom),
510 }
511 }
512
513 pub fn margin_end(self, margin_end: i32) -> Self {
514 Self {
515 builder: self.builder.property("margin-end", margin_end),
516 }
517 }
518
519 pub fn margin_start(self, margin_start: i32) -> Self {
520 Self {
521 builder: self.builder.property("margin-start", margin_start),
522 }
523 }
524
525 pub fn margin_top(self, margin_top: i32) -> Self {
526 Self {
527 builder: self.builder.property("margin-top", margin_top),
528 }
529 }
530
531 pub fn name(self, name: impl Into<glib::GString>) -> Self {
532 Self {
533 builder: self.builder.property("name", name.into()),
534 }
535 }
536
537 pub fn opacity(self, opacity: f64) -> Self {
538 Self {
539 builder: self.builder.property("opacity", opacity),
540 }
541 }
542
543 pub fn overflow(self, overflow: Overflow) -> Self {
544 Self {
545 builder: self.builder.property("overflow", overflow),
546 }
547 }
548
549 pub fn receives_default(self, receives_default: bool) -> Self {
550 Self {
551 builder: self.builder.property("receives-default", receives_default),
552 }
553 }
554
555 pub fn sensitive(self, sensitive: bool) -> Self {
556 Self {
557 builder: self.builder.property("sensitive", sensitive),
558 }
559 }
560
561 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
562 Self {
563 builder: self
564 .builder
565 .property("tooltip-markup", tooltip_markup.into()),
566 }
567 }
568
569 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
570 Self {
571 builder: self.builder.property("tooltip-text", tooltip_text.into()),
572 }
573 }
574
575 pub fn valign(self, valign: Align) -> Self {
576 Self {
577 builder: self.builder.property("valign", valign),
578 }
579 }
580
581 pub fn vexpand(self, vexpand: bool) -> Self {
582 Self {
583 builder: self.builder.property("vexpand", vexpand),
584 }
585 }
586
587 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
588 Self {
589 builder: self.builder.property("vexpand-set", vexpand_set),
590 }
591 }
592
593 pub fn visible(self, visible: bool) -> Self {
594 Self {
595 builder: self.builder.property("visible", visible),
596 }
597 }
598
599 pub fn width_request(self, width_request: i32) -> Self {
600 Self {
601 builder: self.builder.property("width-request", width_request),
602 }
603 }
604
605 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
606 Self {
607 builder: self.builder.property("accessible-role", accessible_role),
608 }
609 }
610
611 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
614 pub fn build(self) -> Expander {
615 assert_initialized_main_thread!();
616 self.builder.build()
617 }
618}