Skip to content

Commit

Permalink
Add button to equalize the size of the children of a container (#6194)
Browse files Browse the repository at this point in the history
### What

When drag-dropping tiles it's easy for the tiles to get very unevenly
sized. This helps.


https://github.com/rerun-io/rerun/assets/1148717/efc9f152-a724-4f9a-b505-40d5a22ecd4a

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6194?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6194?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6194)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.

---------

Co-authored-by: Nikolaus West <[email protected]>
  • Loading branch information
emilk and nikolausWest authored May 3, 2024
1 parent 68c39f0 commit b938213
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
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 @@ -670,6 +670,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

0 comments on commit b938213

Please sign in to comment.