Skip to content

Commit

Permalink
Hide entity icons in paths (#5550)
Browse files Browse the repository at this point in the history
### What
* Closes #5524

Before:
<img width="447" alt="image"
src="https://github.com/rerun-io/rerun/assets/1148717/4a92a481-2185-41a4-b2b0-15a63c41e060">


After:
<img width="374" alt="image"
src="https://github.com/rerun-io/rerun/assets/1148717/1d2942e3-bb19-4a80-a5c0-7422101f7560">


### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using newly built examples:
[app.rerun.io](https://app.rerun.io/pr/5550/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/5550/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[app.rerun.io](https://app.rerun.io/pr/5550/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/5550)
- [Docs
preview](https://rerun.io/preview/93e90e8c6e8e8df6093eabdf129d7061dab0d1a8/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/93e90e8c6e8e8df6093eabdf129d7061dab0d1a8/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
emilk authored Mar 18, 2024
1 parent 1a79510 commit c8ab078
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 49 deletions.
90 changes: 66 additions & 24 deletions crates/re_data_ui/src/item_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! TODO(andreas): This is not a `data_ui`, can this go somewhere else, shouldn't be in `re_data_ui`.
use re_entity_db::{EntityTree, InstancePath};
use re_log_types::external::re_types_core::components::InstanceKey;
use re_log_types::{ComponentPath, EntityPath, TimeInt, Timeline};
use re_ui::SyntaxHighlighting;
use re_viewer_context::{HoverHighlight, Item, SpaceViewId, UiVerbosity, ViewerContext};
Expand Down Expand Up @@ -62,22 +61,29 @@ pub fn entity_path_parts_buttons(
space_view_id: Option<SpaceViewId>,
entity_path: &EntityPath,
) -> egui::Response {
let with_icon = false; // too much noise with icons in a path

ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 4.0;
ui.spacing_mut().item_spacing.x = 2.0;

// Show one single icon up-front instead:
let instance_path = InstancePath::entity_splat(entity_path.clone());
ui.add(instance_path_icon(&query.timeline, store, &instance_path).as_image());

let mut accumulated = Vec::new();
for part in entity_path.iter() {
accumulated.push(part.clone());

ui.strong("/");
entity_path_button_to(
instance_path_button_to_ex(
ctx,
query,
store,
ui,
space_view_id,
&accumulated.clone().into(),
&InstancePath::entity_splat(accumulated.clone().into()),
part.syntax_highlighted(ui.style()),
with_icon,
);
}
})
Expand Down Expand Up @@ -134,17 +140,19 @@ pub fn instance_path_icon(
store: &re_data_store::DataStore,
instance_path: &InstancePath,
) -> &'static re_ui::icons::Icon {
if instance_path.instance_key != InstanceKey::SPLAT {
return &re_ui::icons::ENTITY;
}

if store
.all_components(timeline, &instance_path.entity_path)
.is_some()
{
&re_ui::icons::ENTITY
if instance_path.is_splat() {
// It is an entity path
if store
.all_components(timeline, &instance_path.entity_path)
.is_some()
{
&re_ui::icons::ENTITY
} else {
&re_ui::icons::ENTITY_EMPTY
}
} else {
&re_ui::icons::ENTITY_EMPTY
// An instance path
&re_ui::icons::ENTITY
}
}

Expand Down Expand Up @@ -190,25 +198,52 @@ pub fn instance_path_button_to(
space_view_id: Option<SpaceViewId>,
instance_path: &InstancePath,
text: impl Into<egui::WidgetText>,
) -> egui::Response {
instance_path_button_to_ex(
ctx,
query,
store,
ui,
space_view_id,
instance_path,
text,
true,
)
}

/// Show an instance id and make it selectable.
#[allow(clippy::too_many_arguments)]
fn instance_path_button_to_ex(
ctx: &ViewerContext<'_>,
query: &re_data_store::LatestAtQuery,
store: &re_data_store::DataStore,
ui: &mut egui::Ui,
space_view_id: Option<SpaceViewId>,
instance_path: &InstancePath,
text: impl Into<egui::WidgetText>,
with_icon: bool,
) -> egui::Response {
let item = if let Some(space_view_id) = space_view_id {
Item::DataResult(space_view_id, instance_path.clone())
} else {
Item::InstancePath(instance_path.clone())
};

let response = ctx
.re_ui
.selectable_label_with_icon(
let response = if with_icon {
ctx.re_ui.selectable_label_with_icon(
ui,
instance_path_icon(&query.timeline, store, instance_path),
text,
ctx.selection().contains_item(&item),
re_ui::LabelStyle::Normal,
)
.on_hover_ui(|ui| {
instance_hover_card_ui(ui, ctx, query, store, instance_path);
});
} else {
ui.selectable_label(ctx.selection().contains_item(&item), text)
};

let response = response.on_hover_ui(|ui| {
instance_hover_card_ui(ui, ctx, query, store, instance_path);
});

cursor_interact_with_selectable(ctx, response, item)
}
Expand All @@ -222,35 +257,42 @@ pub fn instance_path_parts_buttons(
space_view_id: Option<SpaceViewId>,
instance_path: &InstancePath,
) -> egui::Response {
let with_icon = false; // too much noise with icons in a path

ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 4.0;
ui.spacing_mut().item_spacing.x = 2.0;

// Show one single icon up-front instead:
ui.add(instance_path_icon(&query.timeline, store, instance_path).as_image());

let mut accumulated = Vec::new();
for part in instance_path.entity_path.iter() {
accumulated.push(part.clone());

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

if !instance_path.instance_key.is_splat() {
ui.strong("/");
instance_path_button_to(
instance_path_button_to_ex(
ctx,
query,
store,
ui,
space_view_id,
instance_path,
instance_path.instance_key.syntax_highlighted(ui.style()),
with_icon,
);
}
})
Expand Down
51 changes: 26 additions & 25 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ fn what_is_selected_ui(

item_title_ui(ctx.re_ui, ui, &title, Some(&re_ui::icons::STORE), &id_str);
}

Item::Container(container_id) => {
if let Some(container_blueprint) = viewport.container(container_id) {
item_title_ui(
Expand All @@ -329,6 +330,7 @@ fn what_is_selected_ui(
);
}
}

Item::ComponentPath(re_log_types::ComponentPath {
entity_path,
component_name,
Expand All @@ -354,6 +356,7 @@ fn what_is_selected_ui(

list_existing_data_blueprints(ui, ctx, &entity_path.clone().into(), viewport);
}

Item::SpaceView(space_view_id) => {
if let Some(space_view) = viewport.space_view(space_view_id) {
let space_view_class = space_view.class(ctx.space_view_class_registry);
Expand Down Expand Up @@ -381,20 +384,10 @@ fn what_is_selected_ui(
.on_hover_text(hover_text);
}
}
Item::InstancePath(instance_path) => {
let is_instance = !instance_path.instance_key.is_splat();

Item::InstancePath(instance_path) => {
let typ = item.kind();

let (query, store) =
guess_query_and_store_for_selected_entity(ctx, &instance_path.entity_path);

let name = instance_path.syntax_highlighted(ui.style());
let parent = if is_instance {
Some(instance_path.entity_path.clone())
} else {
instance_path.entity_path.parent()
};

item_title_ui(
ctx.re_ui,
Expand All @@ -404,10 +397,18 @@ fn what_is_selected_ui(
&format!("{typ} '{instance_path}'"),
);

let is_instance = !instance_path.instance_key.is_splat();
let parent = if is_instance {
Some(instance_path.entity_path.clone())
} else {
instance_path.entity_path.parent()
};
if let Some(parent) = parent {
if !parent.is_root() {
let (query, store) =
guess_query_and_store_for_selected_entity(ctx, &instance_path.entity_path);
ui.horizontal(|ui| {
ui.label("path");
ui.label("Parent");
item_ui::entity_path_parts_buttons(ctx, &query, store, ui, None, &parent);
});
}
Expand All @@ -417,21 +418,10 @@ fn what_is_selected_ui(
}

Item::DataResult(space_view_id, instance_path) => {
let is_instance = !instance_path.instance_key.is_splat();

let typ = item.kind();

let (query, store) =
guess_query_and_store_for_selected_entity(ctx, &instance_path.entity_path);

let name = instance_path.syntax_highlighted(ui.style());
let parent = if is_instance {
Some(instance_path.entity_path.clone())
} else {
instance_path.entity_path.parent()
};

if let Some(space_view) = viewport.space_view(space_view_id) {
let typ = item.kind();
item_title_ui(
ctx.re_ui,
ui,
Expand All @@ -443,10 +433,21 @@ fn what_is_selected_ui(
),
);

let is_instance = !instance_path.instance_key.is_splat();
let parent = if is_instance {
Some(instance_path.entity_path.clone())
} else {
instance_path.entity_path.parent()
};
if let Some(parent) = parent {
if !parent.is_root() {
ui.horizontal(|ui| {
ui.label("path");
let (query, store) = guess_query_and_store_for_selected_entity(
ctx,
&instance_path.entity_path,
);

ui.label("Parent");
item_ui::entity_path_parts_buttons(
ctx,
&query,
Expand Down

0 comments on commit c8ab078

Please sign in to comment.