cotis_layout/cotis_traits/
secondary_traits.rs1use crate::layout_struct::layout_states::{LayoutElement, clip_content_size};
17use crate::preamble::CotisLayoutManager;
18use cotis::utils::ElementId;
19use cotis_utils::element_state::*;
20use cotis_utils::math::{BoundingBox, Vector2};
21
22impl ElementsList for CotisLayoutManager {
23 fn get_element_ids(&self) -> Vec<ElementId> {
24 self.cached_element_ids()
25 }
26
27 fn get_parent_id(&self, id: ElementId) -> Option<ElementId> {
28 let parent_slot = self.parent_layout_slot_of(id)?;
29 Some(self.get_cache_element(parent_slot)?.id)
30 }
31}
32
33impl ElementDebugName for CotisLayoutManager {
34 fn debug_name(&self, id: ElementId) -> Option<&str> {
35 let element = self.get_cache_element(id)?;
36 Some(&element.name)
37 }
38}
39
40impl ElementBoundingBox for CotisLayoutManager {
41 fn bounding_box(&self, id: ElementId) -> Option<BoundingBox> {
42 Some(self.get_cache_element(id)?.info.to_bounding_box())
43 }
44}
45
46impl ElementClipOffset for CotisLayoutManager {
47 fn clip_offset(&self, id: ElementId) -> Option<Vector2> {
48 Some(self.get_cache_element(id)?.config.clip.offset)
49 }
50}
51
52impl ElementClipInternalSize for CotisLayoutManager {
53 fn clip_internal_size(&self, id: ElementId) -> Option<Vector2> {
54 let parent = self.get_cache_element(id)?;
55 let children: Vec<&LayoutElement> = self
56 .direct_child_slots(id)
57 .iter()
58 .filter_map(|&c| self.get_cache_element(c))
59 .collect();
60 clip_content_size(parent, &children)
61 }
62}