use crate::Control;
use ferroui_base::collections::{FerroList, ResetBehavior};
use ferroui_base::{IntoRef, Ref};
use std::ops::Deref;
#[derive(Clone, PartialEq, Debug)]
pub struct Controls {
list: FerroList<Ref<Control>>,
}
impl Default for Controls {
fn default() -> Self {
Self::new()
}
}
impl Controls {
pub fn new() -> Self {
let list = FerroList::new();
list.set_reset_behavior(ResetBehavior::Remove);
Self { list }
}
pub fn from_items(items: impl IntoIterator<Item = Ref<Control>>) -> Self {
let result = Self::new();
result.list.add_range(items);
result
}
pub fn add(&self, item: impl IntoRef<Control>) {
self.list.add(item.into_ref());
}
pub fn insert(&self, index: usize, item: impl IntoRef<Control>) {
self.list.insert(index, item.into_ref());
}
pub fn remove(&self, item: impl IntoRef<Control>) -> bool {
self.list.remove(&item.into_ref())
}
pub fn set(&self, index: usize, item: impl IntoRef<Control>) {
self.list.set(index, item.into_ref());
}
}
impl Deref for Controls {
type Target = FerroList<Ref<Control>>;
fn deref(&self) -> &Self::Target {
&self.list
}
}