use super::ContainerChild;
use gtk::prelude::*;
pub trait RelmSetChildExt: ContainerChild {
fn container_set_child(&self, widget: Option<&impl AsRef<Self::Child>>);
fn container_get_child(&self) -> Option<Self::Child>;
}
macro_rules! set_child_impl {
($($type:ty), +) => {
$(
impl RelmSetChildExt for $type {
fn container_set_child(&self, widget: Option<&impl AsRef<Self::Child>>) {
let self_ref: >k::Container = self.upcast_ref();
for child in self_ref.children() {
self_ref.remove(&child);
}
if let Some(widget) = widget {
self_ref.add(widget.as_ref());
}
}
fn container_get_child(&self) -> Option<Self::Child> {
let self_ref: >k::Container = self.upcast_ref();
self_ref.children().first().and_then(|child| child.clone().downcast::<Self::Child>().ok())
}
}
)+
}
}
set_child_impl!(
gtk::Button,
gtk::LinkButton,
gtk::ToggleButton,
gtk::FlowBoxChild,
gtk::Frame,
gtk::ListBoxRow,
gtk::Popover,
gtk::Window,
gtk::ScrolledWindow,
gtk::ApplicationWindow,
gtk::Overlay,
gtk::Revealer,
gtk::Expander,
gtk::AspectFrame,
gtk::SearchBar,
gtk::Viewport,
gtk::MenuButton
);