Skip to content

Commit

Permalink
More context menu 2: add support to show/hide DataResults (#5397)
Browse files Browse the repository at this point in the history
### What

The `Hide` and `Show` actions now support `DataResult`s as well.

With that, it's easier than ever to run into:
- #5396
- #5310

<img width="313" alt="image"
src="https://github.com/rerun-io/rerun/assets/49431240/d6ee0b27-3438-4c95-b60d-7ed95ca26061">


### 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/5397/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/5397/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/5397/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/5397)
- [Docs
preview](https://rerun.io/preview/5fb3cb84bb6be6f6b133dd82e2d2a19b9d9ce4a9/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/5fb3cb84bb6be6f6b133dd82e2d2a19b9d9ce4a9/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 authored Mar 6, 2024
1 parent 8ebb5df commit e77b518
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 13 deletions.
79 changes: 77 additions & 2 deletions crates/re_viewport/src/context_menu/actions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use re_entity_db::InstancePath;
use re_log_types::{EntityPath, EntityPathFilter};
use re_space_view::{DataQueryBlueprint, SpaceViewBlueprint};
use re_viewer_context::{ContainerId, Item, SpaceViewClassIdentifier, SpaceViewId};
Expand All @@ -18,6 +19,9 @@ impl ContextMenuAction for ShowAction {
.is_contents_visible(&Contents::Container(*container_id))
&& ctx.viewport_blueprint.root_container != Some(*container_id)
}
Item::DataResult(space_view_id, instance_path) => {
data_result_visible(ctx, space_view_id, instance_path).is_some_and(|vis| !vis)
}
_ => false,
})
}
Expand Down Expand Up @@ -45,9 +49,16 @@ impl ContextMenuAction for ShowAction {
true,
);
}
}

// ---
fn process_data_result(
&self,
ctx: &ContextMenuContext<'_>,
space_view_id: &SpaceViewId,
instance_path: &InstancePath,
) {
set_data_result_visible(ctx, space_view_id, instance_path, true);
}
}

pub(super) struct HideAction;

Expand All @@ -62,6 +73,9 @@ impl ContextMenuAction for HideAction {
.is_contents_visible(&Contents::Container(*container_id))
&& ctx.viewport_blueprint.root_container != Some(*container_id)
}
Item::DataResult(space_view_id, instance_path) => {
data_result_visible(ctx, space_view_id, instance_path).unwrap_or(false)
}
_ => false,
})
}
Expand Down Expand Up @@ -89,6 +103,67 @@ impl ContextMenuAction for HideAction {
false,
);
}

fn process_data_result(
&self,
ctx: &ContextMenuContext<'_>,
space_view_id: &SpaceViewId,
instance_path: &InstancePath,
) {
set_data_result_visible(ctx, space_view_id, instance_path, false);
}
}

fn data_result_visible(
ctx: &ContextMenuContext<'_>,
space_view_id: &SpaceViewId,
instance_path: &InstancePath,
) -> Option<bool> {
instance_path
.is_splat()
.then(|| {
ctx.viewport_blueprint
.space_view(space_view_id)
.and_then(|space_view| {
let query_result = ctx
.viewer_context
.lookup_query_result(space_view.query_id());
query_result
.tree
.lookup_result_by_path(&instance_path.entity_path)
.map(|data_result| {
data_result
.recursive_properties()
.map_or(true, |prop| prop.visible)
})
})
})
.flatten()
}

fn set_data_result_visible(
ctx: &ContextMenuContext<'_>,
space_view_id: &SpaceViewId,
instance_path: &InstancePath,
visible: bool,
) {
if let Some(space_view) = ctx.viewport_blueprint.space_view(space_view_id) {
let query_result = ctx
.viewer_context
.lookup_query_result(space_view.query_id());
if let Some(data_result) = query_result
.tree
.lookup_result_by_path(&instance_path.entity_path)
{
let mut recursive_properties = data_result
.recursive_properties()
.cloned()
.unwrap_or_default();
recursive_properties.visible = visible;

data_result.save_recursive_override(ctx.viewer_context, Some(recursive_properties));
}
}
}

// ---
Expand Down
16 changes: 13 additions & 3 deletions crates/re_viewport/src/viewport_blueprint_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Viewport<'_, '_> {
default_open,
|_, ui| {
// Always show the origin hierarchy first.
Self::space_view_entity_hierarchy_ui(
self.space_view_entity_hierarchy_ui(
ctx,
ui,
query_result,
Expand Down Expand Up @@ -323,7 +323,7 @@ impl Viewport<'_, '_> {
ui.label(egui::RichText::new("Projections:").italics());

for projection in projections {
Self::space_view_entity_hierarchy_ui(
self.space_view_entity_hierarchy_ui(
ctx,
ui,
query_result,
Expand Down Expand Up @@ -365,7 +365,9 @@ impl Viewport<'_, '_> {
);
}

#[allow(clippy::too_many_arguments)]
fn space_view_entity_hierarchy_ui(
&self,
ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
query_result: &DataQueryResult,
Expand Down Expand Up @@ -491,7 +493,7 @@ impl Viewport<'_, '_> {
continue;
};

Self::space_view_entity_hierarchy_ui(
self.space_view_entity_hierarchy_ui(
ctx,
ui,
query_result,
Expand All @@ -517,6 +519,14 @@ impl Viewport<'_, '_> {
let query = ctx.current_query();
re_data_ui::item_ui::entity_hover_card_ui(ui, ctx, &query, store, entity_path);
});

context_menu_ui_for_item(
ctx,
self.blueprint,
&item,
&response,
SelectionUpdateBehavior::UseSelection,
);
ctx.select_hovered_on_click(&response, item);
}

Expand Down
20 changes: 12 additions & 8 deletions tests/python/release_checklist/check_context_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Reset the blueprint.
* Right-click on any space view and check for context menu content:
- Hide
- Hide (or Show, depending on visibility)
- Remove
- Clone
- Move to new container
Expand All @@ -26,19 +26,17 @@
- Add Space View
* Add a container via the context menu, check the container appears at then end of the list.
* Right-click on the container and check for context menu content:
- Hide
- Hide (or Show, depending on visibility)
- Remove
- Add Container
- Add Space View
- Move to new container
* Right-click on a data result and check for the context menu content:
- Hide (or Show, depending on visibility)
* Select a container and, in the Selection Panel, right click on either space view or container children:
- The context menu action should be the same as before.
- The selection state is not affected by the right-click.
### Show/Hide
* Hide a space view and check that its context menu shows "Show" instead of "Hide".
* Select multiple space views with homogeneous or heterogeneous visibility states. Check that either or both of "Show All" and "Hide All" are showed as appropriate.
### Selection behavior
Expand All @@ -52,12 +50,18 @@
### Multi-selection checks
* Select multiple space views, right-click, and check for context menu content:
- Hide
- Hide All (if any are visible)
- Show All (if any are hidden)
- Remove
- Move to new container
* Same as above, but with only containers selected.
* Same as above, but with both space views and containers selected.
* Same as above, but with the viewport selected as well. The context menu should be identical, but none of its actions should apply to the viewport.
* Same as above, but with the viewport selected as well, and check for context menu content. These should not affect the Viewport.
- Hide All (if any are visible)
- Show All (if any are hidden)
* Select a mix of containers, space views, and data results, and check for context menu content:
- Hide All (if any are visible)
- Show All (if any are hidden)
### Invalid sub-container kind
Expand Down

0 comments on commit e77b518

Please sign in to comment.