gtk4/auto/
switch.rs

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