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

Invisible tiles #7

Merged
merged 24 commits into from
Jun 28, 2023
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# `egui_tiles` Changelog

## [Unreleased](https://github.com/rerun-io/rerun/compare/latest...HEAD)
* Add support for invisible tiles
* `PartialEq` for `Tiles` now ignores internal state
* Add `Tiles::find_pane`
* Add `Tiles::remove_recursively`


## 0.1.0 - Initial Release - 2023-05-24
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ all-features = true


[dependencies]
ahash = { version = "0.8.1", default-features = false, features = [
"no-rng", # we don't need DOS-protection for what we use ahash for
"std",
] }
egui = { version = "0.22", default-features = false }
getrandom = { version = "0.2", features = ["js"] }
itertools = "0.10"
itertools = "0.11"
log = { version = "0.4", features = ["std"] }
nohash-hasher = "0.2"
rand = { version = "0.8.5", features = ["getrandom", "small_rng"] }
serde = { version = "1", features = ["derive"] }


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Supports:
### Comparison with [egui_dock](https://github.com/Adanos020/egui_dock)
[egui_dock](https://github.com/Adanos020/egui_dock) is an excellent crate serving similar needs. `egui_tiles` aims to become a more flexible and feature-rich alternative to `egui_dock`.

`egui_dock` only supports binary splits (left/right or top/bottom), while `egui_tiles` support full horizontal and vertical layouts, as well as grid layouts. `egui_tiles` is also strives to be more customizable, enabling users to override the default style and behavior by implementing methods on a `Behavior` `trait`.
`egui_dock` only supports binary splits (left/right or top/bottom), while `egui_tiles` support full horizontal and vertical layouts, as well as grid layouts. `egui_tiles` also strives to be more customizable, enabling users to override the default style and behavior by implementing methods on a `Behavior` `trait`.

`egui_dock` supports some features that `egui_tiles` does not yet support, such as close-buttons on each tab, and built-in scroll areas.

Expand Down
10 changes: 10 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Release Checklist

* [ ] `git commit -m 'Release 0.x.0 - summary'`
* [ ] `cargo publish`
* [ ] `git tag -a 0.x.0 -m 'Release 0.x.0 - summary'`
* [ ] `git pull --tags && git tag -d latest && git tag -a latest -m 'Latest release' && git push --tags origin latest --force`
* [ ] `git push && git push --tags`
* [ ] Do a GitHub release: https://github.com/rerun-io/egui_tiles/releases/new
* [ ] Wait for documentation to build: https://docs.rs/releases/queue
* [ ] Post on Twitter
60 changes: 35 additions & 25 deletions examples/advanced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ impl eframe::App for MyApp {
ui.monospace(&tree_debug);
if self.last_tree_debug != tree_debug {
self.last_tree_debug = tree_debug;
log::debug!("{}", self.last_tree_debug);
}
});

Expand All @@ -265,35 +264,46 @@ fn tree_ui(
behavior.tab_title_for_tile(tiles, tile_id).text()
);

let Some(mut tile) = tiles.tiles.remove(&tile_id) else {
// Temporarily remove the tile to circumvent the borrowchecker
let Some(mut tile) = tiles.remove(tile_id) else {
log::warn!("Missing tile {tile_id:?}");
return;
};

egui::CollapsingHeader::new(text)
.id_source((tile_id, "tree"))
.default_open(true)
.show(ui, |ui| match &mut tile {
egui_tiles::Tile::Pane(_) => {}
egui_tiles::Tile::Container(container) => {
let mut kind = container.kind();
egui::ComboBox::from_label("Kind")
.selected_text(format!("{kind:?}"))
.show_ui(ui, |ui| {
for typ in egui_tiles::ContainerKind::ALL {
ui.selectable_value(&mut kind, typ, format!("{typ:?}"))
.clicked();
}
});
if kind != container.kind() {
container.set_kind(kind);
}
let default_open = true;
egui::collapsing_header::CollapsingState::load_with_default_open(
ui.ctx(),
egui::Id::new((tile_id, "tree")),
default_open,
)
.show_header(ui, |ui| {
ui.label(text);
let mut visible = tiles.is_visible(tile_id);
ui.checkbox(&mut visible, "Visible");
tiles.set_visible(tile_id, visible);
})
.body(|ui| match &mut tile {
egui_tiles::Tile::Pane(_) => {}
egui_tiles::Tile::Container(container) => {
let mut kind = container.kind();
egui::ComboBox::from_label("Kind")
.selected_text(format!("{kind:?}"))
.show_ui(ui, |ui| {
for typ in egui_tiles::ContainerKind::ALL {
ui.selectable_value(&mut kind, typ, format!("{typ:?}"))
.clicked();
}
});
if kind != container.kind() {
container.set_kind(kind);
}

for &child in container.children() {
tree_ui(ui, behavior, tiles, child);
}
for &child in container.children() {
tree_ui(ui, behavior, tiles, child);
}
});
}
});

tiles.tiles.insert(tile_id, tile);
// Put the tile back
tiles.insert(tile_id, tile);
}
17 changes: 8 additions & 9 deletions src/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait Behavior<Pane> {
/// The default implementation calls [`Self::tab_title_for_pane`] for panes and
/// uses the name of the [`crate::ContainerKind`] for [`crate::Container`]s.
fn tab_title_for_tile(&mut self, tiles: &Tiles<Pane>, tile_id: TileId) -> WidgetText {
if let Some(tile) = tiles.tiles.get(&tile_id) {
if let Some(tile) = tiles.get(tile_id) {
match tile {
Tile::Pane(pane) => self.tab_title_for_pane(pane),
Tile::Container(container) => format!("{:?}", container.kind()).into(),
Expand Down Expand Up @@ -238,14 +238,13 @@ pub trait Behavior<Pane> {
///
/// The `rect` is the available space for the grid,
/// and `gap` is the distance between each column and row.
fn grid_auto_column_count(
&self,
_tiles: &Tiles<Pane>,
children: &[TileId],
rect: Rect,
gap: f32,
) -> usize {
num_columns_heuristic(children.len(), rect, gap, self.ideal_tile_aspect_ratio())
fn grid_auto_column_count(&self, num_visible_children: usize, rect: Rect, gap: f32) -> usize {
num_columns_heuristic(
num_visible_children,
rect,
gap,
self.ideal_tile_aspect_ratio(),
)
}

/// When using [`crate::GridLayout::Auto`], what is the ideal aspect ratio of a tile?
Expand Down
Loading
Loading