gtk4/auto/
check_button.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6    ffi, Accessible, AccessibleRole, Actionable, Align, Buildable, ConstraintTarget, LayoutManager,
7    Overflow, 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 = "GtkCheckButton")]
19    pub struct CheckButton(Object<ffi::GtkCheckButton, ffi::GtkCheckButtonClass>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Actionable;
20
21    match fn {
22        type_ => || ffi::gtk_check_button_get_type(),
23    }
24}
25
26impl CheckButton {
27    pub const NONE: Option<&'static CheckButton> = None;
28
29    #[doc(alias = "gtk_check_button_new")]
30    pub fn new() -> CheckButton {
31        assert_initialized_main_thread!();
32        unsafe { Widget::from_glib_none(ffi::gtk_check_button_new()).unsafe_cast() }
33    }
34
35    #[doc(alias = "gtk_check_button_new_with_label")]
36    #[doc(alias = "new_with_label")]
37    pub fn with_label(label: &str) -> CheckButton {
38        assert_initialized_main_thread!();
39        unsafe {
40            Widget::from_glib_none(ffi::gtk_check_button_new_with_label(label.to_glib_none().0))
41                .unsafe_cast()
42        }
43    }
44
45    #[doc(alias = "gtk_check_button_new_with_mnemonic")]
46    #[doc(alias = "new_with_mnemonic")]
47    pub fn with_mnemonic(label: &str) -> CheckButton {
48        assert_initialized_main_thread!();
49        unsafe {
50            Widget::from_glib_none(ffi::gtk_check_button_new_with_mnemonic(
51                label.to_glib_none().0,
52            ))
53            .unsafe_cast()
54        }
55    }
56
57    // rustdoc-stripper-ignore-next
58    /// Creates a new builder-pattern struct instance to construct [`CheckButton`] objects.
59    ///
60    /// This method returns an instance of [`CheckButtonBuilder`](crate::builders::CheckButtonBuilder) which can be used to create [`CheckButton`] objects.
61    pub fn builder() -> CheckButtonBuilder {
62        CheckButtonBuilder::new()
63    }
64}
65
66impl Default for CheckButton {
67    fn default() -> Self {
68        Self::new()
69    }
70}
71
72// rustdoc-stripper-ignore-next
73/// A [builder-pattern] type to construct [`CheckButton`] objects.
74///
75/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
76#[must_use = "The builder must be built to be used"]
77pub struct CheckButtonBuilder {
78    builder: glib::object::ObjectBuilder<'static, CheckButton>,
79}
80
81impl CheckButtonBuilder {
82    fn new() -> Self {
83        Self {
84            builder: glib::object::Object::builder(),
85        }
86    }
87
88    pub fn active(self, active: bool) -> Self {
89        Self {
90            builder: self.builder.property("active", active),
91        }
92    }
93
94    #[cfg(feature = "v4_8")]
95    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
96    pub fn child(self, child: &impl IsA<Widget>) -> Self {
97        Self {
98            builder: self.builder.property("child", child.clone().upcast()),
99        }
100    }
101
102    pub fn group(self, group: &impl IsA<CheckButton>) -> Self {
103        Self {
104            builder: self.builder.property("group", group.clone().upcast()),
105        }
106    }
107
108    pub fn inconsistent(self, inconsistent: bool) -> Self {
109        Self {
110            builder: self.builder.property("inconsistent", inconsistent),
111        }
112    }
113
114    pub fn label(self, label: impl Into<glib::GString>) -> Self {
115        Self {
116            builder: self.builder.property("label", label.into()),
117        }
118    }
119
120    pub fn use_underline(self, use_underline: bool) -> Self {
121        Self {
122            builder: self.builder.property("use-underline", use_underline),
123        }
124    }
125
126    pub fn can_focus(self, can_focus: bool) -> Self {
127        Self {
128            builder: self.builder.property("can-focus", can_focus),
129        }
130    }
131
132    pub fn can_target(self, can_target: bool) -> Self {
133        Self {
134            builder: self.builder.property("can-target", can_target),
135        }
136    }
137
138    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
139        Self {
140            builder: self.builder.property("css-classes", css_classes.into()),
141        }
142    }
143
144    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
145        Self {
146            builder: self.builder.property("css-name", css_name.into()),
147        }
148    }
149
150    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
151        Self {
152            builder: self.builder.property("cursor", cursor.clone()),
153        }
154    }
155
156    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
157        Self {
158            builder: self.builder.property("focus-on-click", focus_on_click),
159        }
160    }
161
162    pub fn focusable(self, focusable: bool) -> Self {
163        Self {
164            builder: self.builder.property("focusable", focusable),
165        }
166    }
167
168    pub fn halign(self, halign: Align) -> Self {
169        Self {
170            builder: self.builder.property("halign", halign),
171        }
172    }
173
174    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
175        Self {
176            builder: self.builder.property("has-tooltip", has_tooltip),
177        }
178    }
179
180    pub fn height_request(self, height_request: i32) -> Self {
181        Self {
182            builder: self.builder.property("height-request", height_request),
183        }
184    }
185
186    pub fn hexpand(self, hexpand: bool) -> Self {
187        Self {
188            builder: self.builder.property("hexpand", hexpand),
189        }
190    }
191
192    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
193        Self {
194            builder: self.builder.property("hexpand-set", hexpand_set),
195        }
196    }
197
198    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
199        Self {
200            builder: self
201                .builder
202                .property("layout-manager", layout_manager.clone().upcast()),
203        }
204    }
205
206    #[cfg(feature = "v4_18")]
207    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
208    pub fn limit_events(self, limit_events: bool) -> Self {
209        Self {
210            builder: self.builder.property("limit-events", limit_events),
211        }
212    }
213
214    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
215        Self {
216            builder: self.builder.property("margin-bottom", margin_bottom),
217        }
218    }
219
220    pub fn margin_end(self, margin_end: i32) -> Self {
221        Self {
222            builder: self.builder.property("margin-end", margin_end),
223        }
224    }
225
226    pub fn margin_start(self, margin_start: i32) -> Self {
227        Self {
228            builder: self.builder.property("margin-start", margin_start),
229        }
230    }
231
232    pub fn margin_top(self, margin_top: i32) -> Self {
233        Self {
234            builder: self.builder.property("margin-top", margin_top),
235        }
236    }
237
238    pub fn name(self, name: impl Into<glib::GString>) -> Self {
239        Self {
240            builder: self.builder.property("name", name.into()),
241        }
242    }
243
244    pub fn opacity(self, opacity: f64) -> Self {
245        Self {
246            builder: self.builder.property("opacity", opacity),
247        }
248    }
249
250    pub fn overflow(self, overflow: Overflow) -> Self {
251        Self {
252            builder: self.builder.property("overflow", overflow),
253        }
254    }
255
256    pub fn receives_default(self, receives_default: bool) -> Self {
257        Self {
258            builder: self.builder.property("receives-default", receives_default),
259        }
260    }
261
262    pub fn sensitive(self, sensitive: bool) -> Self {
263        Self {
264            builder: self.builder.property("sensitive", sensitive),
265        }
266    }
267
268    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
269        Self {
270            builder: self
271                .builder
272                .property("tooltip-markup", tooltip_markup.into()),
273        }
274    }
275
276    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
277        Self {
278            builder: self.builder.property("tooltip-text", tooltip_text.into()),
279        }
280    }
281
282    pub fn valign(self, valign: Align) -> Self {
283        Self {
284            builder: self.builder.property("valign", valign),
285        }
286    }
287
288    pub fn vexpand(self, vexpand: bool) -> Self {
289        Self {
290            builder: self.builder.property("vexpand", vexpand),
291        }
292    }
293
294    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
295        Self {
296            builder: self.builder.property("vexpand-set", vexpand_set),
297        }
298    }
299
300    pub fn visible(self, visible: bool) -> Self {
301        Self {
302            builder: self.builder.property("visible", visible),
303        }
304    }
305
306    pub fn width_request(self, width_request: i32) -> Self {
307        Self {
308            builder: self.builder.property("width-request", width_request),
309        }
310    }
311
312    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
313        Self {
314            builder: self.builder.property("accessible-role", accessible_role),
315        }
316    }
317
318    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
319        Self {
320            builder: self.builder.property("action-name", action_name.into()),
321        }
322    }
323
324    pub fn action_target(self, action_target: &glib::Variant) -> Self {
325        Self {
326            builder: self
327                .builder
328                .property("action-target", action_target.clone()),
329        }
330    }
331
332    // rustdoc-stripper-ignore-next
333    /// Build the [`CheckButton`].
334    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
335    pub fn build(self) -> CheckButton {
336        assert_initialized_main_thread!();
337        self.builder.build()
338    }
339}
340
341pub trait CheckButtonExt: IsA<CheckButton> + 'static {
342    #[doc(alias = "gtk_check_button_get_active")]
343    #[doc(alias = "get_active")]
344    #[doc(alias = "active")]
345    fn is_active(&self) -> bool {
346        unsafe {
347            from_glib(ffi::gtk_check_button_get_active(
348                self.as_ref().to_glib_none().0,
349            ))
350        }
351    }
352
353    #[cfg(feature = "v4_8")]
354    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
355    #[doc(alias = "gtk_check_button_get_child")]
356    #[doc(alias = "get_child")]
357    fn child(&self) -> Option<Widget> {
358        unsafe {
359            from_glib_none(ffi::gtk_check_button_get_child(
360                self.as_ref().to_glib_none().0,
361            ))
362        }
363    }
364
365    #[doc(alias = "gtk_check_button_get_inconsistent")]
366    #[doc(alias = "get_inconsistent")]
367    #[doc(alias = "inconsistent")]
368    fn is_inconsistent(&self) -> bool {
369        unsafe {
370            from_glib(ffi::gtk_check_button_get_inconsistent(
371                self.as_ref().to_glib_none().0,
372            ))
373        }
374    }
375
376    #[doc(alias = "gtk_check_button_get_label")]
377    #[doc(alias = "get_label")]
378    fn label(&self) -> Option<glib::GString> {
379        unsafe {
380            from_glib_none(ffi::gtk_check_button_get_label(
381                self.as_ref().to_glib_none().0,
382            ))
383        }
384    }
385
386    #[doc(alias = "gtk_check_button_get_use_underline")]
387    #[doc(alias = "get_use_underline")]
388    #[doc(alias = "use-underline")]
389    fn uses_underline(&self) -> bool {
390        unsafe {
391            from_glib(ffi::gtk_check_button_get_use_underline(
392                self.as_ref().to_glib_none().0,
393            ))
394        }
395    }
396
397    #[doc(alias = "gtk_check_button_set_active")]
398    #[doc(alias = "active")]
399    fn set_active(&self, setting: bool) {
400        unsafe {
401            ffi::gtk_check_button_set_active(self.as_ref().to_glib_none().0, setting.into_glib());
402        }
403    }
404
405    #[cfg(feature = "v4_8")]
406    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
407    #[doc(alias = "gtk_check_button_set_child")]
408    #[doc(alias = "child")]
409    fn set_child(&self, child: Option<&impl IsA<Widget>>) {
410        unsafe {
411            ffi::gtk_check_button_set_child(
412                self.as_ref().to_glib_none().0,
413                child.map(|p| p.as_ref()).to_glib_none().0,
414            );
415        }
416    }
417
418    #[doc(alias = "gtk_check_button_set_group")]
419    #[doc(alias = "group")]
420    fn set_group(&self, group: Option<&impl IsA<CheckButton>>) {
421        unsafe {
422            ffi::gtk_check_button_set_group(
423                self.as_ref().to_glib_none().0,
424                group.map(|p| p.as_ref()).to_glib_none().0,
425            );
426        }
427    }
428
429    #[doc(alias = "gtk_check_button_set_inconsistent")]
430    #[doc(alias = "inconsistent")]
431    fn set_inconsistent(&self, inconsistent: bool) {
432        unsafe {
433            ffi::gtk_check_button_set_inconsistent(
434                self.as_ref().to_glib_none().0,
435                inconsistent.into_glib(),
436            );
437        }
438    }
439
440    #[doc(alias = "gtk_check_button_set_label")]
441    #[doc(alias = "label")]
442    fn set_label(&self, label: Option<&str>) {
443        unsafe {
444            ffi::gtk_check_button_set_label(self.as_ref().to_glib_none().0, label.to_glib_none().0);
445        }
446    }
447
448    #[doc(alias = "gtk_check_button_set_use_underline")]
449    #[doc(alias = "use-underline")]
450    fn set_use_underline(&self, setting: bool) {
451        unsafe {
452            ffi::gtk_check_button_set_use_underline(
453                self.as_ref().to_glib_none().0,
454                setting.into_glib(),
455            );
456        }
457    }
458
459    #[cfg(feature = "v4_2")]
460    #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
461    #[doc(alias = "activate")]
462    fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
463        unsafe extern "C" fn activate_trampoline<P: IsA<CheckButton>, F: Fn(&P) + 'static>(
464            this: *mut ffi::GtkCheckButton,
465            f: glib::ffi::gpointer,
466        ) {
467            let f: &F = &*(f as *const F);
468            f(CheckButton::from_glib_borrow(this).unsafe_cast_ref())
469        }
470        unsafe {
471            let f: Box_<F> = Box_::new(f);
472            connect_raw(
473                self.as_ptr() as *mut _,
474                c"activate".as_ptr() as *const _,
475                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
476                    activate_trampoline::<Self, F> as *const (),
477                )),
478                Box_::into_raw(f),
479            )
480        }
481    }
482
483    #[cfg(feature = "v4_2")]
484    #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
485    fn emit_activate(&self) {
486        self.emit_by_name::<()>("activate", &[]);
487    }
488
489    #[doc(alias = "toggled")]
490    fn connect_toggled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
491        unsafe extern "C" fn toggled_trampoline<P: IsA<CheckButton>, F: Fn(&P) + 'static>(
492            this: *mut ffi::GtkCheckButton,
493            f: glib::ffi::gpointer,
494        ) {
495            let f: &F = &*(f as *const F);
496            f(CheckButton::from_glib_borrow(this).unsafe_cast_ref())
497        }
498        unsafe {
499            let f: Box_<F> = Box_::new(f);
500            connect_raw(
501                self.as_ptr() as *mut _,
502                c"toggled".as_ptr() as *const _,
503                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
504                    toggled_trampoline::<Self, F> as *const (),
505                )),
506                Box_::into_raw(f),
507            )
508        }
509    }
510
511    #[doc(alias = "active")]
512    fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
513        unsafe extern "C" fn notify_active_trampoline<P: IsA<CheckButton>, F: Fn(&P) + 'static>(
514            this: *mut ffi::GtkCheckButton,
515            _param_spec: glib::ffi::gpointer,
516            f: glib::ffi::gpointer,
517        ) {
518            let f: &F = &*(f as *const F);
519            f(CheckButton::from_glib_borrow(this).unsafe_cast_ref())
520        }
521        unsafe {
522            let f: Box_<F> = Box_::new(f);
523            connect_raw(
524                self.as_ptr() as *mut _,
525                c"notify::active".as_ptr() as *const _,
526                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
527                    notify_active_trampoline::<Self, F> as *const (),
528                )),
529                Box_::into_raw(f),
530            )
531        }
532    }
533
534    #[cfg(feature = "v4_8")]
535    #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
536    #[doc(alias = "child")]
537    fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
538        unsafe extern "C" fn notify_child_trampoline<P: IsA<CheckButton>, F: Fn(&P) + 'static>(
539            this: *mut ffi::GtkCheckButton,
540            _param_spec: glib::ffi::gpointer,
541            f: glib::ffi::gpointer,
542        ) {
543            let f: &F = &*(f as *const F);
544            f(CheckButton::from_glib_borrow(this).unsafe_cast_ref())
545        }
546        unsafe {
547            let f: Box_<F> = Box_::new(f);
548            connect_raw(
549                self.as_ptr() as *mut _,
550                c"notify::child".as_ptr() as *const _,
551                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
552                    notify_child_trampoline::<Self, F> as *const (),
553                )),
554                Box_::into_raw(f),
555            )
556        }
557    }
558
559    #[doc(alias = "group")]
560    fn connect_group_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
561        unsafe extern "C" fn notify_group_trampoline<P: IsA<CheckButton>, F: Fn(&P) + 'static>(
562            this: *mut ffi::GtkCheckButton,
563            _param_spec: glib::ffi::gpointer,
564            f: glib::ffi::gpointer,
565        ) {
566            let f: &F = &*(f as *const F);
567            f(CheckButton::from_glib_borrow(this).unsafe_cast_ref())
568        }
569        unsafe {
570            let f: Box_<F> = Box_::new(f);
571            connect_raw(
572                self.as_ptr() as *mut _,
573                c"notify::group".as_ptr() as *const _,
574                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
575                    notify_group_trampoline::<Self, F> as *const (),
576                )),
577                Box_::into_raw(f),
578            )
579        }
580    }
581
582    #[doc(alias = "inconsistent")]
583    fn connect_inconsistent_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
584        unsafe extern "C" fn notify_inconsistent_trampoline<
585            P: IsA<CheckButton>,
586            F: Fn(&P) + 'static,
587        >(
588            this: *mut ffi::GtkCheckButton,
589            _param_spec: glib::ffi::gpointer,
590            f: glib::ffi::gpointer,
591        ) {
592            let f: &F = &*(f as *const F);
593            f(CheckButton::from_glib_borrow(this).unsafe_cast_ref())
594        }
595        unsafe {
596            let f: Box_<F> = Box_::new(f);
597            connect_raw(
598                self.as_ptr() as *mut _,
599                c"notify::inconsistent".as_ptr() as *const _,
600                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
601                    notify_inconsistent_trampoline::<Self, F> as *const (),
602                )),
603                Box_::into_raw(f),
604            )
605        }
606    }
607
608    #[doc(alias = "label")]
609    fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
610        unsafe extern "C" fn notify_label_trampoline<P: IsA<CheckButton>, F: Fn(&P) + 'static>(
611            this: *mut ffi::GtkCheckButton,
612            _param_spec: glib::ffi::gpointer,
613            f: glib::ffi::gpointer,
614        ) {
615            let f: &F = &*(f as *const F);
616            f(CheckButton::from_glib_borrow(this).unsafe_cast_ref())
617        }
618        unsafe {
619            let f: Box_<F> = Box_::new(f);
620            connect_raw(
621                self.as_ptr() as *mut _,
622                c"notify::label".as_ptr() as *const _,
623                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
624                    notify_label_trampoline::<Self, F> as *const (),
625                )),
626                Box_::into_raw(f),
627            )
628        }
629    }
630
631    #[doc(alias = "use-underline")]
632    fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
633        unsafe extern "C" fn notify_use_underline_trampoline<
634            P: IsA<CheckButton>,
635            F: Fn(&P) + 'static,
636        >(
637            this: *mut ffi::GtkCheckButton,
638            _param_spec: glib::ffi::gpointer,
639            f: glib::ffi::gpointer,
640        ) {
641            let f: &F = &*(f as *const F);
642            f(CheckButton::from_glib_borrow(this).unsafe_cast_ref())
643        }
644        unsafe {
645            let f: Box_<F> = Box_::new(f);
646            connect_raw(
647                self.as_ptr() as *mut _,
648                c"notify::use-underline".as_ptr() as *const _,
649                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
650                    notify_use_underline_trampoline::<Self, F> as *const (),
651                )),
652                Box_::into_raw(f),
653            )
654        }
655    }
656}
657
658impl<O: IsA<CheckButton>> CheckButtonExt for O {}