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

Fix crash when toggling visibility of grid cell #8

Merged
merged 2 commits into from
Jul 4, 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
2 changes: 2 additions & 0 deletions Cranky.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ warn = [
"clippy::iter_on_empty_collections",
"clippy::iter_on_single_items",
"clippy::large_digit_groups",
"clippy::large_include_file",
"clippy::large_stack_arrays",
"clippy::large_types_passed_by_value",
"clippy::let_unit_value",
Expand Down Expand Up @@ -96,6 +97,7 @@ warn = [
"clippy::string_to_string",
"clippy::suspicious_xor_used_as_pow",
"clippy::todo",
"clippy::too_many_lines",
"clippy::trailing_empty_array",
"clippy::trait_duplication_in_bounds",
"clippy::unchecked_duration_subtraction",
Expand Down
14 changes: 14 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
msrv = "1.69"

allow-unwrap-in-tests = true

# https://doc.rust-lang.org/nightly/clippy/lint_configuration.html#avoid-breaking-exported-api
# We want suggestions, even if it changes public API.
avoid-breaking-exported-api = false

max-fn-params-bools = 1

# https://rust-lang.github.io/rust-clippy/master/index.html#/large_include_file
max-include-file-size = 1000

too-many-lines-threshold = 100
1 change: 1 addition & 0 deletions src/behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub trait Behavior<Pane> {
///
/// You can override the default implementation to add e.g. a close button.
/// Make sure it is sensitive to clicks and drags (if you want to enable drag-and-drop of tabs).
#[allow(clippy::fn_params_excessive_bools)]
fn tab_ui(
&mut self,
tiles: &Tiles<Pane>,
Expand Down
18 changes: 11 additions & 7 deletions src/container/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ impl Grid {
self.children.retain(|child| child.is_some());
}

/// Keeps holes
pub fn visible_children<Pane>(&self, tiles: &Tiles<Pane>) -> Vec<Option<TileId>> {
self.children
.iter()
.filter(|id| id.map_or(true, |id| tiles.is_visible(id)))
.copied()
.collect()
}

pub(super) fn layout<Pane>(
&mut self,
tiles: &mut Tiles<Pane>,
Expand All @@ -142,12 +151,7 @@ impl Grid {
self.children.pop();
}

let num_visible_children = self
.children
.iter()
.filter_map(|&child| child)
.filter(|&child_id| tiles.is_visible(child_id))
.count();
let num_visible_children = self.visible_children(tiles).len();

let gap = behavior.gap_width(style);

Expand Down Expand Up @@ -187,7 +191,7 @@ impl Grid {
}

// Layout each child:
for (i, &child) in self.children.iter().enumerate() {
for (i, &child) in self.visible_children(tiles).iter().enumerate() {
if let Some(child) = child {
let col = i % num_cols;
let row = i / num_cols;
Expand Down