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    /// Shows a button which remains “pressed-in” when clicked.
20    ///
21    /// <picture>
22    ///   <source srcset="toggle-button-dark.png" media="(prefers-color-scheme: dark)">
23    ///   <img alt="Example GtkToggleButtons" src="toggle-button.png">
24    /// </picture>
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 | Writeable
105    ///
106    ///
107    /// #### `group`
108    ///  The toggle button whose group this widget belongs to.
109    ///
110    /// Writeable
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 | Writeable
124    ///
125    ///
126    /// #### `child`
127    ///  The child widget.
128    ///
129    /// Readable | Writeable
130    ///
131    ///
132    /// #### `has-frame`
133    ///  Whether the button has a frame.
134    ///
135    /// Readable | Writeable
136    ///
137    ///
138    /// #### `icon-name`
139    ///  The name of the icon used to automatically populate the button.
140    ///
141    /// Readable | Writeable
142    ///
143    ///
144    /// #### `label`
145    ///  Text of the label inside the button, if the button contains a label widget.
146    ///
147    /// Readable | Writeable
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 | Writeable
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 | Writeable
167    ///
168    ///
169    /// #### `can-target`
170    ///  Whether the widget can receive pointer events.
171    ///
172    /// Readable | Writeable
173    ///
174    ///
175    /// #### `css-classes`
176    ///  A list of css classes applied to this widget.
177    ///
178    /// Readable | Writeable
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 | Writeable | Construct Only
188    ///
189    ///
190    /// #### `cursor`
191    ///  The cursor used by @widget.
192    ///
193    /// Readable | Writeable
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 | Writeable
202    ///
203    ///
204    /// #### `focusable`
205    ///  Whether this widget itself will accept the input focus.
206    ///
207    /// Readable | Writeable
208    ///
209    ///
210    /// #### `halign`
211    ///  How to distribute horizontal space if widget gets extra space.
212    ///
213    /// Readable | Writeable
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 | Writeable
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 | Writeable
245    ///
246    ///
247    /// #### `hexpand`
248    ///  Whether to expand horizontally.
249    ///
250    /// Readable | Writeable
251    ///
252    ///
253    /// #### `hexpand-set`
254    ///  Whether to use the `hexpand` property.
255    ///
256    /// Readable | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
324    ///
325    ///
326    /// #### `name`
327    ///  The name of the widget.
328    ///
329    /// Readable | Writeable
330    ///
331    ///
332    /// #### `opacity`
333    ///  The requested opacity of the widget.
334    ///
335    /// Readable | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
412    ///
413    ///
414    /// #### `valign`
415    ///  How to distribute vertical space if widget gets extra space.
416    ///
417    /// Readable | Writeable
418    ///
419    ///
420    /// #### `vexpand`
421    ///  Whether to expand vertically.
422    ///
423    /// Readable | Writeable
424    ///
425    ///
426    /// #### `vexpand-set`
427    ///  Whether to use the `vexpand` property.
428    ///
429    /// Readable | Writeable
430    ///
431    ///
432    /// #### `visible`
433    ///  Whether the widget is visible.
434    ///
435    /// Readable | Writeable
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 | Writeable
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 | Writeable
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 | Writeable
462    ///
463    ///
464    /// #### `action-target`
465    ///  The target value of the actionable widget's action.
466    ///
467    /// Readable | Writeable
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    ///  Emitted to animate press then release.
482    ///
483    /// This is an action signal. Applications should never connect
484    /// to this signal, but use the [`clicked`][struct@crate::Button#clicked] signal.
485    ///
486    /// The default bindings for this signal are all forms of the
487    /// <kbd>␣</kbd> and <kbd>Enter</kbd> keys.
488    ///
489    /// Action
490    ///
491    ///
492    /// #### `clicked`
493    ///  Emitted when the button has been activated (pressed and released).
494    ///
495    /// Action
496    /// </details>
497    /// <details><summary><h4>Widget</h4></summary>
498    ///
499    ///
500    /// #### `destroy`
501    ///  Signals that all holders of a reference to the widget should release
502    /// the reference that they hold.
503    ///
504    /// May result in finalization of the widget if all references are released.
505    ///
506    /// This signal is not suitable for saving widget state.
507    ///
508    ///
509    ///
510    ///
511    /// #### `direction-changed`
512    ///  Emitted when the text direction of a widget changes.
513    ///
514    ///
515    ///
516    ///
517    /// #### `hide`
518    ///  Emitted when @widget is hidden.
519    ///
520    ///
521    ///
522    ///
523    /// #### `keynav-failed`
524    ///  Emitted if keyboard navigation fails.
525    ///
526    /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
527    ///
528    ///
529    ///
530    ///
531    /// #### `map`
532    ///  Emitted when @widget is going to be mapped.
533    ///
534    /// A widget is mapped when the widget is visible (which is controlled with
535    /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
536    /// are also visible.
537    ///
538    /// The `::map` signal can be used to determine whether a widget will be drawn,
539    /// for instance it can resume an animation that was stopped during the
540    /// emission of [`unmap`][struct@crate::Widget#unmap].
541    ///
542    ///
543    ///
544    ///
545    /// #### `mnemonic-activate`
546    ///  Emitted when a widget is activated via a mnemonic.
547    ///
548    /// The default handler for this signal activates @widget if @group_cycling
549    /// is false, or just makes @widget grab focus if @group_cycling is true.
550    ///
551    ///
552    ///
553    ///
554    /// #### `move-focus`
555    ///  Emitted when the focus is moved.
556    ///
557    /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
558    ///
559    /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
560    /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
561    ///
562    /// Action
563    ///
564    ///
565    /// #### `query-tooltip`
566    ///  Emitted when the widget’s tooltip is about to be shown.
567    ///
568    /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
569    /// is true and the hover timeout has expired with the cursor hovering
570    /// above @widget; or emitted when @widget got focus in keyboard mode.
571    ///
572    /// Using the given coordinates, the signal handler should determine
573    /// whether a tooltip should be shown for @widget. If this is the case
574    /// true should be returned, false otherwise. Note that if @keyboard_mode
575    /// is true, the values of @x and @y are undefined and should not be used.
576    ///
577    /// The signal handler is free to manipulate @tooltip with the therefore
578    /// destined function calls.
579    ///
580    ///
581    ///
582    ///
583    /// #### `realize`
584    ///  Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
585    ///
586    /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
587    /// or the widget has been mapped (that is, it is going to be drawn).
588    ///
589    ///
590    ///
591    ///
592    /// #### `show`
593    ///  Emitted when @widget is shown.
594    ///
595    ///
596    ///
597    ///
598    /// #### `state-flags-changed`
599    ///  Emitted when the widget state changes.
600    ///
601    /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
602    ///
603    ///
604    ///
605    ///
606    /// #### `unmap`
607    ///  Emitted when @widget is going to be unmapped.
608    ///
609    /// A widget is unmapped when either it or any of its parents up to the
610    /// toplevel widget have been set as hidden.
611    ///
612    /// As `::unmap` indicates that a widget will not be shown any longer,
613    /// it can be used to, for example, stop an animation on the widget.
614    ///
615    ///
616    ///
617    ///
618    /// #### `unrealize`
619    ///  Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
620    ///
621    /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
622    /// or the widget has been unmapped (that is, it is going to be hidden).
623    ///
624    ///
625    /// </details>
626    ///
627    /// # Implements
628    ///
629    /// [`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]
630    #[doc(alias = "GtkToggleButton")]
631    pub struct ToggleButton(Object<ffi::GtkToggleButton, ffi::GtkToggleButtonClass>) @extends Button, Widget, @implements Accessible, Buildable, ConstraintTarget, Actionable;
632
633    match fn {
634        type_ => || ffi::gtk_toggle_button_get_type(),
635    }
636}
637
638impl ToggleButton {
639    pub const NONE: Option<&'static ToggleButton> = None;
640
641    /// Creates a new toggle button.
642    ///
643    /// A widget should be packed into the button, as in [`Button::new()`][crate::Button::new()].
644    ///
645    /// # Returns
646    ///
647    /// a new toggle button.
648    #[doc(alias = "gtk_toggle_button_new")]
649    pub fn new() -> ToggleButton {
650        assert_initialized_main_thread!();
651        unsafe { Widget::from_glib_none(ffi::gtk_toggle_button_new()).unsafe_cast() }
652    }
653
654    /// Creates a new toggle button with a text label.
655    /// ## `label`
656    /// a string containing the message to be placed in the toggle button.
657    ///
658    /// # Returns
659    ///
660    /// a new toggle button.
661    #[doc(alias = "gtk_toggle_button_new_with_label")]
662    #[doc(alias = "new_with_label")]
663    pub fn with_label(label: &str) -> ToggleButton {
664        assert_initialized_main_thread!();
665        unsafe {
666            Widget::from_glib_none(ffi::gtk_toggle_button_new_with_label(
667                label.to_glib_none().0,
668            ))
669            .unsafe_cast()
670        }
671    }
672
673    /// Creates a new [`ToggleButton`][crate::ToggleButton] containing a label.
674    ///
675    /// The label will be created using [`Label::with_mnemonic()`][crate::Label::with_mnemonic()],
676    /// so underscores in @label indicate the mnemonic for the button.
677    /// ## `label`
678    /// the text of the button, with an underscore in front of the
679    ///   mnemonic character
680    ///
681    /// # Returns
682    ///
683    /// a new [`ToggleButton`][crate::ToggleButton]
684    #[doc(alias = "gtk_toggle_button_new_with_mnemonic")]
685    #[doc(alias = "new_with_mnemonic")]
686    pub fn with_mnemonic(label: &str) -> ToggleButton {
687        assert_initialized_main_thread!();
688        unsafe {
689            Widget::from_glib_none(ffi::gtk_toggle_button_new_with_mnemonic(
690                label.to_glib_none().0,
691            ))
692            .unsafe_cast()
693        }
694    }
695
696    // rustdoc-stripper-ignore-next
697    /// Creates a new builder-pattern struct instance to construct [`ToggleButton`] objects.
698    ///
699    /// This method returns an instance of [`ToggleButtonBuilder`](crate::builders::ToggleButtonBuilder) which can be used to create [`ToggleButton`] objects.
700    pub fn builder() -> ToggleButtonBuilder {
701        ToggleButtonBuilder::new()
702    }
703}
704
705impl Default for ToggleButton {
706    fn default() -> Self {
707        Self::new()
708    }
709}
710
711// rustdoc-stripper-ignore-next
712/// A [builder-pattern] type to construct [`ToggleButton`] objects.
713///
714/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
715#[must_use = "The builder must be built to be used"]
716pub struct ToggleButtonBuilder {
717    builder: glib::object::ObjectBuilder<'static, ToggleButton>,
718}
719
720impl ToggleButtonBuilder {
721    fn new() -> Self {
722        Self {
723            builder: glib::object::Object::builder(),
724        }
725    }
726
727    /// If the toggle button should be pressed in.
728    pub fn active(self, active: bool) -> Self {
729        Self {
730            builder: self.builder.property("active", active),
731        }
732    }
733
734    /// The toggle button whose group this widget belongs to.
735    pub fn group(self, group: &impl IsA<ToggleButton>) -> Self {
736        Self {
737            builder: self.builder.property("group", group.clone().upcast()),
738        }
739    }
740
741    /// Whether the size of the button can be made smaller than the natural
742    /// size of its contents.
743    ///
744    /// For text buttons, setting this property will allow ellipsizing the label.
745    ///
746    /// If the contents of a button are an icon or a custom widget, setting this
747    /// property has no effect.
748    #[cfg(feature = "v4_12")]
749    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
750    pub fn can_shrink(self, can_shrink: bool) -> Self {
751        Self {
752            builder: self.builder.property("can-shrink", can_shrink),
753        }
754    }
755
756    /// The child widget.
757    pub fn child(self, child: &impl IsA<Widget>) -> Self {
758        Self {
759            builder: self.builder.property("child", child.clone().upcast()),
760        }
761    }
762
763    /// Whether the button has a frame.
764    pub fn has_frame(self, has_frame: bool) -> Self {
765        Self {
766            builder: self.builder.property("has-frame", has_frame),
767        }
768    }
769
770    /// The name of the icon used to automatically populate the button.
771    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
772        Self {
773            builder: self.builder.property("icon-name", icon_name.into()),
774        }
775    }
776
777    /// Text of the label inside the button, if the button contains a label widget.
778    pub fn label(self, label: impl Into<glib::GString>) -> Self {
779        Self {
780            builder: self.builder.property("label", label.into()),
781        }
782    }
783
784    /// If set, an underline in the text indicates that the following character is
785    /// to be used as mnemonic.
786    pub fn use_underline(self, use_underline: bool) -> Self {
787        Self {
788            builder: self.builder.property("use-underline", use_underline),
789        }
790    }
791
792    /// Whether the widget or any of its descendents can accept
793    /// the input focus.
794    ///
795    /// This property is meant to be set by widget implementations,
796    /// typically in their instance init function.
797    pub fn can_focus(self, can_focus: bool) -> Self {
798        Self {
799            builder: self.builder.property("can-focus", can_focus),
800        }
801    }
802
803    /// Whether the widget can receive pointer events.
804    pub fn can_target(self, can_target: bool) -> Self {
805        Self {
806            builder: self.builder.property("can-target", can_target),
807        }
808    }
809
810    /// A list of css classes applied to this widget.
811    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
812        Self {
813            builder: self.builder.property("css-classes", css_classes.into()),
814        }
815    }
816
817    /// The name of this widget in the CSS tree.
818    ///
819    /// This property is meant to be set by widget implementations,
820    /// typically in their instance init function.
821    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
822        Self {
823            builder: self.builder.property("css-name", css_name.into()),
824        }
825    }
826
827    /// The cursor used by @widget.
828    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
829        Self {
830            builder: self.builder.property("cursor", cursor.clone()),
831        }
832    }
833
834    /// Whether the widget should grab focus when it is clicked with the mouse.
835    ///
836    /// This property is only relevant for widgets that can take focus.
837    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
838        Self {
839            builder: self.builder.property("focus-on-click", focus_on_click),
840        }
841    }
842
843    /// Whether this widget itself will accept the input focus.
844    pub fn focusable(self, focusable: bool) -> Self {
845        Self {
846            builder: self.builder.property("focusable", focusable),
847        }
848    }
849
850    /// How to distribute horizontal space if widget gets extra space.
851    pub fn halign(self, halign: Align) -> Self {
852        Self {
853            builder: self.builder.property("halign", halign),
854        }
855    }
856
857    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
858    /// signal on @widget.
859    ///
860    /// A true value indicates that @widget can have a tooltip, in this case
861    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
862    /// determine whether it will provide a tooltip or not.
863    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
864        Self {
865            builder: self.builder.property("has-tooltip", has_tooltip),
866        }
867    }
868
869    /// Overrides for height request of the widget.
870    ///
871    /// If this is -1, the natural request will be used.
872    pub fn height_request(self, height_request: i32) -> Self {
873        Self {
874            builder: self.builder.property("height-request", height_request),
875        }
876    }
877
878    /// Whether to expand horizontally.
879    pub fn hexpand(self, hexpand: bool) -> Self {
880        Self {
881            builder: self.builder.property("hexpand", hexpand),
882        }
883    }
884
885    /// Whether to use the `hexpand` property.
886    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
887        Self {
888            builder: self.builder.property("hexpand-set", hexpand_set),
889        }
890    }
891
892    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
893    /// the preferred size of the widget, and allocate its children.
894    ///
895    /// This property is meant to be set by widget implementations,
896    /// typically in their instance init function.
897    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
898        Self {
899            builder: self
900                .builder
901                .property("layout-manager", layout_manager.clone().upcast()),
902        }
903    }
904
905    /// Makes this widget act like a modal dialog, with respect to
906    /// event delivery.
907    ///
908    /// Global event controllers will not handle events with targets
909    /// inside the widget, unless they are set up to ignore propagation
910    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
911    #[cfg(feature = "v4_18")]
912    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
913    pub fn limit_events(self, limit_events: bool) -> Self {
914        Self {
915            builder: self.builder.property("limit-events", limit_events),
916        }
917    }
918
919    /// Margin on bottom side of widget.
920    ///
921    /// This property adds margin outside of the widget's normal size
922    /// request, the margin will be added in addition to the size from
923    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
924    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
925        Self {
926            builder: self.builder.property("margin-bottom", margin_bottom),
927        }
928    }
929
930    /// Margin on end of widget, horizontally.
931    ///
932    /// This property supports left-to-right and right-to-left text
933    /// directions.
934    ///
935    /// This property adds margin outside of the widget's normal size
936    /// request, the margin will be added in addition to the size from
937    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
938    pub fn margin_end(self, margin_end: i32) -> Self {
939        Self {
940            builder: self.builder.property("margin-end", margin_end),
941        }
942    }
943
944    /// Margin on start of widget, horizontally.
945    ///
946    /// This property supports left-to-right and right-to-left text
947    /// directions.
948    ///
949    /// This property adds margin outside of the widget's normal size
950    /// request, the margin will be added in addition to the size from
951    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
952    pub fn margin_start(self, margin_start: i32) -> Self {
953        Self {
954            builder: self.builder.property("margin-start", margin_start),
955        }
956    }
957
958    /// Margin on top side of widget.
959    ///
960    /// This property adds margin outside of the widget's normal size
961    /// request, the margin will be added in addition to the size from
962    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
963    pub fn margin_top(self, margin_top: i32) -> Self {
964        Self {
965            builder: self.builder.property("margin-top", margin_top),
966        }
967    }
968
969    /// The name of the widget.
970    pub fn name(self, name: impl Into<glib::GString>) -> Self {
971        Self {
972            builder: self.builder.property("name", name.into()),
973        }
974    }
975
976    /// The requested opacity of the widget.
977    pub fn opacity(self, opacity: f64) -> Self {
978        Self {
979            builder: self.builder.property("opacity", opacity),
980        }
981    }
982
983    /// How content outside the widget's content area is treated.
984    ///
985    /// This property is meant to be set by widget implementations,
986    /// typically in their instance init function.
987    pub fn overflow(self, overflow: Overflow) -> Self {
988        Self {
989            builder: self.builder.property("overflow", overflow),
990        }
991    }
992
993    /// Whether the widget will receive the default action when it is focused.
994    pub fn receives_default(self, receives_default: bool) -> Self {
995        Self {
996            builder: self.builder.property("receives-default", receives_default),
997        }
998    }
999
1000    /// Whether the widget responds to input.
1001    pub fn sensitive(self, sensitive: bool) -> Self {
1002        Self {
1003            builder: self.builder.property("sensitive", sensitive),
1004        }
1005    }
1006
1007    /// Sets the text of tooltip to be the given string, which is marked up
1008    /// with Pango markup.
1009    ///
1010    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1011    ///
1012    /// This is a convenience property which will take care of getting the
1013    /// tooltip shown if the given string is not `NULL`:
1014    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1015    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1016    /// the default signal handler.
1017    ///
1018    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1019    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1020    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1021        Self {
1022            builder: self
1023                .builder
1024                .property("tooltip-markup", tooltip_markup.into()),
1025        }
1026    }
1027
1028    /// Sets the text of tooltip to be the given string.
1029    ///
1030    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1031    ///
1032    /// This is a convenience property which will take care of getting the
1033    /// tooltip shown if the given string is not `NULL`:
1034    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1035    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1036    /// the default signal handler.
1037    ///
1038    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1039    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1040    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1041        Self {
1042            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1043        }
1044    }
1045
1046    /// How to distribute vertical space if widget gets extra space.
1047    pub fn valign(self, valign: Align) -> Self {
1048        Self {
1049            builder: self.builder.property("valign", valign),
1050        }
1051    }
1052
1053    /// Whether to expand vertically.
1054    pub fn vexpand(self, vexpand: bool) -> Self {
1055        Self {
1056            builder: self.builder.property("vexpand", vexpand),
1057        }
1058    }
1059
1060    /// Whether to use the `vexpand` property.
1061    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1062        Self {
1063            builder: self.builder.property("vexpand-set", vexpand_set),
1064        }
1065    }
1066
1067    /// Whether the widget is visible.
1068    pub fn visible(self, visible: bool) -> Self {
1069        Self {
1070            builder: self.builder.property("visible", visible),
1071        }
1072    }
1073
1074    /// Overrides for width request of the widget.
1075    ///
1076    /// If this is -1, the natural request will be used.
1077    pub fn width_request(self, width_request: i32) -> Self {
1078        Self {
1079            builder: self.builder.property("width-request", width_request),
1080        }
1081    }
1082
1083    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1084    ///
1085    /// The accessible role cannot be changed once set.
1086    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1087        Self {
1088            builder: self.builder.property("accessible-role", accessible_role),
1089        }
1090    }
1091
1092    /// The name of the action with which this widget should be associated.
1093    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
1094        Self {
1095            builder: self.builder.property("action-name", action_name.into()),
1096        }
1097    }
1098
1099    /// The target value of the actionable widget's action.
1100    pub fn action_target(self, action_target: &glib::Variant) -> Self {
1101        Self {
1102            builder: self
1103                .builder
1104                .property("action-target", action_target.clone()),
1105        }
1106    }
1107
1108    // rustdoc-stripper-ignore-next
1109    /// Build the [`ToggleButton`].
1110    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1111    pub fn build(self) -> ToggleButton {
1112        assert_initialized_main_thread!();
1113        self.builder.build()
1114    }
1115}
1116
1117/// Trait containing all [`struct@ToggleButton`] methods.
1118///
1119/// # Implementors
1120///
1121/// [`ToggleButton`][struct@crate::ToggleButton]
1122pub trait ToggleButtonExt: IsA<ToggleButton> + 'static {
1123    /// Queries a [`ToggleButton`][crate::ToggleButton] and returns its current state.
1124    ///
1125    /// Returns [`true`] if the toggle button is pressed in and [`false`]
1126    /// if it is raised.
1127    ///
1128    /// # Returns
1129    ///
1130    /// whether the button is pressed
1131    #[doc(alias = "gtk_toggle_button_get_active")]
1132    #[doc(alias = "get_active")]
1133    #[doc(alias = "active")]
1134    fn is_active(&self) -> bool {
1135        unsafe {
1136            from_glib(ffi::gtk_toggle_button_get_active(
1137                self.as_ref().to_glib_none().0,
1138            ))
1139        }
1140    }
1141
1142    /// Sets the status of the toggle button.
1143    ///
1144    /// Set to [`true`] if you want the [`ToggleButton`][crate::ToggleButton] to be “pressed in”,
1145    /// and [`false`] to raise it.
1146    ///
1147    /// If the status of the button changes, this action causes the
1148    /// [`toggled`][struct@crate::ToggleButton#toggled] signal to be emitted.
1149    /// ## `is_active`
1150    /// [`true`] or [`false`].
1151    #[doc(alias = "gtk_toggle_button_set_active")]
1152    #[doc(alias = "active")]
1153    fn set_active(&self, is_active: bool) {
1154        unsafe {
1155            ffi::gtk_toggle_button_set_active(
1156                self.as_ref().to_glib_none().0,
1157                is_active.into_glib(),
1158            );
1159        }
1160    }
1161
1162    /// Adds @self_ to the group of @group.
1163    ///
1164    /// In a group of multiple toggle buttons, only one button can be active
1165    /// at a time.
1166    ///
1167    /// Setting up groups in a cycle leads to undefined behavior.
1168    ///
1169    /// Note that the same effect can be achieved via the [`Actionable`][crate::Actionable]
1170    /// API, by using the same action with parameter type and state type 's'
1171    /// for all buttons in the group, and giving each button its own target
1172    /// value.
1173    /// ## `group`
1174    /// another [`ToggleButton`][crate::ToggleButton] to
1175    ///   form a group with
1176    #[doc(alias = "gtk_toggle_button_set_group")]
1177    #[doc(alias = "group")]
1178    fn set_group(&self, group: Option<&impl IsA<ToggleButton>>) {
1179        unsafe {
1180            ffi::gtk_toggle_button_set_group(
1181                self.as_ref().to_glib_none().0,
1182                group.map(|p| p.as_ref()).to_glib_none().0,
1183            );
1184        }
1185    }
1186
1187    /// Emits the ::toggled signal on the [`ToggleButton`][crate::ToggleButton].
1188    ///
1189    /// # Deprecated since 4.10
1190    ///
1191    /// There is no good reason for an application ever to call this function.
1192    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1193    #[allow(deprecated)]
1194    #[doc(alias = "gtk_toggle_button_toggled")]
1195    fn toggled(&self) {
1196        unsafe {
1197            ffi::gtk_toggle_button_toggled(self.as_ref().to_glib_none().0);
1198        }
1199    }
1200
1201    /// Emitted whenever the [`ToggleButton`][crate::ToggleButton]'s state is changed.
1202    #[doc(alias = "toggled")]
1203    fn connect_toggled<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1204        unsafe extern "C" fn toggled_trampoline<P: IsA<ToggleButton>, F: Fn(&P) + 'static>(
1205            this: *mut ffi::GtkToggleButton,
1206            f: glib::ffi::gpointer,
1207        ) {
1208            let f: &F = &*(f as *const F);
1209            f(ToggleButton::from_glib_borrow(this).unsafe_cast_ref())
1210        }
1211        unsafe {
1212            let f: Box_<F> = Box_::new(f);
1213            connect_raw(
1214                self.as_ptr() as *mut _,
1215                c"toggled".as_ptr() as *const _,
1216                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1217                    toggled_trampoline::<Self, F> as *const (),
1218                )),
1219                Box_::into_raw(f),
1220            )
1221        }
1222    }
1223
1224    #[doc(alias = "active")]
1225    fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1226        unsafe extern "C" fn notify_active_trampoline<P: IsA<ToggleButton>, F: Fn(&P) + 'static>(
1227            this: *mut ffi::GtkToggleButton,
1228            _param_spec: glib::ffi::gpointer,
1229            f: glib::ffi::gpointer,
1230        ) {
1231            let f: &F = &*(f as *const F);
1232            f(ToggleButton::from_glib_borrow(this).unsafe_cast_ref())
1233        }
1234        unsafe {
1235            let f: Box_<F> = Box_::new(f);
1236            connect_raw(
1237                self.as_ptr() as *mut _,
1238                c"notify::active".as_ptr() as *const _,
1239                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1240                    notify_active_trampoline::<Self, F> as *const (),
1241                )),
1242                Box_::into_raw(f),
1243            )
1244        }
1245    }
1246
1247    #[doc(alias = "group")]
1248    fn connect_group_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1249        unsafe extern "C" fn notify_group_trampoline<P: IsA<ToggleButton>, F: Fn(&P) + 'static>(
1250            this: *mut ffi::GtkToggleButton,
1251            _param_spec: glib::ffi::gpointer,
1252            f: glib::ffi::gpointer,
1253        ) {
1254            let f: &F = &*(f as *const F);
1255            f(ToggleButton::from_glib_borrow(this).unsafe_cast_ref())
1256        }
1257        unsafe {
1258            let f: Box_<F> = Box_::new(f);
1259            connect_raw(
1260                self.as_ptr() as *mut _,
1261                c"notify::group".as_ptr() as *const _,
1262                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1263                    notify_group_trampoline::<Self, F> as *const (),
1264                )),
1265                Box_::into_raw(f),
1266            )
1267        }
1268    }
1269}
1270
1271impl<O: IsA<ToggleButton>> ToggleButtonExt for O {}