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

Clear empty containers after tile drag-and-drop #5044

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,6 @@ emath = { git = "https://github.com/emilk/egui.git", rev = "c5352cf6c16b28d00432
# egui-wgpu = { path = "../../egui/crates/egui-wgpu" }
# emath = { path = "../../egui/crates/emath" }

egui_tiles = { git = "https://github.com/rerun-io/egui_tiles", rev = "35e711283e7a021ca425d9fbd8e7581548971f49" } # master 2024-01-26
egui_tiles = { git = "https://github.com/rerun-io/egui_tiles", rev = "be78596d3564f696b61a1ba14678b0aa0bfcdb2f" } # master 2024-02-05

# egui_commonmark = { git = "https://github.com/rerun-io/egui_commonmark", rev = "3d83a92f995a1d18ab1172d0b129d496e0eedaae" } # Update to egui 0.25 https://github.com/lampsitter/egui_commonmark/pull/27
8 changes: 6 additions & 2 deletions crates/re_viewer/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,17 @@ impl AppState {
// this, which gives us interior mutability (only a shared reference of `ViewportBlueprint`
// is available to the UI code) and, if needed in the future, concurrency.
let (sender, receiver) = std::sync::mpsc::channel();
let viewport_blueprint =
ViewportBlueprint::try_from_db(store_context.blueprint, &blueprint_query, sender);
let viewport_blueprint = ViewportBlueprint::try_from_db(
store_context.blueprint,
&blueprint_query,
sender.clone(),
);
let mut viewport = Viewport::new(
&viewport_blueprint,
viewport_state,
space_view_class_registry,
receiver,
sender,
);

// If the blueprint is invalid, reset it.
Expand Down
56 changes: 53 additions & 3 deletions crates/re_viewport/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::collections::BTreeMap;

use ahash::HashMap;
use egui_tiles::Behavior as _;
use egui_tiles::{Behavior as _, EditAction};
use once_cell::sync::Lazy;

use re_entity_db::EntityPropertyMap;
Expand Down Expand Up @@ -166,6 +166,11 @@ pub struct Viewport<'a, 'b> {
/// We delay any modifications to the tree until the end of the frame,
/// so that we don't mutate something while inspecting it.
tree_action_receiver: std::sync::mpsc::Receiver<TreeAction>,

/// Tree action sender
///
/// Used to pass along `TabViewer`.
tree_action_sender: std::sync::mpsc::Sender<TreeAction>,
}

impl<'a, 'b> Viewport<'a, 'b> {
Expand All @@ -174,6 +179,7 @@ impl<'a, 'b> Viewport<'a, 'b> {
state: &'b mut ViewportState,
space_view_class_registry: &SpaceViewClassRegistry,
tree_action_receiver: std::sync::mpsc::Receiver<TreeAction>,
tree_action_sender: std::sync::mpsc::Sender<TreeAction>,
) -> Self {
re_tracing::profile_function!();

Expand All @@ -196,6 +202,7 @@ impl<'a, 'b> Viewport<'a, 'b> {
tree,
tree_edited: edited,
tree_action_receiver,
tree_action_sender,
}
}

Expand Down Expand Up @@ -271,6 +278,8 @@ impl<'a, 'b> Viewport<'a, 'b> {
edited: false,
executed_systems_per_space_view,
contents_per_tile_id,
tree_action_sender: self.tree_action_sender.clone(),
root_container_id: self.blueprint.root_container,
};

tree.ui(&mut tab_viewer, ui);
Expand Down Expand Up @@ -537,6 +546,8 @@ struct TabViewer<'a, 'b> {
ctx: &'a ViewerContext<'b>,
space_views: &'a BTreeMap<SpaceViewId, SpaceViewBlueprint>,
maximized: &'a mut Option<SpaceViewId>,
root_container_id: Option<ContainerId>,
tree_action_sender: std::sync::mpsc::Sender<TreeAction>,

/// List of query & system execution results for each space view.
executed_systems_per_space_view: HashMap<SpaceViewId, (ViewQuery<'a>, SystemExecutionOutput)>,
Expand Down Expand Up @@ -770,8 +781,47 @@ impl<'a, 'b> egui_tiles::Behavior<SpaceViewId> for TabViewer<'a, 'b> {

// Callbacks:

fn on_edit(&mut self) {
self.edited = true;
fn on_edit(&mut self, edit_action: egui_tiles::EditAction) {
match edit_action {
EditAction::TileResized | EditAction::TileDragged => {}
EditAction::TileDropped => {
// TODO(ab): when we finally stop using egui_tiles as application-level data
// structure, this work-around should be unnecessary.

// The continuous simplification options are considerably reduced when the additive
// workflow is enabled. Due to the egui_tiles -> blueprint synchronisation process,
// drag and drop operation often lead to many spurious empty containers. To work
// around this, we run a simplification pass when a drop occurs.
if self.ctx.app_options.experimental_additive_workflow {
if let Some(root_container_id) = self.root_container_id {
if self
.tree_action_sender
.send(TreeAction::SimplifyContainer(
root_container_id,
egui_tiles::SimplificationOptions {
prune_empty_tabs: true,
prune_empty_containers: false,
prune_single_child_tabs: true,
prune_single_child_containers: false,
all_panes_must_have_tabs: true,
join_nested_linear_containers: false,
},
))
.is_err()
{
re_log::warn_once!(
"Channel between ViewportBlueprint and Viewport is broken"
);
}
}
}

self.edited = true;
}
EditAction::TabSelected => {
self.edited = true;
}
}
}
}

Expand Down
Loading