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::{ffi, ActionRow, PreferencesRow};
7use glib::{
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    #[doc(alias = "AdwSwitchRow")]
16    pub struct SwitchRow(Object<ffi::AdwSwitchRow, ffi::AdwSwitchRowClass>) @extends ActionRow, PreferencesRow, gtk::ListBoxRow, gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget, gtk::Actionable;
17
18    match fn {
19        type_ => || ffi::adw_switch_row_get_type(),
20    }
21}
22
23impl SwitchRow {
24    #[doc(alias = "adw_switch_row_new")]
25    pub fn new() -> SwitchRow {
26        assert_initialized_main_thread!();
27        unsafe { gtk::Widget::from_glib_none(ffi::adw_switch_row_new()).unsafe_cast() }
28    }
29
30    // rustdoc-stripper-ignore-next
31    /// Creates a new builder-pattern struct instance to construct [`SwitchRow`] objects.
32    ///
33    /// This method returns an instance of [`SwitchRowBuilder`](crate::builders::SwitchRowBuilder) which can be used to create [`SwitchRow`] objects.
34    pub fn builder() -> SwitchRowBuilder {
35        SwitchRowBuilder::new()
36    }
37
38    #[doc(alias = "adw_switch_row_get_active")]
39    #[doc(alias = "get_active")]
40    #[doc(alias = "active")]
41    pub fn is_active(&self) -> bool {
42        unsafe { from_glib(ffi::adw_switch_row_get_active(self.to_glib_none().0)) }
43    }
44
45    #[doc(alias = "adw_switch_row_set_active")]
46    #[doc(alias = "active")]
47    pub fn set_active(&self, is_active: bool) {
48        unsafe {
49            ffi::adw_switch_row_set_active(self.to_glib_none().0, is_active.into_glib());
50        }
51    }
52
53    #[cfg(feature = "v1_4")]
54    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
55    #[doc(alias = "active")]
56    pub fn connect_active_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
57        unsafe extern "C" fn notify_active_trampoline<F: Fn(&SwitchRow) + 'static>(
58            this: *mut ffi::AdwSwitchRow,
59            _param_spec: glib::ffi::gpointer,
60            f: glib::ffi::gpointer,
61        ) {
62            let f: &F = &*(f as *const F);
63            f(&from_glib_borrow(this))
64        }
65        unsafe {
66            let f: Box_<F> = Box_::new(f);
67            connect_raw(
68                self.as_ptr() as *mut _,
69                c"notify::active".as_ptr() as *const _,
70                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
71                    notify_active_trampoline::<F> as *const (),
72                )),
73                Box_::into_raw(f),
74            )
75        }
76    }
77}
78
79#[cfg(feature = "v1_4")]
80#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
81impl Default for SwitchRow {
82    fn default() -> Self {
83        Self::new()
84    }
85}
86
87// rustdoc-stripper-ignore-next
88/// A [builder-pattern] type to construct [`SwitchRow`] objects.
89///
90/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
91#[must_use = "The builder must be built to be used"]
92pub struct SwitchRowBuilder {
93    builder: glib::object::ObjectBuilder<'static, SwitchRow>,
94}
95
96impl SwitchRowBuilder {
97    fn new() -> Self {
98        Self {
99            builder: glib::object::Object::builder(),
100        }
101    }
102
103    #[cfg(feature = "v1_4")]
104    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
105    pub fn active(self, active: bool) -> Self {
106        Self {
107            builder: self.builder.property("active", active),
108        }
109    }
110
111    pub fn activatable_widget(self, activatable_widget: &impl IsA<gtk::Widget>) -> Self {
112        Self {
113            builder: self
114                .builder
115                .property("activatable-widget", activatable_widget.clone().upcast()),
116        }
117    }
118
119    #[cfg_attr(feature = "v1_3", deprecated = "Since 1.3")]
120    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
121        Self {
122            builder: self.builder.property("icon-name", icon_name.into()),
123        }
124    }
125
126    pub fn subtitle(self, subtitle: impl Into<glib::GString>) -> Self {
127        Self {
128            builder: self.builder.property("subtitle", subtitle.into()),
129        }
130    }
131
132    pub fn subtitle_lines(self, subtitle_lines: i32) -> Self {
133        Self {
134            builder: self.builder.property("subtitle-lines", subtitle_lines),
135        }
136    }
137
138    #[cfg(feature = "v1_3")]
139    #[cfg_attr(docsrs, doc(cfg(feature = "v1_3")))]
140    pub fn subtitle_selectable(self, subtitle_selectable: bool) -> Self {
141        Self {
142            builder: self
143                .builder
144                .property("subtitle-selectable", subtitle_selectable),
145        }
146    }
147
148    pub fn title_lines(self, title_lines: i32) -> Self {
149        Self {
150            builder: self.builder.property("title-lines", title_lines),
151        }
152    }
153
154    pub fn title(self, title: impl Into<glib::GString>) -> Self {
155        Self {
156            builder: self.builder.property("title", title.into()),
157        }
158    }
159
160    #[cfg(feature = "v1_1")]
161    #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
162    pub fn title_selectable(self, title_selectable: bool) -> Self {
163        Self {
164            builder: self.builder.property("title-selectable", title_selectable),
165        }
166    }
167
168    #[cfg(feature = "v1_2")]
169    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
170    pub fn use_markup(self, use_markup: bool) -> Self {
171        Self {
172            builder: self.builder.property("use-markup", use_markup),
173        }
174    }
175
176    pub fn use_underline(self, use_underline: bool) -> Self {
177        Self {
178            builder: self.builder.property("use-underline", use_underline),
179        }
180    }
181
182    pub fn activatable(self, activatable: bool) -> Self {
183        Self {
184            builder: self.builder.property("activatable", activatable),
185        }
186    }
187
188    pub fn child(self, child: &impl IsA<gtk::Widget>) -> Self {
189        Self {
190            builder: self.builder.property("child", child.clone().upcast()),
191        }
192    }
193
194    pub fn selectable(self, selectable: bool) -> Self {
195        Self {
196            builder: self.builder.property("selectable", selectable),
197        }
198    }
199
200    pub fn can_focus(self, can_focus: bool) -> Self {
201        Self {
202            builder: self.builder.property("can-focus", can_focus),
203        }
204    }
205
206    pub fn can_target(self, can_target: bool) -> Self {
207        Self {
208            builder: self.builder.property("can-target", can_target),
209        }
210    }
211
212    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
213        Self {
214            builder: self.builder.property("css-classes", css_classes.into()),
215        }
216    }
217
218    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
219        Self {
220            builder: self.builder.property("css-name", css_name.into()),
221        }
222    }
223
224    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
225        Self {
226            builder: self.builder.property("cursor", cursor.clone()),
227        }
228    }
229
230    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
231        Self {
232            builder: self.builder.property("focus-on-click", focus_on_click),
233        }
234    }
235
236    pub fn focusable(self, focusable: bool) -> Self {
237        Self {
238            builder: self.builder.property("focusable", focusable),
239        }
240    }
241
242    pub fn halign(self, halign: gtk::Align) -> Self {
243        Self {
244            builder: self.builder.property("halign", halign),
245        }
246    }
247
248    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
249        Self {
250            builder: self.builder.property("has-tooltip", has_tooltip),
251        }
252    }
253
254    pub fn height_request(self, height_request: i32) -> Self {
255        Self {
256            builder: self.builder.property("height-request", height_request),
257        }
258    }
259
260    pub fn hexpand(self, hexpand: bool) -> Self {
261        Self {
262            builder: self.builder.property("hexpand", hexpand),
263        }
264    }
265
266    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
267        Self {
268            builder: self.builder.property("hexpand-set", hexpand_set),
269        }
270    }
271
272    pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
273        Self {
274            builder: self
275                .builder
276                .property("layout-manager", layout_manager.clone().upcast()),
277        }
278    }
279
280    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
281        Self {
282            builder: self.builder.property("margin-bottom", margin_bottom),
283        }
284    }
285
286    pub fn margin_end(self, margin_end: i32) -> Self {
287        Self {
288            builder: self.builder.property("margin-end", margin_end),
289        }
290    }
291
292    pub fn margin_start(self, margin_start: i32) -> Self {
293        Self {
294            builder: self.builder.property("margin-start", margin_start),
295        }
296    }
297
298    pub fn margin_top(self, margin_top: i32) -> Self {
299        Self {
300            builder: self.builder.property("margin-top", margin_top),
301        }
302    }
303
304    pub fn name(self, name: impl Into<glib::GString>) -> Self {
305        Self {
306            builder: self.builder.property("name", name.into()),
307        }
308    }
309
310    pub fn opacity(self, opacity: f64) -> Self {
311        Self {
312            builder: self.builder.property("opacity", opacity),
313        }
314    }
315
316    pub fn overflow(self, overflow: gtk::Overflow) -> Self {
317        Self {
318            builder: self.builder.property("overflow", overflow),
319        }
320    }
321
322    pub fn receives_default(self, receives_default: bool) -> Self {
323        Self {
324            builder: self.builder.property("receives-default", receives_default),
325        }
326    }
327
328    pub fn sensitive(self, sensitive: bool) -> Self {
329        Self {
330            builder: self.builder.property("sensitive", sensitive),
331        }
332    }
333
334    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
335        Self {
336            builder: self
337                .builder
338                .property("tooltip-markup", tooltip_markup.into()),
339        }
340    }
341
342    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
343        Self {
344            builder: self.builder.property("tooltip-text", tooltip_text.into()),
345        }
346    }
347
348    pub fn valign(self, valign: gtk::Align) -> Self {
349        Self {
350            builder: self.builder.property("valign", valign),
351        }
352    }
353
354    pub fn vexpand(self, vexpand: bool) -> Self {
355        Self {
356            builder: self.builder.property("vexpand", vexpand),
357        }
358    }
359
360    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
361        Self {
362            builder: self.builder.property("vexpand-set", vexpand_set),
363        }
364    }
365
366    pub fn visible(self, visible: bool) -> Self {
367        Self {
368            builder: self.builder.property("visible", visible),
369        }
370    }
371
372    pub fn width_request(self, width_request: i32) -> Self {
373        Self {
374            builder: self.builder.property("width-request", width_request),
375        }
376    }
377
378    pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
379        Self {
380            builder: self.builder.property("accessible-role", accessible_role),
381        }
382    }
383
384    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
385        Self {
386            builder: self.builder.property("action-name", action_name.into()),
387        }
388    }
389
390    pub fn action_target(self, action_target: &glib::Variant) -> Self {
391        Self {
392            builder: self
393                .builder
394                .property("action-target", action_target.clone()),
395        }
396    }
397
398    // rustdoc-stripper-ignore-next
399    /// Build the [`SwitchRow`].
400    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
401    pub fn build(self) -> SwitchRow {
402        assert_initialized_main_thread!();
403        self.builder.build()
404    }
405}