Skip to content

Commit

Permalink
More context menus 2: DataResult visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Mar 5, 2024
1 parent 9d0d2a3 commit 244b37c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 5 deletions.
78 changes: 76 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,66 @@ 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> {
if instance_path.is_splat() {
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());
query_result
.tree
.lookup_result_by_path(&instance_path.entity_path)
.map(|data_result| {
data_result
.recursive_properties()
.map_or(true, |prop| prop.visible)
})
} else {
None
}
} else {
None
}
}

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

0 comments on commit 244b37c

Please sign in to comment.