From 51f14014c580042a977f54e221a2550d960df027 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Thu, 10 Oct 2024 17:20:07 +0200 Subject: [PATCH] trim board size to same margin as when expanding --- src/editor.rs | 2 +- src/marble_engine/board.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index c27324a..68bc1db 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -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; } diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index 04bf0df..ae2b8f9 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -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();