1use 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 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#[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 #[cfg(feature = "gtk_v4_18")]
281 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
282 pub fn limit_events(self, limit_events: bool) -> Self {
283 Self {
284 builder: self.builder.property("limit-events", limit_events),
285 }
286 }
287
288 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
289 Self {
290 builder: self.builder.property("margin-bottom", margin_bottom),
291 }
292 }
293
294 pub fn margin_end(self, margin_end: i32) -> Self {
295 Self {
296 builder: self.builder.property("margin-end", margin_end),
297 }
298 }
299
300 pub fn margin_start(self, margin_start: i32) -> Self {
301 Self {
302 builder: self.builder.property("margin-start", margin_start),
303 }
304 }
305
306 pub fn margin_top(self, margin_top: i32) -> Self {
307 Self {
308 builder: self.builder.property("margin-top", margin_top),
309 }
310 }
311
312 pub fn name(self, name: impl Into<glib::GString>) -> Self {
313 Self {
314 builder: self.builder.property("name", name.into()),
315 }
316 }
317
318 pub fn opacity(self, opacity: f64) -> Self {
319 Self {
320 builder: self.builder.property("opacity", opacity),
321 }
322 }
323
324 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
325 Self {
326 builder: self.builder.property("overflow", overflow),
327 }
328 }
329
330 pub fn receives_default(self, receives_default: bool) -> Self {
331 Self {
332 builder: self.builder.property("receives-default", receives_default),
333 }
334 }
335
336 pub fn sensitive(self, sensitive: bool) -> Self {
337 Self {
338 builder: self.builder.property("sensitive", sensitive),
339 }
340 }
341
342 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
343 Self {
344 builder: self
345 .builder
346 .property("tooltip-markup", tooltip_markup.into()),
347 }
348 }
349
350 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
351 Self {
352 builder: self.builder.property("tooltip-text", tooltip_text.into()),
353 }
354 }
355
356 pub fn valign(self, valign: gtk::Align) -> Self {
357 Self {
358 builder: self.builder.property("valign", valign),
359 }
360 }
361
362 pub fn vexpand(self, vexpand: bool) -> Self {
363 Self {
364 builder: self.builder.property("vexpand", vexpand),
365 }
366 }
367
368 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
369 Self {
370 builder: self.builder.property("vexpand-set", vexpand_set),
371 }
372 }
373
374 pub fn visible(self, visible: bool) -> Self {
375 Self {
376 builder: self.builder.property("visible", visible),
377 }
378 }
379
380 pub fn width_request(self, width_request: i32) -> Self {
381 Self {
382 builder: self.builder.property("width-request", width_request),
383 }
384 }
385
386 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
387 Self {
388 builder: self.builder.property("accessible-role", accessible_role),
389 }
390 }
391
392 pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
393 Self {
394 builder: self.builder.property("action-name", action_name.into()),
395 }
396 }
397
398 pub fn action_target(self, action_target: &glib::Variant) -> Self {
399 Self {
400 builder: self
401 .builder
402 .property("action-target", action_target.clone()),
403 }
404 }
405
406 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
409 pub fn build(self) -> SwitchRow {
410 assert_initialized_main_thread!();
411 self.builder.build()
412 }
413}