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