Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow adding Horizontal/Vertical containers inside of containers with the same type #5091

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 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,34 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe parent_container_kind is more descriptive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have "target_container" all over the place in that file, so I'd keep it as is for consistency.

.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
&& matches!(
kind,
egui_tiles::ContainerKind::Horizontal | 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
Loading