ferroui_controls/
controls.rs1use crate::Control;
2use ferroui_base::collections::{FerroList, ResetBehavior};
3use ferroui_base::{IntoRef, Ref};
4use std::ops::Deref;
5
6#[derive(Clone, PartialEq, Debug)]
11pub struct Controls {
12 list: FerroList<Ref<Control>>,
13}
14
15impl Default for Controls {
16 fn default() -> Self {
17 Self::new()
18 }
19}
20
21impl Controls {
22 pub fn new() -> Self {
24 let list = FerroList::new();
25 list.set_reset_behavior(ResetBehavior::Remove);
26 Self { list }
27 }
28
29 pub fn from_items(items: impl IntoIterator<Item = Ref<Control>>) -> Self {
31 let result = Self::new();
32 result.list.add_range(items);
33 result
34 }
35
36 pub fn add(&self, item: impl IntoRef<Control>) {
38 self.list.add(item.into_ref());
39 }
40
41 pub fn insert(&self, index: usize, item: impl IntoRef<Control>) {
43 self.list.insert(index, item.into_ref());
44 }
45
46 pub fn remove(&self, item: impl IntoRef<Control>) -> bool {
49 self.list.remove(&item.into_ref())
50 }
51
52 pub fn set(&self, index: usize, item: impl IntoRef<Control>) {
54 self.list.set(index, item.into_ref());
55 }
56}
57
58impl Deref for Controls {
59 type Target = FerroList<Ref<Control>>;
60
61 fn deref(&self) -> &Self::Target {
62 &self.list
63 }
64}