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