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