Skip to main content

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