Skip to content

Commit

Permalink
Different icon for empty entity paths (#5338)
Browse files Browse the repository at this point in the history
### What

This PR adds a subtly different icon for "empty" entities. By "empty", I
mean "no component logged _on the current timeline_". This means that
changing timeline may potentially change the icon of some entity (though
it takes a somewhat contrived example to do so).

TODO:
- [x] do the same in blueprint tree after
#5326 is merged

<img width="187" alt="image"
src="https://github.com/rerun-io/rerun/assets/49431240/197d99ce-9f51-4468-85ce-978e6fd92b43">
<img width="252" alt="image"
src="https://github.com/rerun-io/rerun/assets/49431240/bde725d6-aa6b-44ed-9faa-3ce1c6ec7915">
<img width="249" alt="image"
src="https://github.com/rerun-io/rerun/assets/49431240/23e4168f-ddd9-4f10-91c5-fbfc79736d2b">
<img width="195" alt="image"
src="https://github.com/rerun-io/rerun/assets/49431240/b0dc0113-9b43-4248-9718-c33b7a2444b7">


Fixes #5302



### 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/5338/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/5338/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/5338/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/5338)
- [Docs
preview](https://rerun.io/preview/33ddbf880c630f2053e269d9403230dde1ab63ca/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/33ddbf880c630f2053e269d9403230dde1ab63ca/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
abey79 committed Mar 4, 2024
1 parent 4e0673d commit eaec30f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 31 deletions.
59 changes: 58 additions & 1 deletion crates/re_data_ui/src/item_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! 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 @@ -124,6 +125,62 @@ pub fn instance_path_button(
)
}

/// Return the instance path icon.
///
/// The choice of icon is based on whether the instance is "empty" as in hasn't any logged component
/// _on the current timeline_.
pub fn instance_path_icon(
timeline: &re_data_store::Timeline,
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
} else {
&re_ui::icons::ENTITY_EMPTY
}
}

/// The current time query, based on the current time control and an `entity_path`
///
/// If the user is inspecting the blueprint, and the `entity_path` is on the blueprint
/// timeline, then use the blueprint. Otherwise, use the recording.
// TODO(jleibs): Ideally this wouldn't be necessary and we could make the assessment
// directly from the entity_path.
pub fn guess_query_and_store_for_selected_entity<'a>(
ctx: &'a ViewerContext<'_>,
entity_path: &EntityPath,
) -> (re_data_store::LatestAtQuery, &'a re_data_store::DataStore) {
if ctx.app_options.inspect_blueprint_timeline
&& ctx.store_context.blueprint.is_logged_entity(entity_path)
{
(
ctx.blueprint_cfg.time_ctrl.read().current_query(),
ctx.store_context.blueprint.store(),
)
} else {
(
ctx.rec_cfg.time_ctrl.read().current_query(),
ctx.entity_db.store(),
)
}
}

pub fn guess_instance_path_icon(
ctx: &ViewerContext<'_>,
instance_path: &InstancePath,
) -> &'static re_ui::icons::Icon {
let (query, store) = guess_query_and_store_for_selected_entity(ctx, &instance_path.entity_path);
instance_path_icon(&query.timeline, store, instance_path)
}

