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