Skip to main content

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