/// Show an instance id and make it selectable.
pub fn instance_path_button_to(
ctx: &ViewerContext<'_>,
Expand All @@ -144,7 +201,7 @@ pub fn instance_path_button_to(
.re_ui
.selectable_label_with_icon(
ui,
&re_ui::icons::ENTITY,
instance_path_icon(&query.timeline, store, instance_path),
text,
ctx.selection().contains_item(&item),
re_ui::LabelStyle::Normal,
Expand Down
6 changes: 5 additions & 1 deletion crates/re_time_panel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod time_selection_ui;
use egui::emath::Rangef;
use egui::{pos2, Color32, CursorIcon, NumExt, Painter, PointerButton, Rect, Shape, Ui, Vec2};

use re_data_ui::item_ui::guess_instance_path_icon;
use re_entity_db::{EntityTree, InstancePath, TimeHistogram};
use re_log_types::{
external::re_types_core::ComponentName, ComponentPath, EntityPath, EntityPathPart, TimeInt,
Expand Down Expand Up @@ -573,7 +574,10 @@ impl TimePanel {
item_response: response,
body_response,
} = ListItem::new(ctx.re_ui, text)
.with_icon(&re_ui::icons::ENTITY)
.with_icon(guess_instance_path_icon(
ctx,
&InstancePath::from(tree.path.clone()),
))
.width_allocation_mode(WidthAllocationMode::Compact)
.selected(is_selected)
.force_hovered(is_item_hovered)
Expand Down
35 changes: 7 additions & 28 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use egui::{NumExt as _, Ui};

use re_data_ui::{image_meaning_for_entity, item_ui, DataUi};
use re_data_ui::{
image_meaning_for_entity, item_ui,
item_ui::{guess_instance_path_icon, guess_query_and_store_for_selected_entity},
DataUi,
};
use re_entity_db::{
ColorMapper, Colormap, EditableAutoValue, EntityPath, EntityProperties, InstancePath,
};
Expand Down Expand Up @@ -37,31 +41,6 @@ pub(crate) struct SelectionPanel {
selection_state_ui: SelectionHistoryUi,
}

/// The current time query, based on the current time control and an `entity_path`
///
/// If the user is inspecting the blueprint, and the `entity_path` is on the blueprint
/// timeline, then use the blueprint. Otherwise use the recording.
// TODO(jleibs): Ideally this wouldn't be necessary and we could make the assessment
// directly from the entity_path.
fn guess_query_and_store_for_selected_entity<'a>(
ctx: &'a ViewerContext<'_>,
entity_path: &EntityPath,
) -> (re_data_store::LatestAtQuery, &'a re_data_store::DataStore) {
if ctx.app_options.inspect_blueprint_timeline
&& ctx.store_context.blueprint.is_logged_entity(entity_path)
{
(
ctx.blueprint_cfg.time_ctrl.read().current_query(),
ctx.store_context.blueprint.store(),
)
} else {
(
ctx.rec_cfg.time_ctrl.read().current_query(),
ctx.entity_db.store(),
)
}
}

impl SelectionPanel {
pub fn show_panel(
&mut self,
Expand Down Expand Up @@ -423,7 +402,7 @@ fn what_is_selected_ui(
ctx.re_ui,
ui,
name,
Some(&re_ui::icons::ENTITY),
Some(guess_instance_path_icon(ctx, instance_path)),
&format!("{typ} '{instance_path}'"),
);

Expand Down Expand Up @@ -459,7 +438,7 @@ fn what_is_selected_ui(
ctx.re_ui,
ui,
name,
Some(&re_ui::icons::ENTITY),
Some(guess_instance_path_icon(ctx, instance_path)),
&format!(
"{typ} '{instance_path}' as shown in Space View {:?}",
space_view.display_name
Expand Down
6 changes: 5 additions & 1 deletion crates/re_viewport/src/viewport_blueprint_ui.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use egui::{Response, Ui};
use itertools::Itertools;
use re_data_ui::item_ui::guess_instance_path_icon;

use re_entity_db::InstancePath;
use re_log_types::EntityPath;
Expand Down Expand Up @@ -432,7 +433,10 @@ impl Viewport<'_, '_> {

let list_item = ListItem::new(ctx.re_ui, item_label)
.selected(is_selected)
.with_icon(&re_ui::icons::ENTITY)
.with_icon(guess_instance_path_icon(
ctx,
&InstancePath::from(entity_path.clone()),
))
.subdued(subdued)
.force_hovered(is_item_hovered)
.with_buttons(|re_ui: &_, ui: &mut egui::Ui| {
Expand Down

0 comments on commit eaec30f

Please sign in to comment.