Skip to content

Commit

Permalink
clickable parts
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Feb 16, 2024
1 parent 00608f9 commit c66fc37
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 22 deletions.
71 changes: 71 additions & 0 deletions crates/re_data_ui/src/item_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ pub fn entity_path_button(
)
}

/// Show the different parts of an entity path and make them selectable.
pub fn entity_path_parts_buttons(
ctx: &ViewerContext<'_>,
query: &re_data_store::LatestAtQuery,
store: &re_data_store::DataStore,
ui: &mut egui::Ui,
space_view_id: Option<SpaceViewId>,
entity_path: &EntityPath,
) -> egui::Response {
ui.horizontal(|ui| {
let mut accumulated = Vec::new();
for part in entity_path.iter() {
accumulated.push(part.clone());

ui.strong("/");
entity_path_button_to(
ctx,
query,
store,
ui,
space_view_id,
&accumulated.clone().into(),
part.syntax_highlighted(ui.style()),
);
}
})
.response
}

/// Show an entity path and make it selectable.
pub fn entity_path_button_to(
ctx: &ViewerContext<'_>,
Expand Down Expand Up @@ -119,6 +148,48 @@ pub fn instance_path_button_to(
cursor_interact_with_selectable(ctx, response, item)
}

/// Show the different parts of an instance path and make them selectable.
pub fn instance_path_parts_buttons(
ctx: &ViewerContext<'_>,
query: &re_data_store::LatestAtQuery,
store: &re_data_store::DataStore,
ui: &mut egui::Ui,
space_view_id: Option<SpaceViewId>,
instance_path: &InstancePath,
) -> egui::Response {
ui.horizontal(|ui| {
let mut accumulated = Vec::new();
for part in instance_path.entity_path.iter() {
accumulated.push(part.clone());

ui.strong("/");
entity_path_button_to(
ctx,
query,
store,
ui,
space_view_id,
&accumulated.clone().into(),
part.syntax_highlighted(ui.style()),
);
}

if !instance_path.instance_key.is_splat() {
ui.strong("/");
instance_path_button_to(
ctx,
query,
store,
ui,
space_view_id,
instance_path,
instance_path.instance_key.syntax_highlighted(ui.style()),
);
}
})
.response
}

fn entity_tree_stats_ui(ui: &mut egui::Ui, timeline: &Timeline, tree: &EntityTree) {
use re_format::format_bytes;

Expand Down
14 changes: 10 additions & 4 deletions crates/re_ui/src/syntax_highlighting.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use re_entity_db::InstancePath;
use re_log_types::{EntityPath, EntityPathPart};
use re_log_types::{external::re_types_core::components::InstanceKey, EntityPath, EntityPathPart};

use egui::{text::LayoutJob, Color32, Style, TextFormat};

Expand Down Expand Up @@ -39,6 +39,14 @@ impl SyntaxHighlighting for EntityPathPart {
}
}

impl SyntaxHighlighting for InstanceKey {
fn syntax_highlight_into(&self, style: &Style, job: &mut LayoutJob) {
job.append("[", 0.0, faint_text_format(style));
job.append(&self.to_string(), 0.0, text_format(style));
job.append("]", 0.0, faint_text_format(style));
}
}

impl SyntaxHighlighting for EntityPath {
fn syntax_highlight_into(&self, style: &Style, job: &mut LayoutJob) {
job.append("/", 0.0, faint_text_format(style));
Expand All @@ -56,9 +64,7 @@ impl SyntaxHighlighting for InstancePath {
fn syntax_highlight_into(&self, style: &Style, job: &mut LayoutJob) {
self.entity_path.syntax_highlight_into(style, job);
if !self.instance_key.is_splat() {
job.append("[", 0.0, faint_text_format(style));
job.append(&self.instance_key.to_string(), 0.0, text_format(style));
job.append("]", 0.0, faint_text_format(style));
self.instance_key.syntax_highlight_into(style, job);
}
}
}
33 changes: 15 additions & 18 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use re_types::{
use re_types_core::components::InstanceKey;
use re_ui::list_item::ListItem;
use re_ui::ReUi;
use re_ui::SyntaxHighlighting as _;
use re_viewer_context::{
blueprint_timepoint_for_writes, gpu_bridge::colormap_dropdown_button_ui, ContainerId,
DataQueryId, HoverHighlight, Item, SpaceViewClass, SpaceViewClassIdentifier, SpaceViewId,
Expand Down Expand Up @@ -414,34 +413,32 @@ fn what_is_selected_ui(
"Entity instance"
};

let name = instance_path.syntax_highlighted(ui.style());
let (query, store) =
guess_query_and_store_for_selected_entity(ctx, &instance_path.entity_path);

if let Some(space_view_id) = space_view_id {
if let Some(space_view) = viewport.space_view(space_view_id) {
item_title_ui(
ctx.re_ui,
item_ui::instance_path_parts_buttons(
ctx,
&query,
store,
ui,
name,
None,
&format!(
"{typ} '{instance_path}' as shown in Space View {:?}",
space_view.display_name
),
);
Some(*space_view_id),
instance_path,
)
.on_hover_text(format!(
"{typ} '{instance_path}' as shown in Space View {:?}",
space_view.display_name
));

ui.horizontal(|ui| {
ui.label("in");
space_view_button(ctx, ui, space_view);
});
}
} else {
item_title_ui(
ctx.re_ui,
ui,
name,
None,
&format!("{typ} '{instance_path}'"),
);
item_ui::instance_path_parts_buttons(ctx, &query, store, ui, None, instance_path)
.on_hover_text(format!("{typ} '{instance_path}'"));

list_existing_data_blueprints(ui, ctx, &instance_path.entity_path, viewport);
}
Expand Down

0 comments on commit c66fc37

Please sign in to comment.