Skip to main content

fret_ui/tree/
ui_tree_accessors.rs

1use super::*;
2
3impl<H: UiHost> UiTree<H> {
4    pub(crate) fn request_redraw_coalesced(&mut self, app: &mut H) {
5        let Some(window) = self.window else {
6            return;
7        };
8        let tick = app.tick_id();
9        if self.last_redraw_request_tick == Some(tick) {
10            return;
11        }
12        self.last_redraw_request_tick = Some(tick);
13        app.request_redraw(window);
14    }
15
16    /// Resolve the live attached node currently associated with `element` in this tree.
17    ///
18    /// This is the authoritative element-to-node query when callers already have access to the
19    /// current `UiTree` and need a node that is still attached to an active layer tree.
20    pub fn live_attached_node_for_element(
21        &self,
22        app: &mut H,
23        element: GlobalElementId,
24    ) -> Option<NodeId> {
25        self.resolve_live_attached_node_for_element(app, self.window, element)
26    }
27
28    pub(crate) fn node_bounds(&self, node: NodeId) -> Option<Rect> {
29        self.nodes.get(node).map(|n| n.bounds)
30    }
31
32    pub(crate) fn node_needs_layout(&self, node: NodeId) -> bool {
33        self.nodes.get(node).is_some_and(|n| n.invalidation.layout)
34    }
35
36    pub(crate) fn node_exists(&self, node: NodeId) -> bool {
37        self.nodes.contains_key(node)
38    }
39
40    pub(crate) fn set_node_element(&mut self, node: NodeId, element: Option<GlobalElementId>) {
41        if let Some(n) = self.nodes.get_mut(node) {
42            n.element = element;
43        }
44    }
45
46    pub(crate) fn node_element(&self, node: NodeId) -> Option<GlobalElementId> {
47        self.nodes.get(node).and_then(|n| n.element)
48    }
49
50    pub(crate) fn node_layout_invalidated(&self, node: NodeId) -> bool {
51        self.nodes
52            .get(node)
53            .map(|n| n.invalidation.layout)
54            .unwrap_or(false)
55    }
56
57    pub(crate) fn node_measured_size(&self, node: NodeId) -> Option<Size> {
58        self.nodes.get(node).map(|n| n.measured_size)
59    }
60
61    pub(crate) fn node_text_wrap_none_measure_cache(&self, node: NodeId) -> Option<(u64, Size)> {
62        self.nodes.get(node).and_then(|n| {
63            n.text_wrap_none_measure_cache
64                .map(|cache| (cache.fingerprint, cache.size))
65        })
66    }
67}