Skip to content

Commit

Permalink
Disallow hiding/removing root container
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Feb 14, 2024
1 parent 21f8516 commit 9309f41
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions crates/re_viewport/src/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,43 @@ trait ContextMenuItem {
// selections
fn context_menu_items_for_item(
ctx: &ViewerContext<'_>,
viewport_blueprint: &ViewportBlueprint,
item: &Item,
) -> Vec<Box<dyn ContextMenuItem>> {
match item {
Item::Container(container_id) => vec![
ContentVisibilityToggle::item(Contents::Container(*container_id)),
ContentRemove::item(Contents::Container(*container_id)),
Separator::item(),
SubMenu::item(
"Add Container",
[
AddContainer::item(*container_id, egui_tiles::ContainerKind::Tabs),
AddContainer::item(*container_id, egui_tiles::ContainerKind::Horizontal),
AddContainer::item(*container_id, egui_tiles::ContainerKind::Vertical),
AddContainer::item(*container_id, egui_tiles::ContainerKind::Grid),
],
),
SubMenu::item(
"Add Space View",
ctx.space_view_class_registry
.iter_registry()
.sorted_by_key(|entry| entry.class.display_name())
.map(|entry| AddSpaceView::item(*container_id, entry.class.identifier())),
),
],
Item::Container(container_id) => {
let mut items = vec![];

// only show/hide and remove if it's not the root container
if Some(*container_id) != viewport_blueprint.root_container {
items.extend([
ContentVisibilityToggle::item(Contents::Container(*container_id)),
ContentRemove::item(Contents::Container(*container_id)),
Separator::item(),
]);
}

items.extend([
SubMenu::item(
"Add Container",
[
AddContainer::item(*container_id, egui_tiles::ContainerKind::Tabs),
AddContainer::item(*container_id, egui_tiles::ContainerKind::Horizontal),
AddContainer::item(*container_id, egui_tiles::ContainerKind::Vertical),
AddContainer::item(*container_id, egui_tiles::ContainerKind::Grid),
],
),
SubMenu::item(
"Add Space View",
ctx.space_view_class_registry
.iter_registry()
.sorted_by_key(|entry| entry.class.display_name())
.map(|entry| AddSpaceView::item(*container_id, entry.class.identifier())),
),
]);

items
}
Item::SpaceView(space_view_id) => vec![
ContentVisibilityToggle::item(Contents::SpaceView(*space_view_id)),
ContentRemove::item(Contents::SpaceView(*space_view_id)),
Expand All @@ -78,7 +91,7 @@ pub fn context_menu_ui_for_item(
item_response: &egui::Response,
) {
item_response.context_menu(|ui| {
let actions = context_menu_items_for_item(ctx, item);
let actions = context_menu_items_for_item(ctx, viewport_blueprint, item);
for action in actions {
let response = action.ui(ctx, viewport_blueprint, ui);
if response.clicked() {
Expand Down

0 comments on commit 9309f41

Please sign in to comment.