1use crate::{ffi, SidebarMode, ViewStack};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 #[doc(alias = "AdwViewSwitcherSidebar")]
17 pub struct ViewSwitcherSidebar(Object<ffi::AdwViewSwitcherSidebar, ffi::AdwViewSwitcherSidebarClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
18
19 match fn {
20 type_ => || ffi::adw_view_switcher_sidebar_get_type(),
21 }
22}
23
24impl ViewSwitcherSidebar {
25 #[doc(alias = "adw_view_switcher_sidebar_new")]
26 pub fn new() -> ViewSwitcherSidebar {
27 assert_initialized_main_thread!();
28 unsafe { gtk::Widget::from_glib_none(ffi::adw_view_switcher_sidebar_new()).unsafe_cast() }
29 }
30
31 pub fn builder() -> ViewSwitcherSidebarBuilder {
36 ViewSwitcherSidebarBuilder::new()
37 }
38
39 #[doc(alias = "adw_view_switcher_sidebar_get_filter")]
40 #[doc(alias = "get_filter")]
41 pub fn filter(&self) -> Option<gtk::Filter> {
42 unsafe {
43 from_glib_none(ffi::adw_view_switcher_sidebar_get_filter(
44 self.to_glib_none().0,
45 ))
46 }
47 }
48
49 #[doc(alias = "adw_view_switcher_sidebar_get_mode")]
50 #[doc(alias = "get_mode")]
51 pub fn mode(&self) -> SidebarMode {
52 unsafe {
53 from_glib(ffi::adw_view_switcher_sidebar_get_mode(
54 self.to_glib_none().0,
55 ))
56 }
57 }
58
59 #[doc(alias = "adw_view_switcher_sidebar_get_placeholder")]
60 #[doc(alias = "get_placeholder")]
61 pub fn placeholder(&self) -> Option<gtk::Widget> {
62 unsafe {
63 from_glib_none(ffi::adw_view_switcher_sidebar_get_placeholder(
64 self.to_glib_none().0,
65 ))
66 }
67 }
68
69 #[doc(alias = "adw_view_switcher_sidebar_get_stack")]
70 #[doc(alias = "get_stack")]
71 pub fn stack(&self) -> Option<ViewStack> {
72 unsafe {
73 from_glib_none(ffi::adw_view_switcher_sidebar_get_stack(
74 self.to_glib_none().0,
75 ))
76 }
77 }
78
79 #[doc(alias = "adw_view_switcher_sidebar_set_filter")]
80 #[doc(alias = "filter")]
81 pub fn set_filter(&self, filter: Option<&impl IsA<gtk::Filter>>) {
82 unsafe {
83 ffi::adw_view_switcher_sidebar_set_filter(
84 self.to_glib_none().0,
85 filter.map(|p| p.as_ref()).to_glib_none().0,
86 );
87 }
88 }
89
90 #[doc(alias = "adw_view_switcher_sidebar_set_mode")]
91 #[doc(alias = "mode")]
92 pub fn set_mode(&self, mode: SidebarMode) {
93 unsafe {
94 ffi::adw_view_switcher_sidebar_set_mode(self.to_glib_none().0, mode.into_glib());
95 }
96 }
97
98 #[doc(alias = "adw_view_switcher_sidebar_set_placeholder")]
99 #[doc(alias = "placeholder")]
100 pub fn set_placeholder(&self, placeholder: Option<&impl IsA<gtk::Widget>>) {
101 unsafe {
102 ffi::adw_view_switcher_sidebar_set_placeholder(
103 self.to_glib_none().0,
104 placeholder.map(|p| p.as_ref()).to_glib_none().0,
105 );
106 }
107 }
108
109 #[doc(alias = "adw_view_switcher_sidebar_set_stack")]
110 #[doc(alias = "stack")]
111 pub fn set_stack(&self, stack: Option<&ViewStack>) {
112 unsafe {
113 ffi::adw_view_switcher_sidebar_set_stack(self.to_glib_none().0, stack.to_glib_none().0);
114 }
115 }
116
117 #[cfg(feature = "v1_9")]
118 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
119 #[doc(alias = "activated")]
120 pub fn connect_activated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
121 unsafe extern "C" fn activated_trampoline<F: Fn(&ViewSwitcherSidebar) + 'static>(
122 this: *mut ffi::AdwViewSwitcherSidebar,
123 f: glib::ffi::gpointer,
124 ) {
125 let f: &F = &*(f as *const F);
126 f(&from_glib_borrow(this))
127 }
128 unsafe {
129 let f: Box_<F> = Box_::new(f);
130 connect_raw(
131 self.as_ptr() as *mut _,
132 c"activated".as_ptr() as *const _,
133 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
134 activated_trampoline::<F> as *const (),
135 )),
136 Box_::into_raw(f),
137 )
138 }
139 }
140
141 #[cfg(feature = "v1_9")]
142 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
143 #[doc(alias = "filter")]
144 pub fn connect_filter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
145 unsafe extern "C" fn notify_filter_trampoline<F: Fn(&ViewSwitcherSidebar) + 'static>(
146 this: *mut ffi::AdwViewSwitcherSidebar,
147 _param_spec: glib::ffi::gpointer,
148 f: glib::ffi::gpointer,
149 ) {
150 let f: &F = &*(f as *const F);
151 f(&from_glib_borrow(this))
152 }
153 unsafe {
154 let f: Box_<F> = Box_::new(f);
155 connect_raw(
156 self.as_ptr() as *mut _,
157 c"notify::filter".as_ptr() as *const _,
158 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
159 notify_filter_trampoline::<F> as *const (),
160 )),
161 Box_::into_raw(f),
162 )
163 }
164 }
165
166 #[cfg(feature = "v1_9")]
167 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
168 #[doc(alias = "mode")]
169 pub fn connect_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
170 unsafe extern "C" fn notify_mode_trampoline<F: Fn(&ViewSwitcherSidebar) + 'static>(
171 this: *mut ffi::AdwViewSwitcherSidebar,
172 _param_spec: glib::ffi::gpointer,
173 f: glib::ffi::gpointer,
174 ) {
175 let f: &F = &*(f as *const F);
176 f(&from_glib_borrow(this))
177 }
178 unsafe {
179 let f: Box_<F> = Box_::new(f);
180 connect_raw(
181 self.as_ptr() as *mut _,
182 c"notify::mode".as_ptr() as *const _,
183 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
184 notify_mode_trampoline::<F> as *const (),
185 )),
186 Box_::into_raw(f),
187 )
188 }
189 }
190
191 #[cfg(feature = "v1_9")]
192 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
193 #[doc(alias = "placeholder")]
194 pub fn connect_placeholder_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
195 unsafe extern "C" fn notify_placeholder_trampoline<
196 F: Fn(&ViewSwitcherSidebar) + 'static,
197 >(
198 this: *mut ffi::AdwViewSwitcherSidebar,
199 _param_spec: glib::ffi::gpointer,
200 f: glib::ffi::gpointer,
201 ) {
202 let f: &F = &*(f as *const F);
203 f(&from_glib_borrow(this))
204 }
205 unsafe {
206 let f: Box_<F> = Box_::new(f);
207 connect_raw(
208 self.as_ptr() as *mut _,
209 c"notify::placeholder".as_ptr() as *const _,
210 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
211 notify_placeholder_trampoline::<F> as *const (),
212 )),
213 Box_::into_raw(f),
214 )
215 }
216 }
217
218 #[cfg(feature = "v1_9")]
219 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
220 #[doc(alias = "stack")]
221 pub fn connect_stack_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
222 unsafe extern "C" fn notify_stack_trampoline<F: Fn(&ViewSwitcherSidebar) + 'static>(
223 this: *mut ffi::AdwViewSwitcherSidebar,
224 _param_spec: glib::ffi::gpointer,
225 f: glib::ffi::gpointer,
226 ) {
227 let f: &F = &*(f as *const F);
228 f(&from_glib_borrow(this))
229 }
230 unsafe {
231 let f: Box_<F> = Box_::new(f);
232 connect_raw(
233 self.as_ptr() as *mut _,
234 c"notify::stack".as_ptr() as *const _,
235 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236 notify_stack_trampoline::<F> as *const (),
237 )),
238 Box_::into_raw(f),
239 )
240 }
241 }
242}
243
244#[cfg(feature = "v1_9")]
245#[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
246impl Default for ViewSwitcherSidebar {
247 fn default() -> Self {
248 Self::new()
249 }
250}
251
252#[must_use = "The builder must be built to be used"]
257pub struct ViewSwitcherSidebarBuilder {
258 builder: glib::object::ObjectBuilder<'static, ViewSwitcherSidebar>,
259}
260
261impl ViewSwitcherSidebarBuilder {
262 fn new() -> Self {
263 Self {
264 builder: glib::object::Object::builder(),
265 }
266 }
267
268 #[cfg(feature = "v1_9")]
269 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
270 pub fn filter(self, filter: &impl IsA<gtk::Filter>) -> Self {
271 Self {
272 builder: self.builder.property("filter", filter.clone().upcast()),
273 }
274 }
275
276 #[cfg(feature = "v1_9")]
277 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
278 pub fn mode(self, mode: SidebarMode) -> Self {
279 Self {
280 builder: self.builder.property("mode", mode),
281 }
282 }
283
284 #[cfg(feature = "v1_9")]
285 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
286 pub fn placeholder(self, placeholder: &impl IsA<gtk::Widget>) -> Self {
287 Self {
288 builder: self
289 .builder
290 .property("placeholder", placeholder.clone().upcast()),
291 }
292 }
293
294 #[cfg(feature = "v1_9")]
295 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
296 pub fn stack(self, stack: &ViewStack) -> Self {
297 Self {
298 builder: self.builder.property("stack", stack.clone()),
299 }
300 }
301
302 pub fn can_focus(self, can_focus: bool) -> Self {
303 Self {
304 builder: self.builder.property("can-focus", can_focus),
305 }
306 }
307
308 pub fn can_target(self, can_target: bool) -> Self {
309 Self {
310 builder: self.builder.property("can-target", can_target),
311 }
312 }
313
314 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
315 Self {
316 builder: self.builder.property("css-classes", css_classes.into()),
317 }
318 }
319
320 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
321 Self {
322 builder: self.builder.property("css-name", css_name.into()),
323 }
324 }
325
326 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
327 Self {
328 builder: self.builder.property("cursor", cursor.clone()),
329 }
330 }
331
332 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
333 Self {
334 builder: self.builder.property("focus-on-click", focus_on_click),
335 }
336 }
337
338 pub fn focusable(self, focusable: bool) -> Self {
339 Self {
340 builder: self.builder.property("focusable", focusable),
341 }
342 }
343
344 pub fn halign(self, halign: gtk::Align) -> Self {
345 Self {
346 builder: self.builder.property("halign", halign),
347 }
348 }
349
350 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
351 Self {
352 builder: self.builder.property("has-tooltip", has_tooltip),
353 }
354 }
355
356 pub fn height_request(self, height_request: i32) -> Self {
357 Self {
358 builder: self.builder.property("height-request", height_request),
359 }
360 }
361
362 pub fn hexpand(self, hexpand: bool) -> Self {
363 Self {
364 builder: self.builder.property("hexpand", hexpand),
365 }
366 }
367
368 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
369 Self {
370 builder: self.builder.property("hexpand-set", hexpand_set),
371 }
372 }
373
374 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
375 Self {
376 builder: self
377 .builder
378 .property("layout-manager", layout_manager.clone().upcast()),
379 }
380 }
381
382 #[cfg(feature = "gtk_v4_18")]
383 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
384 pub fn limit_events(self, limit_events: bool) -> Self {
385 Self {
386 builder: self.builder.property("limit-events", limit_events),
387 }
388 }
389
390 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
391 Self {
392 builder: self.builder.property("margin-bottom", margin_bottom),
393 }
394 }
395
396 pub fn margin_end(self, margin_end: i32) -> Self {
397 Self {
398 builder: self.builder.property("margin-end", margin_end),
399 }
400 }
401
402 pub fn margin_start(self, margin_start: i32) -> Self {
403 Self {
404 builder: self.builder.property("margin-start", margin_start),
405 }
406 }
407
408 pub fn margin_top(self, margin_top: i32) -> Self {
409 Self {
410 builder: self.builder.property("margin-top", margin_top),
411 }
412 }
413
414 pub fn name(self, name: impl Into<glib::GString>) -> Self {
415 Self {
416 builder: self.builder.property("name", name.into()),
417 }
418 }
419
420 pub fn opacity(self, opacity: f64) -> Self {
421 Self {
422 builder: self.builder.property("opacity", opacity),
423 }
424 }
425
426 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
427 Self {
428 builder: self.builder.property("overflow", overflow),
429 }
430 }
431
432 pub fn receives_default(self, receives_default: bool) -> Self {
433 Self {
434 builder: self.builder.property("receives-default", receives_default),
435 }
436 }
437
438 pub fn sensitive(self, sensitive: bool) -> Self {
439 Self {
440 builder: self.builder.property("sensitive", sensitive),
441 }
442 }
443
444 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
445 Self {
446 builder: self
447 .builder
448 .property("tooltip-markup", tooltip_markup.into()),
449 }
450 }
451
452 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
453 Self {
454 builder: self.builder.property("tooltip-text", tooltip_text.into()),
455 }
456 }
457
458 pub fn valign(self, valign: gtk::Align) -> Self {
459 Self {
460 builder: self.builder.property("valign", valign),
461 }
462 }
463
464 pub fn vexpand(self, vexpand: bool) -> Self {
465 Self {
466 builder: self.builder.property("vexpand", vexpand),
467 }
468 }
469
470 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
471 Self {
472 builder: self.builder.property("vexpand-set", vexpand_set),
473 }
474 }
475
476 pub fn visible(self, visible: bool) -> Self {
477 Self {
478 builder: self.builder.property("visible", visible),
479 }
480 }
481
482 pub fn width_request(self, width_request: i32) -> Self {
483 Self {
484 builder: self.builder.property("width-request", width_request),
485 }
486 }
487
488 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
489 Self {
490 builder: self.builder.property("accessible-role", accessible_role),
491 }
492 }
493
494 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
497 pub fn build(self) -> ViewSwitcherSidebar {
498 assert_initialized_main_thread!();
499 self.builder.build()
500 }
501}