use std::{slice::Iter, sync::Arc}; use crate::prelude::*; #[derive(Default)] pub struct Elements { framables: Vec>, hoverables: Vec>, clickables: Vec>, displayables: Vec>, selectables: Vec>, textables: Vec>, writeables: Vec>, iconizables: Vec>, colorables: Vec>, } impl Elements { #[inline] fn push_element(vector: &mut Vec>, element: Arc) { if cfg!(debug_assertions) && vector.iter().any(|e| Arc::ptr_eq(e, &element)) { panic!("element is pushed twice, actually an error"); } vector.push(element); } #[inline] fn erase_element(vector: &mut Vec>, element: &Arc) -> bool { match vector.iter().position(|t| Arc::ptr_eq(t, element)) { Some(i) => { vector.remove(i); true } None => false, } } // pub fn is_empty(&self) -> bool { // self.framables.is_empty() // && self.hoverables.is_empty() // && self.clickables.is_empty() // && self.displayables.is_empty() // && self.selectables.is_empty() // && self.textables.is_empty() // && self.writeables.is_empty() // && self.iconizables.is_empty() // && self.colorables.is_empty() // } // framable pub fn add_framable(&mut self, framable: Arc) { Self::push_element(&mut self.framables, framable); } pub fn delete_framable(&mut self, framable: &Arc) -> bool { Self::erase_element(&mut self.framables, framable) } pub fn iter_framables(&self) -> Iter<'_, Arc> { self.framables.iter() } // hoverable pub fn add_hoverable(&mut self, hoverable: Arc) { Self::push_element(&mut self.hoverables, hoverable); } pub fn delete_hoverable(&mut self, hoverable: &Arc) -> bool { Self::erase_element(&mut self.hoverables, hoverable) } pub fn iter_hoverables(&self) -> Iter<'_, Arc> { self.hoverables.iter() } // selectable pub fn add_selectable(&mut self, selectable: Arc) { Self::push_element(&mut self.selectables, selectable); } pub fn delete_selectable(&mut self, selectable: &Arc) -> bool { Self::erase_element(&mut self.selectables, selectable) } // displayable pub fn add_displayable(&mut self, displayable: Arc) { Self::push_element(&mut self.displayables, displayable); } pub fn delete_displayable(&mut self, displayable: &Arc) -> bool { Self::erase_element(&mut self.displayables, displayable) } pub fn iter_displayables(&self) -> Iter<'_, Arc> { self.displayables.iter() } pub fn is_displayables_empty(&self) -> bool { self.displayables.is_empty() } // clickable pub fn add_clickable(&mut self, clickable: Arc) { Self::push_element(&mut self.clickables, clickable); } pub fn delete_clickable(&mut self, clickable: &Arc) -> bool { Self::erase_element(&mut self.clickables, clickable) } pub fn iter_clickables(&self) -> Iter<'_, Arc> { self.clickables.iter() } // textable pub fn add_textable(&mut self, textable: Arc) { Self::push_element(&mut self.textables, textable); } pub fn delete_textable(&mut self, textable: &Arc) -> bool { Self::erase_element(&mut self.textables, textable) } pub fn iter_textables(&self) -> Iter<'_, Arc> { self.textables.iter() } pub fn is_textables_empty(&self) -> bool { self.textables.is_empty() } // writable pub fn add_writeable(&mut self, writeable: Arc) { Self::push_element(&mut self.writeables, writeable); } pub fn delete_writeable(&mut self, writeable: &Arc) -> bool { Self::erase_element(&mut self.writeables, writeable) } // iconizable pub fn add_iconizable(&mut self, iconizable: Arc) { Self::push_element(&mut self.iconizables, iconizable); } pub fn delete_iconizable(&mut self, iconizable: &Arc) -> bool { Self::erase_element(&mut self.iconizables, iconizable) } pub fn iter_iconizables(&self) -> Iter<'_, Arc> { self.iconizables.iter() } pub fn is_iconizables_empty(&self) -> bool { self.iconizables.is_empty() } // colorable pub fn add_colorable(&mut self, colorable: Arc) { Self::push_element(&mut self.colorables, colorable); } pub fn delete_colorable(&mut self, colorable: &Arc) -> bool { Self::erase_element(&mut self.colorables, colorable) } pub fn iter_colorables(&self) -> Iter<'_, Arc> { self.colorables.iter() } pub fn is_colorables_empty(&self) -> bool { self.colorables.is_empty() } }