Skip to main content

lgui_core/core/component/
scope.rs

1use super::{UiId, UiIdPath};
2
3#[derive(Clone, Debug)]
4pub struct UiScope {
5    path: UiIdPath,
6}
7
8impl UiScope {
9    pub fn new(root: &'static str) -> Self {
10        Self {
11            path: UiIdPath::new(root),
12        }
13    }
14
15    pub fn child(&self, segment: &'static str) -> Self {
16        Self {
17            path: self.path.child(segment),
18        }
19    }
20
21    pub fn from_path(path: UiIdPath) -> Self {
22        Self { path }
23    }
24
25    pub fn path(&self) -> &UiIdPath {
26        &self.path
27    }
28
29    pub fn id(&self, leaf: impl AsRef<str>) -> UiId {
30        self.path.id(leaf)
31    }
32
33    pub(crate) fn scope_id(&self) -> UiId {
34        UiId::from_parts(self.path.segments().iter().map(|segment| segment.as_ref()))
35    }
36
37    pub(crate) fn node_id(&self) -> UiId {
38        self.path.id("n")
39    }
40}