trim board size to same margin as when expanding
This commit is contained in:
parent
dee52fa2fd
commit
51f14014c5
2 changed files with 6 additions and 6 deletions
|
@ -322,7 +322,7 @@ impl Editor {
|
|||
pos.y -= BOARD_MARGIN;
|
||||
self.source_board.set(pos, tile);
|
||||
if tile.is_blank() {
|
||||
let (x, y) = self.source_board.trim_size();
|
||||
let (x, y) = self.source_board.trim_size(BOARD_MARGIN as usize);
|
||||
self.view_offset.x += x as f32 * tile_size;
|
||||
self.view_offset.y += y as f32 * tile_size;
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ impl Board {
|
|||
(offset_x as isize, offset_y as isize)
|
||||
}
|
||||
|
||||
pub fn trim_size(&mut self) -> (usize, usize) {
|
||||
pub fn trim_size(&mut self, margin: usize) -> (usize, usize) {
|
||||
let (offset_x, offset_y);
|
||||
// top
|
||||
{
|
||||
|
@ -159,7 +159,7 @@ impl Board {
|
|||
while n < self.height && self.rows[n].iter().all(Tile::is_blank) {
|
||||
n += 1;
|
||||
}
|
||||
let trim_top = n.saturating_sub(2);
|
||||
let trim_top = n.saturating_sub(margin);
|
||||
for _ in 0..trim_top {
|
||||
self.rows.remove(0);
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ impl Board {
|
|||
while n < self.height && self.rows[self.height - n - 1].iter().all(Tile::is_blank) {
|
||||
n += 1;
|
||||
}
|
||||
let trim_bottom = n.saturating_sub(2);
|
||||
let trim_bottom = n.saturating_sub(margin);
|
||||
for _ in 0..trim_bottom {
|
||||
self.rows.pop();
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ impl Board {
|
|||
while n < self.width && self.rows.iter().all(|row| row[n].is_blank()) {
|
||||
n += 1;
|
||||
}
|
||||
let trim_left = n.saturating_sub(2);
|
||||
let trim_left = n.saturating_sub(margin);
|
||||
for row in &mut self.rows {
|
||||
for _ in 0..trim_left {
|
||||
row.remove(0);
|
||||
|
@ -199,7 +199,7 @@ impl Board {
|
|||
while n < self.width && self.rows.iter().all(|r| r[self.width - n - 1].is_blank()) {
|
||||
n += 1;
|
||||
}
|
||||
let trim_right = n.saturating_sub(2);
|
||||
let trim_right = n.saturating_sub(margin);
|
||||
for row in &mut self.rows {
|
||||
for _ in 0..trim_right {
|
||||
row.pop();
|
||||
|
|
Loading…
Reference in a new issue