1use crate::ffi;
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "AdwPreferencesGroup")]
16 pub struct PreferencesGroup(Object<ffi::AdwPreferencesGroup, ffi::AdwPreferencesGroupClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
17
18 match fn {
19 type_ => || ffi::adw_preferences_group_get_type(),
20 }
21}
22
23impl PreferencesGroup {
24 pub const NONE: Option<&'static PreferencesGroup> = None;
25
26 #[doc(alias = "adw_preferences_group_new")]
27 pub fn new() -> PreferencesGroup {
28 assert_initialized_main_thread!();
29 unsafe { gtk::Widget::from_glib_none(ffi::adw_preferences_group_new()).unsafe_cast() }
30 }
31
32 pub fn builder() -> PreferencesGroupBuilder {
37 PreferencesGroupBuilder::new()
38 }
39}
40
41impl Default for PreferencesGroup {
42 fn default() -> Self {
43 Self::new()
44 }
45}
46
47#[must_use = "The builder must be built to be used"]
52pub struct PreferencesGroupBuilder {
53 builder: glib::object::ObjectBuilder<'static, PreferencesGroup>,
54}
55
56impl PreferencesGroupBuilder {
57 fn new() -> Self {
58 Self {
59 builder: glib::object::Object::builder(),
60 }
61 }
62
63 pub fn description(self, description: impl Into<glib::GString>) -> Self {
64 Self {
65 builder: self.builder.property("description", description.into()),
66 }
67 }
68
69 #[cfg(feature = "v1_1")]
70 #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
71 pub fn header_suffix(self, header_suffix: &impl IsA<gtk::Widget>) -> Self {
72 Self {
73 builder: self
74 .builder
75 .property("header-suffix", header_suffix.clone().upcast()),
76 }
77 }
78
79 #[cfg(feature = "v1_6")]
80 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
81 pub fn separate_rows(self, separate_rows: bool) -> Self {
82 Self {
83 builder: self.builder.property("separate-rows", separate_rows),
84 }
85 }
86
87 pub fn title(self, title: impl Into<glib::GString>) -> Self {
88 Self {
89 builder: self.builder.property("title", title.into()),
90 }
91 }
92
93 pub fn can_focus(self, can_focus: bool) -> Self {
94 Self {
95 builder: self.builder.property("can-focus", can_focus),
96 }
97 }
98
99 pub fn can_target(self, can_target: bool) -> Self {
100 Self {
101 builder: self.builder.property("can-target", can_target),
102 }
103 }
104
105 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
106 Self {
107 builder: self.builder.property("css-classes", css_classes.into()),
108 }
109 }
110
111 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
112 Self {
113 builder: self.builder.property("css-name", css_name.into()),
114 }
115 }
116
117 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
118 Self {
119 builder: self.builder.property("cursor", cursor.clone()),
120 }
121 }
122
123 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
124 Self {
125 builder: self.builder.property("focus-on-click", focus_on_click),
126 }
127 }
128
129 pub fn focusable(self, focusable: bool) -> Self {
130 Self {
131 builder: self.builder.property("focusable", focusable),
132 }
133 }
134
135 pub fn halign(self, halign: gtk::Align) -> Self {
136 Self {
137 builder: self.builder.property("halign", halign),
138 }
139 }
140
141 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
142 Self {
143 builder: self.builder.property("has-tooltip", has_tooltip),
144 }
145 }
146
147 pub fn height_request(self, height_request: i32) -> Self {
148 Self {
149 builder: self.builder.property("height-request", height_request),
150 }
151 }
152
153 pub fn hexpand(self, hexpand: bool) -> Self {
154 Self {
155 builder: self.builder.property("hexpand", hexpand),
156 }
157 }
158
159 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
160 Self {
161 builder: self.builder.property("hexpand-set", hexpand_set),
162 }
163 }
164
165 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
166 Self {
167 builder: self
168 .builder
169 .property("layout-manager", layout_manager.clone().upcast()),
170 }
171 }
172
173 #[cfg(feature = "gtk_v4_18")]
174 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
175 pub fn limit_events(self, limit_events: bool) -> Self {
176 Self {
177 builder: self.builder.property("limit-events", limit_events),
178 }
179 }
180
181 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
182 Self {
183 builder: self.builder.property("margin-bottom", margin_bottom),
184 }
185 }
186
187 pub fn margin_end(self, margin_end: i32) -> Self {
188 Self {
189 builder: self.builder.property("margin-end", margin_end),
190 }
191 }
192
193 pub fn margin_start(self, margin_start: i32) -> Self {
194 Self {
195 builder: self.builder.property("margin-start", margin_start),
196 }
197 }
198
199 pub fn margin_top(self, margin_top: i32) -> Self {
200 Self {
201 builder: self.builder.property("margin-top", margin_top),
202 }
203 }
204
205 pub fn name(self, name: impl Into<glib::GString>) -> Self {
206 Self {
207 builder: self.builder.property("name", name.into()),
208 }
209 }
210
211 pub fn opacity(self, opacity: f64) -> Self {
212 Self {
213 builder: self.builder.property("opacity", opacity),
214 }
215 }
216
217 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
218 Self {
219 builder: self.builder.property("overflow", overflow),
220 }
221 }
222
223 pub fn receives_default(self, receives_default: bool) -> Self {
224 Self {
225 builder: self.builder.property("receives-default", receives_default),
226 }
227 }
228
229 pub fn sensitive(self, sensitive: bool) -> Self {
230 Self {
231 builder: self.builder.property("sensitive", sensitive),
232 }
233 }
234
235 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
236 Self {
237 builder: self
238 .builder
239 .property("tooltip-markup", tooltip_markup.into()),
240 }
241 }
242
243 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
244 Self {
245 builder: self.builder.property("tooltip-text", tooltip_text.into()),
246 }
247 }
248
249 pub fn valign(self, valign: gtk::Align) -> Self {
250 Self {
251 builder: self.builder.property("valign", valign),
252 }
253 }
254
255 pub fn vexpand(self, vexpand: bool) -> Self {
256 Self {
257 builder: self.builder.property("vexpand", vexpand),
258 }
259 }
260
261 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
262 Self {
263 builder: self.builder.property("vexpand-set", vexpand_set),
264 }
265 }
266
267 pub fn visible(self, visible: bool) -> Self {
268 Self {
269 builder: self.builder.property("visible", visible),
270 }
271 }
272
273 pub fn width_request(self, width_request: i32) -> Self {
274 Self {
275 builder: self.builder.property("width-request", width_request),
276 }
277 }
278
279 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
280 Self {
281 builder: self.builder.property("accessible-role", accessible_role),
282 }
283 }
284
285 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
288 pub fn build(self) -> PreferencesGroup {
289 assert_initialized_main_thread!();
290 self.builder.build()
291 }
292}
293
294pub trait PreferencesGroupExt: IsA<PreferencesGroup> + 'static {
295 #[doc(alias = "adw_preferences_group_add")]
296 fn add(&self, child: &impl IsA<gtk::Widget>) {
297 unsafe {
298 ffi::adw_preferences_group_add(
299 self.as_ref().to_glib_none().0,
300 child.as_ref().to_glib_none().0,
301 );
302 }
303 }
304
305 #[cfg(feature = "v1_8")]
306 #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
307 #[doc(alias = "adw_preferences_group_bind_model")]
308 fn bind_model(
309 &self,
310 model: Option<&impl IsA<gio::ListModel>>,
311 create_row_func: Option<Box_<dyn Fn(&glib::Object) -> gtk::Widget + 'static>>,
312 ) {
313 let create_row_func_data: Box_<
314 Option<Box_<dyn Fn(&glib::Object) -> gtk::Widget + 'static>>,
315 > = Box_::new(create_row_func);
316 unsafe extern "C" fn create_row_func_func(
317 item: *mut glib::gobject_ffi::GObject,
318 user_data: glib::ffi::gpointer,
319 ) -> *mut gtk::ffi::GtkWidget {
320 let item = from_glib_borrow(item);
321 let callback =
322 &*(user_data as *mut Option<Box_<dyn Fn(&glib::Object) -> gtk::Widget + 'static>>);
323 if let Some(ref callback) = *callback {
324 callback(&item)
325 } else {
326 panic!("cannot get closure...")
327 }
328 .to_glib_full()
329 }
330 let create_row_func = if create_row_func_data.is_some() {
331 Some(create_row_func_func as _)
332 } else {
333 None
334 };
335 unsafe extern "C" fn user_data_free_func_func(data: glib::ffi::gpointer) {
336 let _callback = Box_::from_raw(
337 data as *mut Option<Box_<dyn Fn(&glib::Object) -> gtk::Widget + 'static>>,
338 );
339 }
340 let destroy_call4 = Some(user_data_free_func_func as _);
341 let super_callback0: Box_<Option<Box_<dyn Fn(&glib::Object) -> gtk::Widget + 'static>>> =
342 create_row_func_data;
343 unsafe {
344 ffi::adw_preferences_group_bind_model(
345 self.as_ref().to_glib_none().0,
346 model.map(|p| p.as_ref()).to_glib_none().0,
347 create_row_func,
348 Box_::into_raw(super_callback0) as *mut _,
349 destroy_call4,
350 );
351 }
352 }
353
354 #[doc(alias = "adw_preferences_group_get_description")]
355 #[doc(alias = "get_description")]
356 fn description(&self) -> Option<glib::GString> {
357 unsafe {
358 from_glib_none(ffi::adw_preferences_group_get_description(
359 self.as_ref().to_glib_none().0,
360 ))
361 }
362 }
363
364 #[cfg(feature = "v1_1")]
365 #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
366 #[doc(alias = "adw_preferences_group_get_header_suffix")]
367 #[doc(alias = "get_header_suffix")]
368 #[doc(alias = "header-suffix")]
369 fn header_suffix(&self) -> Option<gtk::Widget> {
370 unsafe {
371 from_glib_none(ffi::adw_preferences_group_get_header_suffix(
372 self.as_ref().to_glib_none().0,
373 ))
374 }
375 }
376
377 #[cfg(feature = "v1_8")]
378 #[cfg_attr(docsrs, doc(cfg(feature = "v1_8")))]
379 #[doc(alias = "adw_preferences_group_get_row")]
380 #[doc(alias = "get_row")]
381 fn row(&self, index: u32) -> Option<gtk::Widget> {
382 unsafe {
383 from_glib_none(ffi::adw_preferences_group_get_row(
384 self.as_ref().to_glib_none().0,
385 index,
386 ))
387 }
388 }
389
390 #[cfg(feature = "v1_6")]
391 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
392 #[doc(alias = "adw_preferences_group_get_separate_rows")]
393 #[doc(alias = "get_separate_rows")]
394 #[doc(alias = "separate-rows")]
395 fn is_separate_rows(&self) -> bool {
396 unsafe {
397 from_glib(ffi::adw_preferences_group_get_separate_rows(
398 self.as_ref().to_glib_none().0,
399 ))
400 }
401 }
402
403 #[doc(alias = "adw_preferences_group_get_title")]
404 #[doc(alias = "get_title")]
405 fn title(&self) -> glib::GString {
406 unsafe {
407 from_glib_none(ffi::adw_preferences_group_get_title(
408 self.as_ref().to_glib_none().0,
409 ))
410 }
411 }
412
413 #[doc(alias = "adw_preferences_group_remove")]
414 fn remove(&self, child: &impl IsA<gtk::Widget>) {
415 unsafe {
416 ffi::adw_preferences_group_remove(
417 self.as_ref().to_glib_none().0,
418 child.as_ref().to_glib_none().0,
419 );
420 }
421 }
422
423 #[doc(alias = "adw_preferences_group_set_description")]
424 #[doc(alias = "description")]
425 fn set_description(&self, description: Option<&str>) {
426 unsafe {
427 ffi::adw_preferences_group_set_description(
428 self.as_ref().to_glib_none().0,
429 description.to_glib_none().0,
430 );
431 }
432 }
433
434 #[cfg(feature = "v1_1")]
435 #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
436 #[doc(alias = "adw_preferences_group_set_header_suffix")]
437 #[doc(alias = "header-suffix")]
438 fn set_header_suffix(&self, suffix: Option<&impl IsA<gtk::Widget>>) {
439 unsafe {
440 ffi::adw_preferences_group_set_header_suffix(
441 self.as_ref().to_glib_none().0,
442 suffix.map(|p| p.as_ref()).to_glib_none().0,
443 );
444 }
445 }
446
447 #[cfg(feature = "v1_6")]
448 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
449 #[doc(alias = "adw_preferences_group_set_separate_rows")]
450 #[doc(alias = "separate-rows")]
451 fn set_separate_rows(&self, separate_rows: bool) {
452 unsafe {
453 ffi::adw_preferences_group_set_separate_rows(
454 self.as_ref().to_glib_none().0,
455 separate_rows.into_glib(),
456 );
457 }
458 }
459
460 #[doc(alias = "adw_preferences_group_set_title")]
461 #[doc(alias = "title")]
462 fn set_title(&self, title: &str) {
463 unsafe {
464 ffi::adw_preferences_group_set_title(
465 self.as_ref().to_glib_none().0,
466 title.to_glib_none().0,
467 );
468 }
469 }
470
471 #[doc(alias = "description")]
472 fn connect_description_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
473 unsafe extern "C" fn notify_description_trampoline<
474 P: IsA<PreferencesGroup>,
475 F: Fn(&P) + 'static,
476 >(
477 this: *mut ffi::AdwPreferencesGroup,
478 _param_spec: glib::ffi::gpointer,
479 f: glib::ffi::gpointer,
480 ) {
481 let f: &F = &*(f as *const F);
482 f(PreferencesGroup::from_glib_borrow(this).unsafe_cast_ref())
483 }
484 unsafe {
485 let f: Box_<F> = Box_::new(f);
486 connect_raw(
487 self.as_ptr() as *mut _,
488 c"notify::description".as_ptr() as *const _,
489 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
490 notify_description_trampoline::<Self, F> as *const (),
491 )),
492 Box_::into_raw(f),
493 )
494 }
495 }
496
497 #[cfg(feature = "v1_1")]
498 #[cfg_attr(docsrs, doc(cfg(feature = "v1_1")))]
499 #[doc(alias = "header-suffix")]
500 fn connect_header_suffix_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
501 unsafe extern "C" fn notify_header_suffix_trampoline<
502 P: IsA<PreferencesGroup>,
503 F: Fn(&P) + 'static,
504 >(
505 this: *mut ffi::AdwPreferencesGroup,
506 _param_spec: glib::ffi::gpointer,
507 f: glib::ffi::gpointer,
508 ) {
509 let f: &F = &*(f as *const F);
510 f(PreferencesGroup::from_glib_borrow(this).unsafe_cast_ref())
511 }
512 unsafe {
513 let f: Box_<F> = Box_::new(f);
514 connect_raw(
515 self.as_ptr() as *mut _,
516 c"notify::header-suffix".as_ptr() as *const _,
517 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
518 notify_header_suffix_trampoline::<Self, F> as *const (),
519 )),
520 Box_::into_raw(f),
521 )
522 }
523 }
524
525 #[cfg(feature = "v1_6")]
526 #[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
527 #[doc(alias = "separate-rows")]
528 fn connect_separate_rows_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
529 unsafe extern "C" fn notify_separate_rows_trampoline<
530 P: IsA<PreferencesGroup>,
531 F: Fn(&P) + 'static,
532 >(
533 this: *mut ffi::AdwPreferencesGroup,
534 _param_spec: glib::ffi::gpointer,
535 f: glib::ffi::gpointer,
536 ) {
537 let f: &F = &*(f as *const F);
538 f(PreferencesGroup::from_glib_borrow(this).unsafe_cast_ref())
539 }
540 unsafe {
541 let f: Box_<F> = Box_::new(f);
542 connect_raw(
543 self.as_ptr() as *mut _,
544 c"notify::separate-rows".as_ptr() as *const _,
545 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
546 notify_separate_rows_trampoline::<Self, F> as *const (),
547 )),
548 Box_::into_raw(f),
549 )
550 }
551 }
552
553 #[doc(alias = "title")]
554 fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
555 unsafe extern "C" fn notify_title_trampoline<
556 P: IsA<PreferencesGroup>,
557 F: Fn(&P) + 'static,
558 >(
559 this: *mut ffi::AdwPreferencesGroup,
560 _param_spec: glib::ffi::gpointer,
561 f: glib::ffi::gpointer,
562 ) {
563 let f: &F = &*(f as *const F);
564 f(PreferencesGroup::from_glib_borrow(this).unsafe_cast_ref())
565 }
566 unsafe {
567 let f: Box_<F> = Box_::new(f);
568 connect_raw(
569 self.as_ptr() as *mut _,
570 c"notify::title".as_ptr() as *const _,
571 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
572 notify_title_trampoline::<Self, F> as *const (),
573 )),
574 Box_::into_raw(f),
575 )
576 }
577 }
578}
579
580impl<O: IsA<PreferencesGroup>> PreferencesGroupExt for O {}