lgui_core/core/view/
tree.rs1use super::{
2 compile_scene, ActionId, ComponentId, ComponentTree, CompositingLayerSpec, EventPolicy,
3 InteractionRole, Point, RenderPhase, Scene, UiAction, UiActionHandler, UiEvent, UiEventHandler,
4 UiEventKind, UiEventPayload, UiHandlerEvent, UiId, UiNode, UiRect,
5};
6use std::{
7 collections::{HashMap, HashSet},
8 sync::Arc,
9};
10
11#[derive(Clone)]
12pub struct HitResult {
13 pub id: UiId,
14 pub rect: UiRect,
15 pub interaction: InteractionRole,
16 pub policy: EventPolicy,
17 pub action: Option<UiAction>,
18 pub action_target: Option<UiId>,
19 pub capture_handlers: Vec<UiEventHandler>,
20 pub bubble_handlers: Vec<UiEventHandler>,
21 pub click_handler: Option<UiEventHandler>,
22}
23
24impl std::fmt::Debug for HitResult {
25 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 formatter
27 .debug_struct("HitResult")
28 .field("id", &self.id)
29 .field("rect", &self.rect)
30 .field("interaction", &self.interaction)
31 .field("policy", &self.policy)
32 .field("action", &self.action)
33 .field("action_target", &self.action_target)
34 .field("capture_handlers", &self.capture_handlers.len())
35 .field("bubble_handlers", &self.bubble_handlers.len())
36 .field("has_click_handler", &self.click_handler.is_some())
37 .finish()
38 }
39}
40
41impl PartialEq for HitResult {
42 fn eq(&self, other: &Self) -> bool {
43 self.id == other.id
44 && self.rect == other.rect
45 && self.interaction == other.interaction
46 && self.policy == other.policy
47 && self.action == other.action
48 && self.action_target == other.action_target
49 && self.capture_handlers.len() == other.capture_handlers.len()
50 && self.bubble_handlers.len() == other.bubble_handlers.len()
51 && self.click_handler.is_some() == other.click_handler.is_some()
52 }
53}
54
55impl Eq for HitResult {}
56
57#[derive(Clone, Default)]
58pub struct HostTree {
59 nodes: Vec<Arc<UiNode>>,
60 node_indices: Arc<HashMap<UiId, usize>>,
61 owners: Arc<HashMap<ComponentId, HashSet<UiId>>>,
62 projection_changes: ProjectionChanges,
63}
64
65impl HostTree {
66 pub fn estimated_bytes(&self) -> usize {
68 std::mem::size_of::<Self>()
69 .saturating_add(
70 self.nodes
71 .capacity()
72 .saturating_mul(std::mem::size_of::<Arc<UiNode>>()),
73 )
74 .saturating_add(
75 self.nodes
76 .iter()
77 .map(|node| node.estimated_bytes())
78 .sum::<usize>(),
79 )
80 }
81}
82
83#[derive(Clone, Default)]
84pub(crate) struct ProjectionChanges {
85 pub changed: std::collections::HashSet<UiId>,
86 pub removed: std::collections::HashSet<UiId>,
87 pub structure_changed: bool,
88 pub(crate) animation_sync: std::collections::HashSet<UiId>,
89 pub(crate) focus_sync: bool,
90}
91
92mod events;
93mod mutation;
94mod scene;
95
96#[cfg(test)]
97#[path = "tree/tree_test.rs"]
98mod tests;