-
Notifications
You must be signed in to change notification settings - Fork 428
/
Copy pathinstance_path.rs
164 lines (148 loc) · 6.13 KB
/
instance_path.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use re_entity_db::InstancePath;
use re_log_types::ComponentPath;
use re_ui::{ContextExt as _, UiExt as _};
use re_viewer_context::{HoverHighlight, Item, UiLayout, ViewerContext};
use super::DataUi;
impl DataUi for InstancePath {
fn data_ui(
&self,
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
ui_layout: UiLayout,
query: &re_chunk_store::LatestAtQuery,
db: &re_entity_db::EntityDb,
) {
let Self {
entity_path,
instance,
} = self;
let Some(components) = ctx
.recording_store()
.all_components_on_timeline(&query.timeline(), entity_path)
else {
if ctx.recording().is_known_entity(entity_path) {
// This is fine - e.g. we're looking at `/world` and the user has only logged to `/world/car`.
ui_layout.label(
ui,
format!(
"No components logged on timeline {:?}",
query.timeline().name()
),
);
} else {
ui_layout.label(
ui,
ui.ctx()
.error_text(format!("Unknown entity: {entity_path:?}")),
);
}
return;
};
let components = crate::sorted_component_list_for_ui(&components);
let indicator_count = components
.iter()
.filter(|c| c.is_indicator_component())
.count();
if ui_layout == UiLayout::List {
ui_layout.label(
ui,
format!(
"{} component{} (including {} indicator component{})",
components.len(),
if components.len() > 1 { "s" } else { "" },
indicator_count,
if indicator_count > 1 { "s" } else { "" }
),
);
return;
}
let show_indicator_comps = match ui_layout {
UiLayout::Tooltip => {
// Skip indicator components in hover ui (unless there are no other
// types of components).
indicator_count == components.len()
}
UiLayout::SelectionPanelLimitHeight | UiLayout::SelectionPanelFull => true,
UiLayout::List => false, // unreachable
};
let interactive = ui_layout != UiLayout::Tooltip;
re_ui::list_item::list_item_scope(ui, "component list", |ui| {
for component_name in components {
if !show_indicator_comps && component_name.is_indicator_component() {
continue;
}
let component_path = ComponentPath::new(entity_path.clone(), component_name);
let is_static = db
.store()
.entity_has_static_component(entity_path, &component_name);
let icon = if is_static {
&re_ui::icons::COMPONENT_STATIC
} else {
&re_ui::icons::COMPONENT_TEMPORAL
};
let item = Item::ComponentPath(component_path);
let mut list_item = ui.list_item().interactive(interactive);
if interactive {
let is_hovered = ctx.selection_state().highlight_for_ui_element(&item)
== HoverHighlight::Hovered;
list_item = list_item.force_hovered(is_hovered);
}
let response = if component_name.is_indicator_component() {
list_item.show_flat(
ui,
re_ui::list_item::LabelContent::new(component_name.short_name())
.with_icon(icon),
)
} else {
let results = db.query_caches2().latest_at(
db.store(),
query,
entity_path,
[component_name],
);
let Some(unit) = results.components.get(&component_name) else {
continue; // no need to show components that are unset at this point in time
};
let content =
re_ui::list_item::PropertyContent::new(component_name.short_name())
.with_icon(icon)
.value_fn(|ui, _| {
if instance.is_all() {
crate::EntityLatestAtResults {
entity_path: entity_path.clone(),
component_name,
unit,
}
.data_ui(
ctx,
ui,
UiLayout::List,
query,
db,
);
} else {
ctx.component_ui_registry.ui(
ctx,
ui,
UiLayout::List,
query,
db,
entity_path,
component_name,
unit,
instance,
);
}
});
list_item.show_flat(ui, content)
};
let response = response.on_hover_ui(|ui| {
component_name.data_ui_recording(ctx, ui, UiLayout::Tooltip);
});
if interactive {
ctx.select_hovered_on_click(&response, item);
}
}
});
}
}