make erasing continuous

This commit is contained in:
Crispy 2024-10-07 16:51:56 +02:00
parent 49917d18a9
commit e661483cd5
3 changed files with 35 additions and 36 deletions

View file

@ -219,41 +219,38 @@ impl Board {
}
pub fn trim_size(&mut self) {
// top
{
let mut top_blanks = 0;
while top_blanks < self.height && self.rows[top_blanks].iter().all(Tile::is_blank) {
top_blanks += 1;
let mut n = 0;
while n < self.height && self.rows[n].iter().all(Tile::is_blank) {
n += 1;
}
let trim_top = top_blanks.saturating_sub(2);
let trim_top = n.saturating_sub(2);
for _ in 0..trim_top {
self.rows.remove(0);
}
self.offset_y -= trim_top as isize;
self.height -= trim_top;
}
// bottom
{
let mut bottom_blanks = 0;
while bottom_blanks < self.height
&& self.rows[self.height - bottom_blanks - 1]
.iter()
.all(Tile::is_blank)
{
bottom_blanks += 1;
let mut n = 0;
while n < self.height && self.rows[self.height - n - 1].iter().all(Tile::is_blank) {
n += 1;
}
let trim_bottom = bottom_blanks.saturating_sub(2);
let trim_bottom = n.saturating_sub(2);
for _ in 0..trim_bottom {
self.rows.pop();
}
self.height -= trim_bottom;
}
// left
{
let mut left_blanks = 0;
while left_blanks < self.width
&& self.rows.iter().all(|row| row[left_blanks].is_blank())
{
left_blanks += 1;
let mut n = 0;
while n < self.width && self.rows.iter().all(|row| row[n].is_blank()) {
n += 1;
}
let trim_left = left_blanks.saturating_sub(2);
let trim_left = n.saturating_sub(2);
for row in &mut self.rows {
for _ in 0..trim_left {
row.remove(0);
@ -262,17 +259,13 @@ impl Board {
self.offset_x -= trim_left as isize;
self.width -= trim_left;
}
// right
{
let mut right_blanks = 0;
while right_blanks < self.height
&& self
.rows
.iter()
.all(|row| row[self.width - right_blanks - 1].is_blank())
{
right_blanks += 1;
let mut n = 0;
while n < self.width && self.rows.iter().all(|r| r[self.width - n - 1].is_blank()) {
n += 1;
}
let trim_right = right_blanks.saturating_sub(2);
let trim_right = n.saturating_sub(2);
for row in &mut self.rows {
for _ in 0..trim_right {
row.pop();