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