cosmic/widget/table/model/
entity.rs1use slotmap::{SecondaryMap, SparseSecondaryMap};
5
6use super::category::{ItemCategory, ItemInterface};
7use super::{Entity, Model, Selectable};
8
9pub struct EntityMut<
11 'a,
12 SelectionMode: Default,
13 Item: ItemInterface<Category>,
14 Category: ItemCategory,
15> {
16 pub(super) id: Entity,
17 pub(super) model: &'a mut Model<SelectionMode, Item, Category>,
18}
19
20impl<'a, SelectionMode: Default, Item: ItemInterface<Category>, Category: ItemCategory>
21 EntityMut<'a, SelectionMode, Item, Category>
22where
23 Model<SelectionMode, Item, Category>: Selectable,
24{
25 #[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
31 pub fn activate(self) -> Self {
32 self.model.activate(self.id);
33 self
34 }
35
36 #[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
46 pub fn secondary<Data>(self, map: &mut SecondaryMap<Entity, Data>, data: Data) -> Self {
47 map.insert(self.id, data);
48 self
49 }
50
51 #[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
60 pub fn secondary_sparse<Data>(
61 self,
62 map: &mut SparseSecondaryMap<Entity, Data>,
63 data: Data,
64 ) -> Self {
65 map.insert(self.id, data);
66 self
67 }
68
69 #[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
77 pub fn data<Data: 'static>(self, data: Data) -> Self {
78 self.model.data_set(self.id, data);
79 self
80 }
81
82 #[must_use]
88 pub fn id(self) -> Entity {
89 self.id
90 }
91
92 #[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
93 pub fn indent(self, indent: u16) -> Self {
94 self.model.indent_set(self.id, indent);
95 self
96 }
97
98 #[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
100 pub fn position(self, position: u16) -> Self {
101 self.model.position_set(self.id, position);
102 self
103 }
104
105 #[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
107 pub fn position_swap(self, other: Entity) -> Self {
108 self.model.position_swap(self.id, other);
109 self
110 }
111
112 #[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
114 pub fn item(self, item: Item) -> Self {
115 self.model.item_set(self.id, item);
116 self
117 }
118
119 #[allow(clippy::must_use_candidate, clippy::return_self_not_must_use)]
121 pub fn with_id(self, func: impl FnOnce(Entity)) -> Self {
122 func(self.id);
123 self
124 }
125}