Skip to main content

gtk4/auto/
toggle_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#![allow(deprecated)]
5
6#[cfg(feature = "v4_10")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
8use crate::Accessible;
9use crate::{
10    AccessibleRole, Actionable, Align, Buildable, Button, ConstraintTarget, LayoutManager,
11    Overflow, Widget, ffi,
12};
13use glib::{
14    object::ObjectType as _,
15    prelude::*,
16    signal::{SignalHandlerId, connect_raw},
17    translate::*,
18};
19use std::boxed::Box as Box_;
20
21#[cfg(feature = "v4_10")]
22#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
23glib::wrapper! {
24    /// m toggle button two";
25    ///   toggle2 = gtk_toggle_button_new_with_label (text);
26    ///   g_signal_connect (toggle2, "toggled",
27    ///                     G_CALLBACK (output_state),
28    ///                     NULL);
29    ///   gtk_box_append (GTK_BOX (box), toggle2);
30    ///
31    ///   gtk_window_set_child (GTK_WINDOW (window), box);
32    ///   gtk_window_present (GTK_WINDOW (window));
33    /// }
34    /// ```text
35    ///
36    ///
37    /// ## Properties
38    ///
39    ///
40    /// #### `active`
41    ///  If the toggle button should be pressed in.
42    ///
43    /// Readable | Writable
44    ///
45    ///
46    /// #### `group`
47    ///  The toggle button whose group this widget belongs to.
48    ///
49    /// Writable
50    /// <details><summary><h4>Button</h4></summary>
51    ///
52    ///
53    /// #### `can-shrink`
54    ///  Whether the size of the button can be made smaller than the natural
55    /// size of its contents.
56    ///
57    /// For text buttons, setting this property will allow ellipsizing the label.
58    ///
59    /// If the contents of a button are an icon or a custom widget, setting this
60    /// property has no effect.
61    ///
62    /// Readable | Writable
63    ///
64    ///
65    /// #### `child`
66    ///  The child widget.
67    ///
68    /// Readable | Writable
69    ///
70    ///
71    /// #### `has-frame`
72    ///  Whether the button has a frame.
73    ///
74    /// Readable | Writable
75    ///
76    ///
77    /// #### `icon-name`
78    ///  The name of the icon used to automatically populate the button.
79    ///
80    /// Readable | Writable
81    ///
82    ///
83    /// #### `label`
84    ///  Text of the label inside the button, if the button contains a label widget.
85    ///
86    /// Readable | Writable
87    ///
88    ///
89    /// #### `use-underline`
90    ///  If set, an underline in the text indicates that the following character is
91    /// to be used as mnemonic.
92    ///
93    /// Readable | Writable
94    /// </details>
95    /// <details><summary><h4>Widget</h4></summary>
96    ///
97    ///
98    /// #### `can-focus`
99    ///  Whether the widget or any of its descendents can accept
100    /// the input focus.
101    ///
102    /// This property is meant to be set by widget implementations,
103    /// typically in their instance init function.
104    ///
105    /// Readable | Writable
106    ///
107    ///
108    /// #### `can-target`
109    ///  Whether the widget can receive pointer events.
110    ///
111    /// Readable | Writable
112    ///
113    ///
114    /// #### `css-classes`
115    ///  A list of css classes applied to this widget.
116    ///
117    /// Readable | Writable
118    ///
119    ///
120    /// #### `css-name`
121    ///  The name of this widget in the CSS tree.
122    ///
123    /// This property is meant to be set by widget implementations,
124    /// typically in their instance init function.
125    ///
126    /// Readable | Writable | Construct Only
127    ///
128    ///
129    /// #### `cursor`
130    ///  The cursor used by @widget.
131    ///
132    /// Readable | Writable
133    ///
134    ///
135    /// #### `focus-on-click`
136    ///  Whether the widget should grab focus when it is clicked with the mouse.
137    ///
138    /// This property is only relevant for widgets that can take focus.
139    ///
140    /// Readable | Writable
141    ///
142    ///
143    /// #### `focusable`
144    ///  Whether this widget itself will accept the input focus.
145    ///
146    /// Readable | Writable
147    ///
148    ///
149    /// #### `halign`
150    ///  How to distribute horizontal space if widget gets extra space.
151    ///
152    /// Readable | Writable
153    ///
154    ///
155    /// #### `has-default`
156    ///  Whether the widget is the default widget.
157    ///
158    /// Readable
159    ///
160    ///
161    /// #### `has-focus`
162    ///  Whether the widget has the input focus.
163    ///
164    /// Readable
165    ///
166    ///
167    /// #### `has-tooltip`
168    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
169    /// signal on @widget.
170    ///
171    /// A true value indicates that @widget can have a tooltip, in this case
172    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
173    /// determine whether it will provide a tooltip or not.
174    ///
175    /// Readable | Writable
176    ///
177    ///
178    /// #### `height-request`
179    ///  Overrides for height request of the widget.
180    ///
181    /// If this is -1, the natural request will be used.
182    ///
183    /// Readable | Writable
184    ///
185    ///
186    /// #### `hexpand`
187    ///  Whether to expand horizontally.
188    ///
189    /// Readable | Writable
190    ///
191    ///
192    /// #### `hexpand-set`
193    ///  Whether to use the `hexpand` property.
194    ///
195    /// Readable | Writable
196    ///
197    ///
198    /// #### `layout-manager`
199    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
200    /// the preferred size of the widget, and allocate its children.
201    ///
202    /// This property is meant to be set by widget implementations,
203    /// typically in their instance init function.
204    ///
205    /// Readable | Writable
206    ///
207    ///
208    /// #### `limit-events`
209    ///  Makes this widget act like a modal dialog, with respect to
210    /// event delivery.
211    ///
212    /// Global event controllers will not handle events with targets
213    /// inside the widget, unless they are set up to ignore propagation
214    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
215    ///
216    /// Readable | Writable
217    ///
218    ///
219    /// #### `margin-bottom`
220    ///  Margin on bottom side of widget.
221    ///
222    /// This property adds margin outside of the widget's normal size
223    /// request, the margin will be added in addition to the size from
224    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
225    ///
226    /// Readable | Writable
227    ///
228    ///
229    /// #### `margin-end`
230    ///  Margin on end of widget, horizontally.
231    ///
232    /// This property supports left-to-right and right-to-left text
233    /// directions.
234    ///
235    /// This property adds margin outside of the widget's normal size
236    /// request, the margin will be added in addition to the size from
237    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
238    ///
239    /// Readable | Writable
240    ///
241    ///
242    /// #### `margin-start`
243    ///  Margin on start of widget, horizontally.
244    ///
245    /// This property supports left-to-right and right-to-left text
246    /// directions.
247    ///
248    /// This property adds margin outside of the widget's normal size
249    /// request, the margin will be added in addition to the size from
250    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
251    ///
252    /// Readable | Writable
253    ///
254    ///
255    /// #### `margin-top`
256    ///  Margin on top side of widget.
257    ///
258    /// This property adds margin outside of the widget's normal size
259    /// request, the margin will be added in addition to the size from
260    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
261    ///
262    /// Readable | Writable
263    ///
264    ///
265    /// #### `name`
266    ///  The name of the widget.
267    ///
268    /// Readable | Writable
269    ///
270    ///
271    /// #### `opacity`
272    ///  The requested opacity of the widget.
273    ///
274    /// Readable | Writable
275    ///
276    ///
277    /// #### `overflow`
278    ///  How content outside the widget's content area is treated.
279    ///
280    /// This property is meant to be set by widget implementations,
281    /// typically in their instance init function.
282    ///
283    /// Readable | Writable
284    ///
285    ///
286    /// #### `parent`
287    ///  The parent widget of this widget.
288    ///
289    /// Readable
290    ///
291    ///
292    /// #### `receives-default`
293    ///  Whether the widget will receive the default action when it is focused.
294    ///
295    /// Readable | Writable
296    ///
297    ///
298    /// #### `root`
299    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
300    ///
301    /// This will be `NULL` if the widget is not contained in a root widget.
302    ///
303    /// Readable
304    ///
305    ///
306    /// #### `scale-factor`
307    ///  The scale factor of the widget.
308    ///
309    /// Readable
310    ///
311    ///
312    /// #### `sensitive`
313    ///  Whether the widget responds to input.
314    ///
315    /// Readable | Writable
316    ///
317    ///
318    /// #### `tooltip-markup`
319    ///  Sets the text of tooltip to be the given string, which is marked up
320    /// with Pango markup.
321    ///
322    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
323    ///
324    /// This is a convenience property which will take care of getting the
325    /// tooltip shown if the given string is not `NULL`:
326    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
327    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
328    /// the default signal handler.
329    ///
330    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
331    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
332    ///
333    /// Readable | Writable
334    ///
335    ///
336    /// #### `tooltip-text`
337    ///  Sets the text of tooltip to be the given string.
338    ///
339    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
340    ///
341    /// This is a convenience property which will take care of getting the
342    /// tooltip shown if the given string is not `NULL`:
343    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
344    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
345    /// the default signal handler.
346    ///
347    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
348    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
349    ///
350    /// Readable | Writable
351    ///
352    ///
353    /// #### `valign`
354    ///  How to distribute vertical space if widget gets extra space.
355    ///
356    /// Readable | Writable
357    ///
358    ///
359    /// #### `vexpand`
360    ///  Whether to expand vertically.
361    ///
362    /// Readable | Writable
363    ///
364    ///
365    /// #### `vexpand-set`
366    ///  Whether to use the `vexpand` property.
367    ///
368    /// Readable | Writable
369    ///
370    ///
371    /// #### `visible`
372    ///  Whether the widget is visible.
373    ///
374    /// Readable | Writable
375    ///
376    ///
377    /// #### `width-request`
378    ///  Overrides for width request of the widget.
379    ///
380    /// If this is -1, the natural request will be used.
381    ///
382    /// Readable | Writable
383    /// </details>
384    /// <details><summary><h4>Accessible</h4></summary>
385    ///
386    ///
387    /// #### `accessible-role`
388    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
389    ///
390    /// The accessible role cannot be changed once set.
391    ///
392    /// Readable | Writable
393    /// </details>
394    /// <details><summary><h4>Actionable</h4></summary>
395    ///
396    ///
397    /// #### `action-name`
398    ///  The name of the action with which this widget should be associated.
399    ///
400    /// Readable | Writable
401    ///
402    ///
403    /// #### `action-target`
404    ///  The target value of the actionable widget's action.
405    ///
406    /// Readable | Writable
407    /// </details>
408    ///
409    /// ## Signals
410    ///
411    ///
412    /// #### `toggled`
413    ///  Emitted whenever the [`ToggleButton`][crate::ToggleButton]'s state is changed.
414    ///
415    ///
416    /// <details><summary><h4>Button</h4></summary>
417    ///
418    ///
419    /// #### `activate`
420    ///   keys.
421    ///
422    /// Action
423    ///
424    ///
425    /// #### `clicked`
426    ///  Emitted when the button has been activated (pressed and released).
427    ///
428    /// Action
429    /// </details>
430    /// <details><summary><h4>Widget</h4></summary>
431    ///
432    ///
433    /// #### `destroy`
434    ///  Signals that all holders of a reference to the widget should release
435    /// the reference that they hold.
436    ///
437    /// May result in finalization of the widget if all references are released.
438    ///
439    /// This signal is not suitable for saving widget state.
440    ///
441    ///
442    ///
443    ///
444    /// #### `direction-changed`
445    ///  Emitted when the text direction of a widget changes.
446    ///
447    ///
448    ///
449    ///
450    /// #### `hide`
451    ///  Emitted when @widget is hidden.
452    ///
453    ///
454    ///
455    ///
456    /// #### `keynav-failed`
457    ///  Emitted if keyboard navigation fails.
458    ///
459    /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
460    ///
461    ///
462    ///
463    ///
464    /// #### `map`
465    ///  Emitted when @widget is going to be mapped.
466    ///
467    /// A widget is mapped when the widget is visible (which is controlled with
468    /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
469    /// are also visible.
470    ///
471    /// The `::map` signal can be used to determine whether a widget will be drawn,
472    /// for instance it can resume an animation that was stopped during the
473    /// emission of [`unmap`][struct@crate::Widget#unmap].
474    ///
475    ///
476    ///
477    ///
478    /// #### `mnemonic-activate`
479    ///  Emitted when a widget is activated via a mnemonic.
480    ///
481    /// The default handler for this signal activates @widget if @group_cycling
482    /// is false, or just makes @widget grab focus if @group_cycling is true.
483    ///
484    ///
485    ///
486    ///
487    /// #### `move-focus`
488    ///   to move backward.
489    ///
490    /// Action
491    ///
492    ///
493    /// #### `query-tooltip`
494    ///  s tooltip is about to be shown.
495    ///
496    /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
497    /// is true and the hover timeout has expired with the cursor hovering
498    /// above @widget; or emitted when @widget got focus in keyboard mode.
499    ///
500    /// Using the given coordinates, the signal handler should determine
501    /// whether a tooltip should be shown for @widget. If this is the case
502    /// true should be returned, false otherwise. Note that if @keyboard_mode
503    /// is true, the values of @x and @y are undefined and should not be used.
504    ///
505    /// The signal handler is free to manipulate @tooltip with the therefore
506    /// destined function calls.
507    ///
508    ///
509    ///
510    ///
511    /// #### `realize`
512    ///  Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
513    ///
514    /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
515    /// or the widget has been mapped (that is, it is going to be drawn).
516    ///
517    ///
518    ///
519    ///
520    /// #### `show`
521    ///  Emitted when @widget is shown.
522    ///
523    ///
524    ///
525    ///
526    /// #### `state-flags-changed`
527    ///  Emitted when the widget state changes.
528    ///
529    /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
530    ///
531    ///
532    ///
533    ///
534    /// #### `unmap`
535    ///  Emitted when @widget is going to be unmapped.
536    ///
537    /// A widget is unmapped when either it or any of its parents up to the
538    /// toplevel widget have been set as hidden.
539    ///
540    /// As `::unmap` indicates that a widget will not be shown any longer,
541    /// it can be used to, for example, stop an animation on the widget.
542    ///
543    ///
544    ///
545    ///
546    /// #### `unrealize`
547    ///  Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
548    ///
549    /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
550    /// or the widget has been unmapped (that is, it is going to be hidden).
551    ///
552    ///
553    /// </details>
554    ///
555    /// # Implements
556    ///
557    /// [`ToggleButtonExt`][trait@crate::prelude::ToggleButtonExt], [`ButtonExt`][trait@crate::prelude::ButtonExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`ActionableExt`][trait@crate::prelude::ActionableExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual], [`ActionableExtManual`][trait@crate::prelude::ActionableExtManual]
558    #[doc(alias = "GtkToggleButton")]
559    pub struct ToggleButton(Object<ffi::GtkToggleButton, ffi::GtkToggleButtonClass>) @extends Button, Widget, @implements Accessible, Buildable, ConstraintTarget, Actionable;
560
561    match fn {
562        type_ => || ffi::gtk_toggle_button_get_type(),
563    }
564}
565
566#[cfg(not(feature = "v4_10"))]
567glib::wrapper! {
568    #[doc(alias = "GtkToggleButton")]
569    pub struct ToggleButton(Object<ffi::GtkToggleButton, ffi::GtkToggleButtonClass>) @extends Button, Widget, @implements Buildable, ConstraintTarget, Actionable;
570
571    match fn {
572        type_ => || ffi::gtk_toggle_button_get_type(),
573    }
574}
575
576impl ToggleButton {
577    pub const NONE: Option<&'static ToggleButton> = None;
578
579    /// Creates a new toggle button.
580    ///
581    /// A widget should be packed into the button, as in [`Button::new()`][crate::Button::new()].
582    ///
583    /// # Returns
584    ///
585    /// a new toggle button.
586    #[doc(alias = "gtk_toggle_button_new")]
587    pub fn new() -> ToggleButton {
588        assert_initialized_main_thread!();
589        unsafe { Widget::from_glib_none(ffi::gtk_toggle_button_new()).unsafe_cast() }
590    }
591
592    /// Creates a new toggle button with a text label.
593    /// ## `label`
594    /// a string containing the message to be placed in the toggle button.
595    ///
596    /// # Returns
597    ///
598    /// a new toggle button.
599    #[doc(alias = "gtk_toggle_button_new_with_label")]
600    #[doc(alias = "new_with_label")]
601    pub fn with_label(label: &str) -> ToggleButton {
602        assert_initialized_main_thread!();
603        unsafe {
604            Widget::from_glib_none(ffi::gtk_toggle_button_new_with_label(
605                label.to_glib_none().0,
606            ))
607            .unsafe_cast()
608        }
609    }
610
611    /// Creates a new [`ToggleButton`][crate::ToggleButton] containing a label.
612    ///
613    /// The label will be created using [`Label::with_mnemonic()`][crate::Label::with_mnemonic()],
614    /// so underscores in @label indicate the mnemonic for the button.
615    /// ## `label`
616    /// the text of the button, with an underscore in front of the
617    ///   mnemonic character
618    ///
619    /// # Returns
620    ///
621    /// a new [`ToggleButton`][crate::ToggleButton]
622    #[doc(alias = "gtk_toggle_button_new_with_mnemonic")]
623    #[doc(alias = "new_with_mnemonic")]
624    pub fn with_mnemonic(label: &str) -> ToggleButton {
625        assert_initialized_main_thread!();
626        unsafe {
627            Widget::from_glib_none(ffi::gtk_toggle_button_new_with_mnemonic(
628                label.to_glib_none().0,
629            ))
630            .unsafe_cast()
631        }
632    }
633
634    // rustdoc-stripper-ignore-next
635    /// Creates a new builder-pattern struct instance to construct [`ToggleButton`] objects.
636    ///
637    /// This method returns an instance of [`ToggleButtonBuilder`](crate::builders::ToggleButtonBuilder) which can be used to create [`ToggleButton`] objects.
638    pub fn builder() -> ToggleButtonBuilder {
639        ToggleButtonBuilder::new()
640    }
641}
642
643impl Default for ToggleButton {
644    fn default() -> Self {
645        Self::new()
646    }
647}
648
649// rustdoc-stripper-ignore-next
650/// A [builder-pattern] type to construct [`ToggleButton`] objects.
651///
652/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
653#[must_use = "The builder must be built to be used"]
654pub struct ToggleButtonBuilder {
655    builder: glib::object::ObjectBuilder<'static, ToggleButton>,
656}
657
658impl ToggleButtonBuilder {
659    fn new() -> Self {
660        Self {
661            builder: glib::object::Object::builder(),
662        }
663    }
664
665    /// If the toggle button should be pressed in.
666    pub fn active(self, active: bool) -> Self {
667        Self {
668            builder: self.builder.property("active", active),
669        }
670    }
671
672    /// The toggle button whose group this widget belongs to.
673    pub fn group(self, group: &impl IsA<ToggleButton>) -> Self {
674        Self {
675            builder: self.builder.property("group", group.clone().upcast()),
676        }
677    }
678
679    /// Whether the size of the button can be made smaller than the natural
680    /// size of its contents.
681    ///
682    /// For text buttons, setting this property will allow ellipsizing the label.
683    ///
684    /// If the contents of a button are an icon or a custom widget, setting this
685    /// property has no effect.
686    #[cfg(feature = "v4_12")]
687    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
688    pub fn can_shrink(self, can_shrink: bool) -> Self {
689        Self {
690            builder: self.builder.property("can-shrink", can_shrink),
691        }
692    }
693
694    /// The child widget.
695    pub fn child(self, child: &impl IsA<Widget>) -> Self {
696        Self {
697            builder: self.builder.property("child", child.clone().upcast()),
698        }
699    }
700
701    /// Whether the button has a frame.
702    pub fn has_frame(self, has_frame: bool) -> Self {
703        Self {
704            builder: self.builder.property("has-frame", has_frame),
705        }
706    }
707
708    /// The name of the icon used to automatically populate the button.
709    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
710        Self {
711            builder: self.builder.property("icon-name", icon_name.into()),
712        }
713    }
714
715    /// Text of the label inside the button, if the button contains a label widget.
716    pub fn label(self, label: impl Into<glib::GString>) -> Self {
717        Self {
718            builder: self.builder.property("label", label.into()),
719        }
720    }
721
722    /// If set, an underline in the text indicates that the following character is
723    /// to be used as mnemonic.
724    pub fn use_underline(self, use_underline: bool) -> Self {
725        Self {
726            builder: self.builder.property("use-underline", use_underline),
727        }
728    }
729
730    /// Whether the widget or any of its descendents can accept
731    /// the input focus.
732    ///
733    /// This property is meant to be set by widget implementations,
734    /// typically in their instance init function.
735    pub fn can_focus(self, can_focus: bool) -> Self {
736        Self {
737            builder: self.builder.property("can-focus", can_focus),
738        }
739    }
740
741    /// Whether the widget can receive pointer events.
742    pub fn can_target(self, can_target: bool) -> Self {
743        Self {
744            builder: self.builder.property("can-target", can_target),
745        }
746    }
747
748    /// A list of css classes applied to this widget.
749    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
750        Self {
751            builder: self.builder.property("css-classes", css_classes.into()),
752        }
753    }
754
755    /// The name of this widget in the CSS tree.
756    ///
757    /// This property is meant to be set by widget implementations,
758    /// typically in their instance init function.
759    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
760        Self {
761            builder: self.builder.property("css-name", css_name.into()),
762        }
763    }
764
765    /// The cursor used by @widget.
766    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
767        Self {
768            builder: self.builder.property("cursor", cursor.clone()),
769        }
770    }
771
772    /// Whether the widget should grab focus when it is clicked with the mouse.
773    ///
774    /// This property is only relevant for widgets that can take focus.
775    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
776        Self {
777            builder: self.builder.property("focus-on-click", focus_on_click),
778        }
779    }
780
781    /// Whether this widget itself will accept the input focus.
782    pub fn focusable(self, focusable: bool) -> Self {
783        Self {
784            builder: self.builder.property("focusable", focusable),
785        }
786    }
787
788    /// How to distribute horizontal space if widget gets extra space.
789    pub fn halign(self, halign: Align) -> Self {
790        Self {
791            builder: self.builder.property("halign", halign),
792        }
793    }
794
795    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
796    /// signal on @widget.
797    ///
798    /// A true value indicates that @widget can have a tooltip, in this case
799    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
800    /// determine whether it will provide a tooltip or not.
801    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
802        Self {
803            builder: self.builder.property("has-tooltip", has_tooltip),
804        }
805    }
806
807    /// Overrides for height request of the widget.
808    ///
809    /// If this is -1, the natural request will be used.
810    pub fn height_request(self, height_request: i32) -> Self {
811        Self {
812            builder: self.builder.property("height-request", height_request),
813        }
814    }
815
816    /// Whether to expand horizontally.
817    pub fn hexpand(self, hexpand: bool) -> Self {
818        Self {
819            builder: self.builder.property("hexpand", hexpand),
820        }
821    }
822
823    /// Whether to use the `hexpand` property.
824    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
825        Self {
826            builder: self.builder.property("hexpand-set", hexpand_set),
827        }
828    }
829
830    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
831    /// the preferred size of the widget, and allocate its children.
832    ///
833    /// This property is meant to be set by widget implementations,
834    /// typically in their instance init function.
835    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
836        Self {
837            builder: self
838                .builder
839                .property("layout-manager", layout_manager.clone().upcast()),
840        }
841    }
842
843    /// Makes this widget act like a modal dialog, with respect to
844    /// event delivery.
845    ///
846    /// Global event controllers will not handle events with targets
847    /// inside the widget, unless they are set up to ignore propagation
848    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
849    #[cfg(feature = "v4_18")]
850    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
851    pub fn limit_events(self, limit_events: bool) -> Self {
852        Self {
853            builder: self.builder.property("limit-events", limit_events),
854        }
855    }
856
857    /// Margin on bottom side of widget.
858    ///
859    /// This property adds margin outside of the widget's normal size
860    /// request, the margin will be added in addition to the size from
861    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
862    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
863        Self {
864            builder: self.builder.property("margin-bottom", margin_bottom),
865        }
866    }
867
868    /// Margin on end of widget, horizontally.
869    ///
870    /// This property supports left-to-right and right-to-left text
871    /// directions.
872    ///
873    /// This property adds margin outside of the widget's normal size
874    /// request, the margin will be added in addition to the size from
875    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
876    pub fn margin_end(self, margin_end: i32) -> Self {
877        Self {
878            builder: self.builder.property("margin-end", margin_end),
879        }
880    }
881
882    /// Margin on start of widget, horizontally.
883    ///
884    /// This property supports left-to-right and right-to-left text
885    /// directions.
886    ///
887    /// This property adds margin outside of the widget's normal size
888    /// request, the margin will be added in addition to the size from
889    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
890    pub fn margin_start(self, margin_start: i32) -> Self {
891        Self {
892            builder: self.builder.property("margin-start", margin_start),
893        }
894    }
895
896    /// Margin on top side of widget.
897    ///
898    /// This property adds margin outside of the widget's normal size
899    /// request, the margin will be added in addition to the size from
900    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
901    pub fn margin_top(self, margin_top: i32) -> Self {
902        Self {
903            builder: self.builder.property("margin-top", margin_top),
904        }
905    }
906
907    /// The name of the widget.
908    pub fn name(self, name: impl Into<glib::GString>) -> Self {
909        Self {
910            builder: self.builder.property("name", name.into()),
911        }
912    }
913
914    /// The requested opacity of the widget.
915    pub fn opacity(self, opacity: f64) -> Self {
916        Self {
917            builder: self.builder.property("opacity", opacity),
918        }
919    }
920
921    /// How content outside the widget's content area is treated.
922    ///
923    /// This property is meant to be set by widget implementations,
924    /// typically in their instance init function.
925    pub fn overflow(self, overflow: Overflow) -> Self {
926        Self {
927            builder: self.builder.property("overflow", overflow),
928        }
929    }
930
931    /// Whether the widget will receive the default action when it is focused.
932    pub fn receives_default(self, receives_default: bool) -> Self {
933        Self {
934            builder: self.builder.property("receives-default", receives_default),
935        }
936    }
937
938    /// Whether the widget responds to input.
939    pub fn sensitive(self, sensitive: bool) -> Self {
940        Self {
941            builder: self.builder.property("sensitive", sensitive),
942        }
943    }
944
945    /// Sets the text of tooltip to be the given string, which is marked up
946    /// with Pango markup.
947    ///
948    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
949    ///
950    /// This is a convenience property which will take care of getting the
951    /// tooltip shown if the given string is not `NULL`:
952    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
953    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
954    /// the default signal handler.
955    ///
956    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
957    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
958    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
959        Self {
960            builder: self
961                .builder
962                .property("tooltip-markup", tooltip_markup.into()),
963        }
964    }
965
966    /// Sets the text of tooltip to be the given string.
967    ///
968    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
969    ///
970    /// This is a convenience property which will take care of getting the
971    /// tooltip shown if the given string is not `NULL`:
972    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
973    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
974    /// the default signal handler.
975    ///
976    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
977    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
978    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
979        Self {
980            builder: self.builder.property("tooltip-text", tooltip_text.into()),
981        }
982    }
983
984    /// How to distribute vertical space if widget gets extra space.
985    pub fn valign(self, valign: Align) -> Self {
986        Self {
987            builder: self.builder.property("valign", valign),
988        }
989    }
990
991    /// Whether to expand vertically.
992    pub fn vexpand(self, vexpand: bool) -> Self {
993        Self {
994            builder: self.builder.property("vexpand", vexpand),
995        }
996    }
997
998    /// Whether to use the `vexpand` property.
999    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1000        Self {
1001            builder: self.builder.property("vexpand-set", vexpand_set),
1002        }
1003    }
1004
1005    /// Whether the widget is visible.
1006    pub fn visible(self, visible: bool) -> Self {
1007        Self {
1008            builder: self.builder.property("visible", visible),
1009        }
1010    }
1011
1012    /// Overrides for width request of the widget.
1013    ///
1014    /// If this is -1, the natural request will be used.
1015    pub fn width_request(self, width_request: i32) -> Self {
1016        Self {
1017            builder: self.builder.property("width-request", width_request),
1018        }
1019    }
1020
1021    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1022    ///
1023    /// The accessible role cannot be changed once set.
1024    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1025        Self {
1026            builder: self.builder.property("accessible-role", accessible_role),
1027        }
1028    }
1029
1030    /// The name of the action with which this widget should be associated.
1031    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
1032        Self {
1033            builder: self.builder.property("action-name", action_name.into()),
1034        }
1035    }
1036
1037    /// The target value of the actionable widget's action.
1038    pub fn action_target(self, action_target: &glib::Variant) -> Self {
1039        Self {
1040            builder: self
1041                .builder
1042                .property("action-target", action_target.clone()),
1043        }
1044    }
1045
1046    // rustdoc-stripper-ignore-next
1047    /// Build the [`ToggleButton`].
1048    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1049    pub fn build(self) -> ToggleButton {
1050        assert_initialized_main_thread!();
1051        self.builder.build()
1052    }
1053}
1054
1055/// Trait containing all [`struct@ToggleButton`] methods.
1056///
1057/// # Implementors
1058///
1059/// [`ToggleButton`][struct@crate::ToggleButton]
1060pub trait ToggleButtonExt: IsA<ToggleButton> + 'static {
1061    /// Queries a [`ToggleButton`][crate::ToggleButton] and returns its current state.
1062    ///
1063    /// Returns [`true`] if the toggle button is pressed in and [`false`]
1064    /// if it is raised.
1065    ///
1066    /// # Returns
1067    ///
1068    /// whether the button is pressed
1069    #[doc(alias = "gtk_toggle_button_get_active")]
1070    #[doc(alias = "get_active")]
1071    #[doc(alias = "active")]
1072    fn is_active(&self) -> bool {
1073        unsafe {
1074            from_glib(ffi::gtk_toggle_button_get_active(
1075                self.as_ref().to_glib_none().0,
1076            ))
1077        }
1078    }
1079
1080    /// ,
1081    /// and [`false`] to raise it.
1082    ///
1083    /// If the status of the button changes, this action causes the
1084    /// [`toggled`][struct@crate::ToggleButton#toggled] signal to be emitted.
1085    /// ## `is_active`
1086    /// [`true`] or [`false`].
1087    #[doc(alias = "gtk_toggle_button_set_active")]
1088    #[doc(alias = "active")]
1089    fn set_active(&self, is_active: bool) {
1090        unsafe {
1091            ffi::gtk_toggle_button_set_active(
1092                self.as_ref().to_glib_none().0,
1093                is_active.into_glib(),
1094            );
1095        }
1096    }
1097
1098    /// Adds @self_ to the group of @group.
1099    ///
1100    /// In a group of multiple toggle buttons, only one button can be active
1101    /// at a time.
1102    ///
1103    /// Setting up groups in a cycle leads to undefined behavior.
1104    ///
1105    /// Note that the same effect can be achieved via the [`Actionable`][crate::Actionable]
1106    /// API, by using the same action with parameter type and state type 's'
1107    /// for all buttons in the group, and giving each button its own target
1108    /// value.
1109    /// ## `group`
1110    /// another [`ToggleButton`][crate::ToggleButton] to
1111    ///   form a group with
1112    #[doc(alias = "gtk_toggle_button_set_group")]
1113    #[doc(alias = "group")]
1114    fn set_group(&self, group: Option<&impl IsA<ToggleButton>>) {
1115        unsafe {
1116            ffi::gtk_toggle_button_set_group(
1117                self.as_ref().to_glib_none().0,
1118                group.map(|p| p.as_ref()).to_glib_none().0,
1119            );
1120        }
1121    }
1122
1123    /// Emits the ::toggled signal on the [`ToggleButton`][crate::ToggleButton].
1124    ///
1125    /// # Deprecated since 4.10
1126    ///
1127    /// There is no good reason for an application ever to call this function.
1128    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1129    #[allow(deprecated)]
1130    #[doc(alias = "gtk_toggle_button_toggled")]
1131    fn toggled(&self) {
1132        unsafe {
1133            ffi::gtk_toggle_button_toggled(self.as_ref().to_glib_none().0);
1134        }
1135    }
1136
1137    /// Emitted whenever the [`ToggleButton`][crate::ToggleButton]'s state is changed.
1138    #[doc(alias = "toggled")]
1139    fn connect_toggled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1140        unsafe extern "C" fn toggled_trampoline<P: IsA<ToggleButton>, F: Fn(&P) + 'static>(
1141            this: *mut ffi::GtkToggleButton,
1142            f: glib::ffi::gpointer,
1143        ) {
1144            unsafe {
1145                let f: &F = &*(f as *const F);
1146                f(ToggleButton::from_glib_borrow(this).unsafe_cast_ref())
1147            }
1148        }
1149        unsafe {
1150            let f: Box_<F> = Box_::new(f);
1151            connect_raw(
1152                self.as_ptr() as *mut _,
1153                c"toggled".as_ptr(),
1154                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1155                    toggled_trampoline::<Self, F> as *const (),
1156                )),
1157                Box_::into_raw(f),
1158            )
1159        }
1160    }
1161
1162    #[doc(alias = "active")]
1163    fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1164        unsafe extern "C" fn notify_active_trampoline<P: IsA<ToggleButton>, F: Fn(&P) + 'static>(
1165            this: *mut ffi::GtkToggleButton,
1166            _param_spec: glib::ffi::gpointer,
1167            f: glib::ffi::gpointer,
1168        ) {
1169            unsafe {
1170                let f: &F = &*(f as *const F);
1171                f(ToggleButton::from_glib_borrow(this).unsafe_cast_ref())
1172            }
1173        }
1174        unsafe {
1175            let f: Box_<F> = Box_::new(f);
1176            connect_raw(
1177                self.as_ptr() as *mut _,
1178                c"notify::active".as_ptr(),
1179                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1180                    notify_active_trampoline::<Self, F> as *const (),
1181                )),
1182                Box_::into_raw(f),
1183            )
1184        }
1185    }
1186
1187    #[doc(alias = "group")]
1188    fn connect_group_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1189        unsafe extern "C" fn notify_group_trampoline<P: IsA<ToggleButton>, F: Fn(&P) + 'static>(
1190            this: *mut ffi::GtkToggleButton,
1191            _param_spec: glib::ffi::gpointer,
1192            f: glib::ffi::gpointer,
1193        ) {
1194            unsafe {
1195                let f: &F = &*(f as *const F);
1196                f(ToggleButton::from_glib_borrow(this).unsafe_cast_ref())
1197            }
1198        }
1199        unsafe {
1200            let f: Box_<F> = Box_::new(f);
1201            connect_raw(
1202                self.as_ptr() as *mut _,
1203                c"notify::group".as_ptr(),
1204                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1205                    notify_group_trampoline::<Self, F> as *const (),
1206                )),
1207                Box_::into_raw(f),
1208            )
1209        }
1210    }
1211}
1212
1213impl<O: IsA<ToggleButton>> ToggleButtonExt for O {}