phantom/screen/
workspace.rs1use std::collections::BTreeMap;
2
3use super::{CResult, Component};
4
5pub struct Workspace {
6 components: BTreeMap<u16, Box<dyn Component>>,
8}
9
10impl Workspace {
11 pub fn new() -> Self {
12 Self {
13 components: BTreeMap::new(),
14 }
15 }
16 pub fn add_component(&mut self, id: u16, component: Box<dyn Component>) {
17 self.components.insert(id, component);
18 }
19 pub fn del_component(&mut self, id: u16) {
20 self.components.remove(&id);
21 }
22 pub fn update(&mut self) -> CResult<()> {
23 for (_cid, component) in self.components.iter_mut() {
24 component.update()?;
25 }
26 Ok(())
27 }
28 pub fn draw(&mut self) -> CResult<()> {
29 for (_cid, component) in self.components.iter_mut() {
30 component.draw()?;
31 }
32 Ok(())
33 }
34}