1use crate::ffi;
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 = "AdwNavigationPage")]
17 pub struct NavigationPage(Object<ffi::AdwNavigationPage, ffi::AdwNavigationPageClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
18
19 match fn {
20 type_ => || ffi::adw_navigation_page_get_type(),
21 }
22}
23
24impl NavigationPage {
25 pub const NONE: Option<&'static NavigationPage> = None;
26
27 #[doc(alias = "adw_navigation_page_new")]
28 pub fn new(child: &impl IsA<gtk::Widget>, title: &str) -> NavigationPage {
29 assert_initialized_main_thread!();
30 unsafe {
31 from_glib_none(ffi::adw_navigation_page_new(
32 child.as_ref().to_glib_none().0,
33 title.to_glib_none().0,
34 ))
35 }
36 }
37
38 #[doc(alias = "adw_navigation_page_new_with_tag")]
39 #[doc(alias = "new_with_tag")]
40 pub fn with_tag(child: &impl IsA<gtk::Widget>, title: &str, tag: &str) -> NavigationPage {
41 assert_initialized_main_thread!();
42 unsafe {
43 from_glib_none(ffi::adw_navigation_page_new_with_tag(
44 child.as_ref().to_glib_none().0,
45 title.to_glib_none().0,
46 tag.to_glib_none().0,
47 ))
48 }
49 }
50
51 pub fn builder() -> NavigationPageBuilder {
56 NavigationPageBuilder::new()
57 }
58}
59
60#[cfg(feature = "v1_4")]
61#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
62impl Default for NavigationPage {
63 fn default() -> Self {
64 glib::object::Object::new::<Self>()
65 }
66}
67
68#[must_use = "The builder must be built to be used"]
73pub struct NavigationPageBuilder {
74 builder: glib::object::ObjectBuilder<'static, NavigationPage>,
75}
76
77impl NavigationPageBuilder {
78 fn new() -> Self {
79 Self {
80 builder: glib::object::Object::builder(),
81 }
82 }
83
84 #[cfg(feature = "v1_4")]
85 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
86 pub fn can_pop(self, can_pop: bool) -> Self {
87 Self {
88 builder: self.builder.property("can-pop", can_pop),
89 }
90 }
91
92 #[cfg(feature = "v1_4")]
93 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
94 pub fn child(self, child: &impl IsA<gtk::Widget>) -> Self {
95 Self {
96 builder: self.builder.property("child", child.clone().upcast()),
97 }
98 }
99
100 #[cfg(feature = "v1_4")]
101 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
102 pub fn tag(self, tag: impl Into<glib::GString>) -> Self {
103 Self {
104 builder: self.builder.property("tag", tag.into()),
105 }
106 }
107
108 #[cfg(feature = "v1_4")]
109 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
110 pub fn title(self, title: impl Into<glib::GString>) -> Self {
111 Self {
112 builder: self.builder.property("title", title.into()),
113 }
114 }
115
116 pub fn can_focus(self, can_focus: bool) -> Self {
117 Self {
118 builder: self.builder.property("can-focus", can_focus),
119 }
120 }
121
122 pub fn can_target(self, can_target: bool) -> Self {
123 Self {
124 builder: self.builder.property("can-target", can_target),
125 }
126 }
127
128 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
129 Self {
130 builder: self.builder.property("css-classes", css_classes.into()),
131 }
132 }
133
134 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
135 Self {
136 builder: self.builder.property("css-name", css_name.into()),
137 }
138 }
139
140 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
141 Self {
142 builder: self.builder.property("cursor", cursor.clone()),
143 }
144 }
145
146 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
147 Self {
148 builder: self.builder.property("focus-on-click", focus_on_click),
149 }
150 }
151
152 pub fn focusable(self, focusable: bool) -> Self {
153 Self {
154 builder: self.builder.property("focusable", focusable),
155 }
156 }
157
158 pub fn halign(self, halign: gtk::Align) -> Self {
159 Self {
160 builder: self.builder.property("halign", halign),
161 }
162 }
163
164 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
165 Self {
166 builder: self.builder.property("has-tooltip", has_tooltip),
167 }
168 }
169
170 pub fn height_request(self, height_request: i32) -> Self {
171 Self {
172 builder: self.builder.property("height-request", height_request),
173 }
174 }
175
176 pub fn hexpand(self, hexpand: bool) -> Self {
177 Self {
178 builder: self.builder.property("hexpand", hexpand),
179 }
180 }
181
182 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
183 Self {
184 builder: self.builder.property("hexpand-set", hexpand_set),
185 }
186 }
187
188 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
189 Self {
190 builder: self
191 .builder
192 .property("layout-manager", layout_manager.clone().upcast()),
193 }
194 }
195
196 #[cfg(feature = "gtk_v4_18")]
197 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
198 pub fn limit_events(self, limit_events: bool) -> Self {
199 Self {
200 builder: self.builder.property("limit-events", limit_events),
201 }
202 }
203
204 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
205 Self {
206 builder: self.builder.property("margin-bottom", margin_bottom),
207 }
208 }
209
210 pub fn margin_end(self, margin_end: i32) -> Self {
211 Self {
212 builder: self.builder.property("margin-end", margin_end),
213 }
214 }
215
216 pub fn margin_start(self, margin_start: i32) -> Self {
217 Self {
218 builder: self.builder.property("margin-start", margin_start),
219 }
220 }
221
222 pub fn margin_top(self, margin_top: i32) -> Self {
223 Self {
224 builder: self.builder.property("margin-top", margin_top),
225 }
226 }
227
228 pub fn name(self, name: impl Into<glib::GString>) -> Self {
229 Self {
230 builder: self.builder.property("name", name.into()),
231 }
232 }
233
234 pub fn opacity(self, opacity: f64) -> Self {
235 Self {
236 builder: self.builder.property("opacity", opacity),
237 }
238 }
239
240 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
241 Self {
242 builder: self.builder.property("overflow", overflow),
243 }
244 }
245
246 pub fn receives_default(self, receives_default: bool) -> Self {
247 Self {
248 builder: self.builder.property("receives-default", receives_default),
249 }
250 }
251
252 pub fn sensitive(self, sensitive: bool) -> Self {
253 Self {
254 builder: self.builder.property("sensitive", sensitive),
255 }
256 }
257
258 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
259 Self {
260 builder: self
261 .builder
262 .property("tooltip-markup", tooltip_markup.into()),
263 }
264 }
265
266 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
267 Self {
268 builder: self.builder.property("tooltip-text", tooltip_text.into()),
269 }
270 }
271
272 pub fn valign(self, valign: gtk::Align) -> Self {
273 Self {
274 builder: self.builder.property("valign", valign),
275 }
276 }
277
278 pub fn vexpand(self, vexpand: bool) -> Self {
279 Self {
280 builder: self.builder.property("vexpand", vexpand),
281 }
282 }
283
284 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
285 Self {
286 builder: self.builder.property("vexpand-set", vexpand_set),
287 }
288 }
289
290 pub fn visible(self, visible: bool) -> Self {
291 Self {
292 builder: self.builder.property("visible", visible),
293 }
294 }
295
296 pub fn width_request(self, width_request: i32) -> Self {
297 Self {
298 builder: self.builder.property("width-request", width_request),
299 }
300 }
301
302 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
303 Self {
304 builder: self.builder.property("accessible-role", accessible_role),
305 }
306 }
307
308 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
311 pub fn build(self) -> NavigationPage {
312 assert_initialized_main_thread!();
313 self.builder.build()
314 }
315}
316
317pub trait NavigationPageExt: IsA<NavigationPage> + 'static {
318 #[doc(alias = "adw_navigation_page_get_can_pop")]
319 #[doc(alias = "get_can_pop")]
320 #[doc(alias = "can-pop")]
321 fn can_pop(&self) -> bool {
322 unsafe {
323 from_glib(ffi::adw_navigation_page_get_can_pop(
324 self.as_ref().to_glib_none().0,
325 ))
326 }
327 }
328
329 #[doc(alias = "adw_navigation_page_get_child")]
330 #[doc(alias = "get_child")]
331 fn child(&self) -> Option<gtk::Widget> {
332 unsafe {
333 from_glib_none(ffi::adw_navigation_page_get_child(
334 self.as_ref().to_glib_none().0,
335 ))
336 }
337 }
338
339 #[doc(alias = "adw_navigation_page_get_tag")]
340 #[doc(alias = "get_tag")]
341 fn tag(&self) -> Option<glib::GString> {
342 unsafe {
343 from_glib_none(ffi::adw_navigation_page_get_tag(
344 self.as_ref().to_glib_none().0,
345 ))
346 }
347 }
348
349 #[doc(alias = "adw_navigation_page_get_title")]
350 #[doc(alias = "get_title")]
351 fn title(&self) -> glib::GString {
352 unsafe {
353 from_glib_none(ffi::adw_navigation_page_get_title(
354 self.as_ref().to_glib_none().0,
355 ))
356 }
357 }
358
359 #[doc(alias = "adw_navigation_page_set_can_pop")]
360 #[doc(alias = "can-pop")]
361 fn set_can_pop(&self, can_pop: bool) {
362 unsafe {
363 ffi::adw_navigation_page_set_can_pop(
364 self.as_ref().to_glib_none().0,
365 can_pop.into_glib(),
366 );
367 }
368 }
369
370 #[doc(alias = "adw_navigation_page_set_child")]
371 #[doc(alias = "child")]
372 fn set_child(&self, child: Option<&impl IsA<gtk::Widget>>) {
373 unsafe {
374 ffi::adw_navigation_page_set_child(
375 self.as_ref().to_glib_none().0,
376 child.map(|p| p.as_ref()).to_glib_none().0,
377 );
378 }
379 }
380
381 #[doc(alias = "adw_navigation_page_set_tag")]
382 #[doc(alias = "tag")]
383 fn set_tag(&self, tag: Option<&str>) {
384 unsafe {
385 ffi::adw_navigation_page_set_tag(self.as_ref().to_glib_none().0, tag.to_glib_none().0);
386 }
387 }
388
389 #[doc(alias = "adw_navigation_page_set_title")]
390 #[doc(alias = "title")]
391 fn set_title(&self, title: &str) {
392 unsafe {
393 ffi::adw_navigation_page_set_title(
394 self.as_ref().to_glib_none().0,
395 title.to_glib_none().0,
396 );
397 }
398 }
399
400 #[cfg(feature = "v1_4")]
401 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
402 #[doc(alias = "hidden")]
403 fn connect_hidden<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
404 unsafe extern "C" fn hidden_trampoline<P: IsA<NavigationPage>, F: Fn(&P) + 'static>(
405 this: *mut ffi::AdwNavigationPage,
406 f: glib::ffi::gpointer,
407 ) {
408 let f: &F = &*(f as *const F);
409 f(NavigationPage::from_glib_borrow(this).unsafe_cast_ref())
410 }
411 unsafe {
412 let f: Box_<F> = Box_::new(f);
413 connect_raw(
414 self.as_ptr() as *mut _,
415 c"hidden".as_ptr() as *const _,
416 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
417 hidden_trampoline::<Self, F> as *const (),
418 )),
419 Box_::into_raw(f),
420 )
421 }
422 }
423
424 #[cfg(feature = "v1_4")]
425 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
426 #[doc(alias = "hiding")]
427 fn connect_hiding<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
428 unsafe extern "C" fn hiding_trampoline<P: IsA<NavigationPage>, F: Fn(&P) + 'static>(
429 this: *mut ffi::AdwNavigationPage,
430 f: glib::ffi::gpointer,
431 ) {
432 let f: &F = &*(f as *const F);
433 f(NavigationPage::from_glib_borrow(this).unsafe_cast_ref())
434 }
435 unsafe {
436 let f: Box_<F> = Box_::new(f);
437 connect_raw(
438 self.as_ptr() as *mut _,
439 c"hiding".as_ptr() as *const _,
440 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
441 hiding_trampoline::<Self, F> as *const (),
442 )),
443 Box_::into_raw(f),
444 )
445 }
446 }
447
448 #[cfg(feature = "v1_4")]
449 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
450 #[doc(alias = "showing")]
451 fn connect_showing<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
452 unsafe extern "C" fn showing_trampoline<P: IsA<NavigationPage>, F: Fn(&P) + 'static>(
453 this: *mut ffi::AdwNavigationPage,
454 f: glib::ffi::gpointer,
455 ) {
456 let f: &F = &*(f as *const F);
457 f(NavigationPage::from_glib_borrow(this).unsafe_cast_ref())
458 }
459 unsafe {
460 let f: Box_<F> = Box_::new(f);
461 connect_raw(
462 self.as_ptr() as *mut _,
463 c"showing".as_ptr() as *const _,
464 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
465 showing_trampoline::<Self, F> as *const (),
466 )),
467 Box_::into_raw(f),
468 )
469 }
470 }
471
472 #[cfg(feature = "v1_4")]
473 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
474 #[doc(alias = "shown")]
475 fn connect_shown<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
476 unsafe extern "C" fn shown_trampoline<P: IsA<NavigationPage>, F: Fn(&P) + 'static>(
477 this: *mut ffi::AdwNavigationPage,
478 f: glib::ffi::gpointer,
479 ) {
480 let f: &F = &*(f as *const F);
481 f(NavigationPage::from_glib_borrow(this).unsafe_cast_ref())
482 }
483 unsafe {
484 let f: Box_<F> = Box_::new(f);
485 connect_raw(
486 self.as_ptr() as *mut _,
487 c"shown".as_ptr() as *const _,
488 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
489 shown_trampoline::<Self, F> as *const (),
490 )),
491 Box_::into_raw(f),
492 )
493 }
494 }
495
496 #[cfg(feature = "v1_4")]
497 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
498 #[doc(alias = "can-pop")]
499 fn connect_can_pop_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
500 unsafe extern "C" fn notify_can_pop_trampoline<
501 P: IsA<NavigationPage>,
502 F: Fn(&P) + 'static,
503 >(
504 this: *mut ffi::AdwNavigationPage,
505 _param_spec: glib::ffi::gpointer,
506 f: glib::ffi::gpointer,
507 ) {
508 let f: &F = &*(f as *const F);
509 f(NavigationPage::from_glib_borrow(this).unsafe_cast_ref())
510 }
511 unsafe {
512 let f: Box_<F> = Box_::new(f);
513 connect_raw(
514 self.as_ptr() as *mut _,
515 c"notify::can-pop".as_ptr() as *const _,
516 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
517 notify_can_pop_trampoline::<Self, F> as *const (),
518 )),
519 Box_::into_raw(f),
520 )
521 }
522 }
523
524 #[cfg(feature = "v1_4")]
525 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
526 #[doc(alias = "child")]
527 fn connect_child_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
528 unsafe extern "C" fn notify_child_trampoline<
529 P: IsA<NavigationPage>,
530 F: Fn(&P) + 'static,
531 >(
532 this: *mut ffi::AdwNavigationPage,
533 _param_spec: glib::ffi::gpointer,
534 f: glib::ffi::gpointer,
535 ) {
536 let f: &F = &*(f as *const F);
537 f(NavigationPage::from_glib_borrow(this).unsafe_cast_ref())
538 }
539 unsafe {
540 let f: Box_<F> = Box_::new(f);
541 connect_raw(
542 self.as_ptr() as *mut _,
543 c"notify::child".as_ptr() as *const _,
544 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
545 notify_child_trampoline::<Self, F> as *const (),
546 )),
547 Box_::into_raw(f),
548 )
549 }
550 }
551
552 #[cfg(feature = "v1_4")]
553 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
554 #[doc(alias = "tag")]
555 fn connect_tag_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
556 unsafe extern "C" fn notify_tag_trampoline<P: IsA<NavigationPage>, F: Fn(&P) + 'static>(
557 this: *mut ffi::AdwNavigationPage,
558 _param_spec: glib::ffi::gpointer,
559 f: glib::ffi::gpointer,
560 ) {
561 let f: &F = &*(f as *const F);
562 f(NavigationPage::from_glib_borrow(this).unsafe_cast_ref())
563 }
564 unsafe {
565 let f: Box_<F> = Box_::new(f);
566 connect_raw(
567 self.as_ptr() as *mut _,
568 c"notify::tag".as_ptr() as *const _,
569 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
570 notify_tag_trampoline::<Self, F> as *const (),
571 )),
572 Box_::into_raw(f),
573 )
574 }
575 }
576
577 #[cfg(feature = "v1_4")]
578 #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
579 #[doc(alias = "title")]
580 fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
581 unsafe extern "C" fn notify_title_trampoline<
582 P: IsA<NavigationPage>,
583 F: Fn(&P) + 'static,
584 >(
585 this: *mut ffi::AdwNavigationPage,
586 _param_spec: glib::ffi::gpointer,
587 f: glib::ffi::gpointer,
588 ) {
589 let f: &F = &*(f as *const F);
590 f(NavigationPage::from_glib_borrow(this).unsafe_cast_ref())
591 }
592 unsafe {
593 let f: Box_<F> = Box_::new(f);
594 connect_raw(
595 self.as_ptr() as *mut _,
596 c"notify::title".as_ptr() as *const _,
597 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
598 notify_title_trampoline::<Self, F> as *const (),
599 )),
600 Box_::into_raw(f),
601 )
602 }
603 }
604}
605
606impl<O: IsA<NavigationPage>> NavigationPageExt for O {}