relm4/extensions/
container.rs1#![allow(deprecated)]
2use gtk::prelude::*;
3
4use crate::{ContainerChild, RelmSetChildExt};
5
6pub trait RelmContainerExt: ContainerChild {
8 fn container_add(&self, widget: &impl AsRef<Self::Child>);
10}
11
12impl<T: RelmSetChildExt> RelmContainerExt for T {
13 fn container_add(&self, widget: &impl AsRef<T::Child>) {
14 self.container_set_child(Some(widget));
15 }
16}
17
18#[allow(deprecated)]
19impl RelmContainerExt for gtk::Dialog {
20 fn container_add(&self, widget: &impl AsRef<gtk::Widget>) {
21 self.content_area().append(widget.as_ref());
22 }
23}
24
25macro_rules! append_impl {
26 ($($type:ty),+) => {
27 $(
28 impl RelmContainerExt for $type {
29 #[allow(unused_qualifications)]
30 fn container_add(&self, widget: &impl AsRef<<$type as crate::extensions::ContainerChild>::Child>) {
31 self.append(widget.as_ref());
32 }
33 }
34 )+
35 }
36}
37
38macro_rules! add_child_impl {
39 ($($type:ty),+) => {
40 $(
41 #[allow(deprecated)]
42 impl RelmContainerExt for $type {
43 fn container_add(&self, widget: &impl AsRef<gtk::Widget>) {
44 self.add_child(widget.as_ref());
45 }
46 }
47 )+
48 }
49}
50
51#[cfg(any(feature = "libadwaita", feature = "libpanel"))]
52#[cfg_attr(docsrs, doc(cfg(any(feature = "libadwaita", feature = "libpanel"))))]
53macro_rules! add_impl {
54 ($($type:ty: $child:ty), +) => {
55 $(
56 impl RelmContainerExt for $type {
57 fn container_add(&self, child: &impl AsRef<$child>) {
58 self.add(child.as_ref());
59 }
60 }
61 )+
62 };
63 ($($type:ty), +) => {
64 $(
65 impl RelmContainerExt for $type {
66 fn container_add(&self, widget: &impl AsRef<gtk::Widget>) {
67 self.add(widget.as_ref());
68 }
69 }
70 )+
71 };
72}
73
74append_impl!(gtk::Box, gtk::ListBox);
75add_child_impl!(gtk::InfoBar, gtk::Stack);
76
77#[cfg(feature = "gnome_42")]
78#[cfg_attr(docsrs, doc(cfg(feature = "gnome_42")))]
79mod gnome_42 {
80 use super::RelmContainerExt;
81 append_impl!(gtk::FlowBox);
82}
83
84#[cfg(feature = "libadwaita")]
85#[cfg_attr(docsrs, doc(cfg(feature = "libadwaita")))]
86mod libadwaita {
87 use super::RelmContainerExt;
88 use adw::prelude::{PreferencesGroupExt, PreferencesPageExt};
89 append_impl!(adw::Leaflet, adw::Carousel, adw::TabView);
90 add_impl! {
91 adw::PreferencesPage: adw::PreferencesGroup
92 }
93 add_impl! {
94 adw::PreferencesGroup,
95 adw::Squeezer
96 }
97
98 #[cfg(all(feature = "libadwaita", feature = "gnome_45"))]
99 #[cfg_attr(docsrs, doc(cfg(all(feature = "libadwaita", feature = "gnome_45"))))]
100 mod gnome_45 {
101 use super::RelmContainerExt;
102 add_impl! {
103 adw::NavigationView: adw::NavigationPage
104 }
105 }
106}
107
108#[cfg(feature = "libpanel")]
109#[cfg_attr(docsrs, doc(cfg(feature = "libpanel")))]
110mod libpanel {
111 use super::RelmContainerExt;
112 use panel::prelude::PanelFrameExt;
113 append_impl!(panel::Paned);
114 add_impl! {
115 panel::Frame: panel::Widget
116 }
117}