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