Skip to content

Commit

Permalink
Do not allow adding Horizontal/Vertical containers inside of containe…
Browse files Browse the repository at this point in the history
…rs with the same type

- Fixes #5082
  • Loading branch information
abey79 committed Feb 7, 2024
1 parent e0f51ab commit 8cddd46
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion crates/re_viewport/src/add_space_view_or_container_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use itertools::Itertools;

use crate::container::blueprint_id_to_tile_id;
use crate::{icon_for_container_kind, ViewportBlueprint};
use re_log_types::{EntityPath, EntityPathFilter};
use re_space_view::{DataQueryBlueprint, SpaceViewBlueprint};
Expand Down Expand Up @@ -70,7 +71,32 @@ fn modal_ui(
];

for (title, subtitle, kind) in container_data {
if row_ui(ui, icon_for_container_kind(&kind), title, subtitle).clicked() {
let target_container_kind = target_container
.and_then(|container_id| {
viewport
.tree
.tiles
.get(blueprint_id_to_tile_id(&container_id))
})
.and_then(|tile| tile.container_kind());

// We disallow creating "linear" containers (horizontal/vertical) inside containers of the same kind, because
// it's not useful and is automatically simplified away.
let disabled = Some(kind) == target_container_kind
&& (target_container_kind == Some(egui_tiles::ContainerKind::Horizontal)
|| target_container_kind == Some(egui_tiles::ContainerKind::Vertical));

let resp = ui
.add_enabled_ui(!disabled, |ui| {
row_ui(ui, icon_for_container_kind(&kind), title, subtitle)
})
.inner
.on_disabled_hover_text(format!(
"Nested {title} containers in containers of the same type are disallowed and automatically simplified \
away as they are not useful."
));

if resp.clicked() {
viewport.add_container(kind, target_container);
viewport.mark_user_interaction(ctx);
*keep_open = false;
Expand Down

0 comments on commit 8cddd46

Please sign in to comment.