1use crate::{ViewStack, 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 = "AdwViewSwitcherBar")]
16 pub struct ViewSwitcherBar(Object<ffi::AdwViewSwitcherBar, ffi::AdwViewSwitcherBarClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
17
18 match fn {
19 type_ => || ffi::adw_view_switcher_bar_get_type(),
20 }
21}
22
23impl ViewSwitcherBar {
24 #[doc(alias = "adw_view_switcher_bar_new")]
25 pub fn new() -> ViewSwitcherBar {
26 assert_initialized_main_thread!();
27 unsafe { gtk::Widget::from_glib_none(ffi::adw_view_switcher_bar_new()).unsafe_cast() }
28 }
29
30 pub fn builder() -> ViewSwitcherBarBuilder {
35 ViewSwitcherBarBuilder::new()
36 }
37
38 #[doc(alias = "adw_view_switcher_bar_get_reveal")]
39 #[doc(alias = "get_reveal")]
40 #[doc(alias = "reveal")]
41 pub fn reveals(&self) -> bool {
42 unsafe { from_glib(ffi::adw_view_switcher_bar_get_reveal(self.to_glib_none().0)) }
43 }
44
45 #[doc(alias = "adw_view_switcher_bar_get_stack")]
46 #[doc(alias = "get_stack")]
47 pub fn stack(&self) -> Option<ViewStack> {
48 unsafe { from_glib_none(ffi::adw_view_switcher_bar_get_stack(self.to_glib_none().0)) }
49 }
50
51 #[doc(alias = "adw_view_switcher_bar_set_reveal")]
52 #[doc(alias = "reveal")]
53 pub fn set_reveal(&self, reveal: bool) {
54 unsafe {
55 ffi::adw_view_switcher_bar_set_reveal(self.to_glib_none().0, reveal.into_glib());
56 }
57 }
58
59 #[doc(alias = "adw_view_switcher_bar_set_stack")]
60 #[doc(alias = "stack")]
61 pub fn set_stack(&self, stack: Option<&ViewStack>) {
62 unsafe {
63 ffi::adw_view_switcher_bar_set_stack(self.to_glib_none().0, stack.to_glib_none().0);
64 }
65 }
66
67 #[doc(alias = "reveal")]
68 pub fn connect_reveal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
69 unsafe extern "C" fn notify_reveal_trampoline<F: Fn(&ViewSwitcherBar) + 'static>(
70 this: *mut ffi::AdwViewSwitcherBar,
71 _param_spec: glib::ffi::gpointer,
72 f: glib::ffi::gpointer,
73 ) {
74 unsafe {
75 let f: &F = &*(f as *const F);
76 f(&from_glib_borrow(this))
77 }
78 }
79 unsafe {
80 let f: Box_<F> = Box_::new(f);
81 connect_raw(
82 self.as_ptr() as *mut _,
83 c"notify::reveal".as_ptr(),
84 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
85 notify_reveal_trampoline::<F> as *const (),
86 )),
87 Box_::into_raw(f),
88 )
89 }
90 }
91
92 #[doc(alias = "stack")]
93 pub fn connect_stack_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
94 unsafe extern "C" fn notify_stack_trampoline<F: Fn(&ViewSwitcherBar) + 'static>(
95 this: *mut ffi::AdwViewSwitcherBar,
96 _param_spec: glib::ffi::gpointer,
97 f: glib::ffi::gpointer,
98 ) {
99 unsafe {
100 let f: &F = &*(f as *const F);
101 f(&from_glib_borrow(this))
102 }
103 }
104 unsafe {
105 let f: Box_<F> = Box_::new(f);
106 connect_raw(
107 self.as_ptr() as *mut _,
108 c"notify::stack".as_ptr(),
109 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
110 notify_stack_trampoline::<F> as *const (),
111 )),
112 Box_::into_raw(f),
113 )
114 }
115 }
116}
117
118impl Default for ViewSwitcherBar {
119 fn default() -> Self {
120 Self::new()
121 }
122}
123
124#[must_use = "The builder must be built to be used"]
129pub struct ViewSwitcherBarBuilder {
130 builder: glib::object::ObjectBuilder<'static, ViewSwitcherBar>,
131}
132
133impl ViewSwitcherBarBuilder {
134 fn new() -> Self {
135 Self {
136 builder: glib::object::Object::builder(),
137 }
138 }
139
140 pub fn reveal(self, reveal: bool) -> Self {
141 Self {
142 builder: self.builder.property("reveal", reveal),
143 }
144 }
145
146 pub fn stack(self, stack: &ViewStack) -> Self {
147 Self {
148 builder: self.builder.property("stack", stack.clone()),
149 }
150 }
151
152 pub fn can_focus(self, can_focus: bool) -> Self {
153 Self {
154 builder: self.builder.property("can-focus", can_focus),
155 }
156 }
157
158 pub fn can_target(self, can_target: bool) -> Self {
159 Self {
160 builder: self.builder.property("can-target", can_target),
161 }
162 }
163
164 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
165 Self {
166 builder: self.builder.property("css-classes", css_classes.into()),
167 }
168 }
169
170 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
171 Self {
172 builder: self.builder.property("css-name", css_name.into()),
173 }
174 }
175
176 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
177 Self {
178 builder: self.builder.property("cursor", cursor.clone()),
179 }
180 }
181
182 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
183 Self {
184 builder: self.builder.property("focus-on-click", focus_on_click),
185 }
186 }
187
188 pub fn focusable(self, focusable: bool) -> Self {
189 Self {
190 builder: self.builder.property("focusable", focusable),
191 }
192 }
193
194 pub fn halign(self, halign: gtk::Align) -> Self {
195 Self {
196 builder: self.builder.property("halign", halign),
197 }
198 }
199
200 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
201 Self {
202 builder: self.builder.property("has-tooltip", has_tooltip),
203 }
204 }
205
206 pub fn height_request(self, height_request: i32) -> Self {
207 Self {
208 builder: self.builder.property("height-request", height_request),
209 }
210 }
211
212 pub fn hexpand(self, hexpand: bool) -> Self {
213 Self {
214 builder: self.builder.property("hexpand", hexpand),
215 }
216 }
217
218 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
219 Self {
220 builder: self.builder.property("hexpand-set", hexpand_set),
221 }
222 }
223
224 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
225 Self {
226 builder: self
227 .builder
228 .property("layout-manager", layout_manager.clone().upcast()),
229 }
230 }
231
232 #[cfg(feature = "gtk_v4_18")]
233 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
234 pub fn limit_events(self, limit_events: bool) -> Self {
235 Self {
236 builder: self.builder.property("limit-events", limit_events),
237 }
238 }
239
240 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
241 Self {
242 builder: self.builder.property("margin-bottom", margin_bottom),
243 }
244 }
245
246 pub fn margin_end(self, margin_end: i32) -> Self {
247 Self {
248 builder: self.builder.property("margin-end", margin_end),
249 }
250 }
251
252 pub fn margin_start(self, margin_start: i32) -> Self {
253 Self {
254 builder: self.builder.property("margin-start", margin_start),
255 }
256 }
257
258 pub fn margin_top(self, margin_top: i32) -> Self {
259 Self {
260 builder: self.builder.property("margin-top", margin_top),
261 }
262 }
263
264 pub fn name(self, name: impl Into<glib::GString>) -> Self {
265 Self {
266 builder: self.builder.property("name", name.into()),
267 }
268 }
269
270 pub fn opacity(self, opacity: f64) -> Self {
271 Self {
272 builder: self.builder.property("opacity", opacity),
273 }
274 }
275
276 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
277 Self {
278 builder: self.builder.property("overflow", overflow),
279 }
280 }
281
282 pub fn receives_default(self, receives_default: bool) -> Self {
283 Self {
284 builder: self.builder.property("receives-default", receives_default),
285 }
286 }
287
288 pub fn sensitive(self, sensitive: bool) -> Self {
289 Self {
290 builder: self.builder.property("sensitive", sensitive),
291 }
292 }
293
294 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
295 Self {
296 builder: self
297 .builder
298 .property("tooltip-markup", tooltip_markup.into()),
299 }
300 }
301
302 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
303 Self {
304 builder: self.builder.property("tooltip-text", tooltip_text.into()),
305 }
306 }
307
308 pub fn valign(self, valign: gtk::Align) -> Self {
309 Self {
310 builder: self.builder.property("valign", valign),
311 }
312 }
313
314 pub fn vexpand(self, vexpand: bool) -> Self {
315 Self {
316 builder: self.builder.property("vexpand", vexpand),
317 }
318 }
319
320 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
321 Self {
322 builder: self.builder.property("vexpand-set", vexpand_set),
323 }
324 }
325
326 pub fn visible(self, visible: bool) -> Self {
327 Self {
328 builder: self.builder.property("visible", visible),
329 }
330 }
331
332 pub fn width_request(self, width_request: i32) -> Self {
333 Self {
334 builder: self.builder.property("width-request", width_request),
335 }
336 }
337
338 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
339 Self {
340 builder: self.builder.property("accessible-role", accessible_role),
341 }
342 }
343
344 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
347 pub fn build(self) -> ViewSwitcherBar {
348 assert_initialized_main_thread!();
349 self.builder.build()
350 }
351}