nrelm 0.1.0

An idiomatic GUI library inspired by Elm and based on gtk3-rs
use super::ContainerChild;
use gtk::prelude::{Cast, ContainerExt, IsA};

/// Extension trait that provides typed iteration over the children of a
/// container.
pub trait RelmIterChildrenExt: ContainerChild + IsA<gtk::Container> {
    /// Returns a double-ended iterator over the children of the container
    /// that can be downcast to [`Self::Child`].
    fn iter_children(&self) -> Box<dyn DoubleEndedIterator<Item = Self::Child>> {
        let self_container: &gtk::Container = self.upcast_ref::<gtk::Container>();
        let children = self_container.children();
        Box::new(
            children
                .into_iter()
                .filter_map(|c| c.downcast::<Self::Child>().ok()),
        )
    }
}

impl RelmIterChildrenExt for gtk::Box {}
impl RelmIterChildrenExt for gtk::ListBox {}
impl RelmIterChildrenExt for gtk::FlowBox {}
impl RelmIterChildrenExt for gtk::Grid {}
impl RelmIterChildrenExt for gtk::Stack {}