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

Add button to equalize the size of the children of a container #6194

Merged
merged 2 commits into from
May 3, 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
29 changes: 29 additions & 0 deletions crates/re_viewer/src/ui/selection_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,35 @@ fn container_top_level_properties(
},
);
}
ui.end_row();

// ---

fn equal_shares(shares: &[f32]) -> bool {
shares.iter().all(|&share| share == shares[0])
}

let all_shares_are_equal =
equal_shares(&container.col_shares) && equal_shares(&container.row_shares);

if container.contents.len() > 1
&& match container.container_kind {
egui_tiles::ContainerKind::Tabs => false,
egui_tiles::ContainerKind::Horizontal
| egui_tiles::ContainerKind::Vertical
| egui_tiles::ContainerKind::Grid => true,
}
&& ui
.add_enabled(
!all_shares_are_equal,
egui::Button::new("Distribute content equally"),
)
.on_hover_text("Make all children the same size")
.clicked()
{
viewport.blueprint.make_all_children_same_size(container_id);
}
ui.end_row();
});
}

Expand Down
21 changes: 21 additions & 0 deletions crates/re_viewport/src/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ pub enum TreeAction {
/// Simplify the container with the provided options
SimplifyContainer(ContainerId, egui_tiles::SimplificationOptions),

/// Make all column and row shares the same for this container
MakeAllChildrenSameSize(ContainerId),

/// Move some contents to a different container
MoveContents {
contents_to_move: Contents,
Expand Down Expand Up @@ -460,6 +463,24 @@ impl<'a, 'b> Viewport<'a, 'b> {
self.tree.simplify_children_of_tile(tile_id, &options);
self.tree_edited = true;
}
TreeAction::MakeAllChildrenSameSize(container_id) => {
let tile_id = blueprint_id_to_tile_id(&container_id);
if let Some(egui_tiles::Tile::Container(container)) =
self.tree.tiles.get_mut(tile_id)
{
match container {
egui_tiles::Container::Tabs(_) => {}
egui_tiles::Container::Linear(linear) => {
linear.shares = Default::default();
}
egui_tiles::Container::Grid(grid) => {
grid.col_shares = Default::default();
grid.row_shares = Default::default();
}
}
}
self.tree_edited = true;
}
TreeAction::MoveContents {
contents_to_move,
target_container,
Expand Down
5 changes: 5 additions & 0 deletions crates/re_viewport/src/viewport_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,11 @@ impl ViewportBlueprint {
));
}

/// Make all children of the given container the same size.
pub fn make_all_children_same_size(&self, container_id: &ContainerId) {
self.send_tree_action(TreeAction::MakeAllChildrenSameSize(*container_id));
}

/// Set the container that is currently identified as the drop target of an ongoing drag.
///
/// This is used for highlighting the drop target in the UI. Note that the drop target container is reset at every
Expand Down
Loading