Skip to content

Commit

Permalink
Anchor camera on the centre instead of the top left corner during res…
Browse files Browse the repository at this point in the history
…izes
  • Loading branch information
LyricLy committed Jun 13, 2024
1 parent 1959625 commit bf1e465
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repository = "https://github.com/LyricLy/minefair"
license = "MIT"
description = "An infinite and fair Minesweeper"
readme = "README.md"
version = "1.1.0"
version = "1.1.1"
edition = "2021"

[dependencies]
Expand Down
8 changes: 4 additions & 4 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Camera {
impl Camera {
fn new(args: Args, save_file: File, (w, h): (u16, u16)) -> Self {
let mode = if args.cheat { DisplayMode::Risk } else { DisplayMode::Normal };
Self { field: Field::new(args), x: 0, y: 0, col: u16::MAX, row: u16::MAX, dead: false, save_file, mode, w, h }
Self { field: Field::new(args), x: -(w as isize) / 2, y: -(h as isize) / 2, col: u16::MAX, row: u16::MAX, dead: false, save_file, mode, w, h }
}

fn show(&mut self, col: isize, row: isize, c: impl Display) {
Expand Down Expand Up @@ -235,9 +235,9 @@ pub fn game_loop(args: Args, save_path: std::path::PathBuf) -> Result<()> {
_ => {},
},
Event::Resize(w, h) => {
cam.w = w;
cam.h = h;
cam.draw_entire_board();
let old_w = std::mem::replace(&mut cam.w, w);
let old_h = std::mem::replace(&mut cam.h, h);
cam.pan((old_w as isize - w as isize) / 2, (old_h as isize - h as isize) / 2);
},
Event::Mouse(event) => match event.kind {
MouseEventKind::Down(MouseButton::Left) => {
Expand Down

0 comments on commit bf1e465

Please sign in to comment.