Skip to content

Commit

Permalink
Get it to work
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 8, 2024
1 parent 6344f2e commit 5b9aa8d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
4 changes: 3 additions & 1 deletion crates/viewer/re_viewport/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ impl<'a> Viewport<'a> {
re_log::trace!("Processing tree action: {tree_action:?}");
match tree_action {
TreeAction::AddSpaceView(space_view_id, parent_container, position_in_parent) => {
if self.blueprint.auto_layout() {
// if self.blueprint.auto_layout()
if false {
// TODO: why was this code here?
// Re-run the auto-layout next frame:
re_log::trace!(
"Added a space view with no user edits yet - will re-run auto-layout"
Expand Down
4 changes: 2 additions & 2 deletions crates/viewer/re_viewport_blueprint/src/tree_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use re_viewer_context::{ContainerId, Contents, SpaceViewId};
#[derive(Clone, Debug)]
pub enum TreeAction {
/// Add a new space view to the provided container (or the root if `None`).
AddSpaceView(SpaceViewId, Option<ContainerId>, Option<usize>),
AddSpaceView(SpaceViewId, Option<ContainerId>, Option<usize>), // TODO: name fields

/// Add a new container of the provided kind to the provided container (or the root if `None`).
AddContainer(egui_tiles::ContainerKind, Option<ContainerId>),
AddContainer(egui_tiles::ContainerKind, Option<ContainerId>), // TODO: name fields

/// Change the kind of a container.
SetContainerKind(ContainerId, egui_tiles::ContainerKind),
Expand Down
40 changes: 34 additions & 6 deletions crates/viewer/re_viewport_blueprint/src/viewport_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ impl ViewportBlueprint {
parent_container: Option<ContainerId>,
position_in_parent: Option<usize>,
) -> Vec<SpaceViewId> {
let parent_container_id = parent_container.unwrap_or(self.root_container);

let mut new_ids: Vec<_> = vec![];

for space_view in space_views {
Expand All @@ -423,12 +425,38 @@ impl ViewportBlueprint {
new_ids.push(space_view_id);
}

for id in &new_ids {
self.send_tree_action(TreeAction::AddSpaceView(
*id,
parent_container,
position_in_parent,
));
if !new_ids.is_empty() {
let mut container = self
.containers
.get(&parent_container_id)
.cloned()
.unwrap_or_else(|| {
self.send_tree_action(TreeAction::AddContainer(
egui_tiles::ContainerKind::Grid,
None,
));
ContainerBlueprint {
id: parent_container_id,
..Default::default()
}
});
for &space_view_id in &new_ids {
container.add_child(Contents::SpaceView(space_view_id));
}
re_log::trace!(
"Added {} space-views to container {parent_container_id}; now contains: {:?}",
new_ids.len(),
container.contents,
);
container.save_to_blueprint_store(ctx);

for id in &new_ids {
self.send_tree_action(TreeAction::AddSpaceView(
*id,
Some(parent_container_id),
position_in_parent,
));
}
}

new_ids
Expand Down

0 comments on commit 5b9aa8d

Please sign in to comment.