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