From 96a4f007cc5d282a8bdedbe15e537954523eec5f Mon Sep 17 00:00:00 2001 From: cool-mist Date: Thu, 22 Jan 2026 19:10:21 +0530 Subject: [PATCH] Adjust everything relative to the board --- README.md | 15 ++++++++------- gui/src/game/constants.rs | 8 +++++++- gui/src/game/draw.rs | 29 +++++++++++++++++++---------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index cd6f28e..fd75d63 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,18 @@ Goal: Generate 'hard' puzzles. ## Install -- Install Rust from [here](https://www.rust-lang.org/tools/install). -- Run `cargo install --git https://github.com/cool-mist/sol_chess` to install the tool. -- This installs 2 binaries: `sol_chess` and `sol_cli`. - -## Usage - +- `cargo install --git https://github.com/cool-mist/sol_chess sol_chess` - Run `sol_chess` to start a windowed GUI game. -- Run `sol_cli` to start the CLI tool. + +## Update + +- `cargo install --git https://github.com/cool-mist/sol_chess sol_chess --force` ## CLI Usage +- `cargo install --git https://github.com/cool-mist/sol_chess sol_cli` +- Run `sol_cli` to start the CLI tool. + - Generate a puzzle ```bash diff --git a/gui/src/game/constants.rs b/gui/src/game/constants.rs index 83040c6..dec60f1 100644 --- a/gui/src/game/constants.rs +++ b/gui/src/game/constants.rs @@ -21,9 +21,15 @@ pub const BUTTON_HEIGHT_MULTIPLIER: f32 = 0.08; // Width of the button relative to the 'board size' pub const BUTTON_WIDTH_MULTIPLIER: f32 = 0.20; -// Gap between the bottom of the row and the first row of buttons +// Gap between the bottom of the board and the first row of buttons pub const BOTTOM_BUTTON_ROW_OFFSET_MULTIPLIER: f32 = 0.3; +// Gap between the right of the board and the first row of buttons +pub const BOTTOM_RIGHT_ROW_OFFSET_MULTIPLIER: f32 = 0.3; + +// Gap between the top of the board and the heading +pub const TOP_HEADING_OFFSET_MULTIPLIER: f32 = 0.5; + pub const HEADING_TEXT: &str = "Solitaire Chess"; pub const RESET_BUTTON_TEXT: &str = "RESET"; pub const NEXT_BUTTON_TEXT: &str = "NEXT"; diff --git a/gui/src/game/draw.rs b/gui/src/game/draw.rs index ada7951..24e6f3d 100644 --- a/gui/src/game/draw.rs +++ b/gui/src/game/draw.rs @@ -48,7 +48,7 @@ impl Game { let dims = measure_text(self.heading_text.as_str(), Some(&self.font), f, 1.0); self.heading_rect = Rect::new( board_x + (board_width - dims.width) / 2.0, - (board_y - dims.height) / 2.0, + board_y - dims.height - constants::TOP_HEADING_OFFSET_MULTIPLIER * self.square_width, dims.width, dims.height, ); @@ -80,26 +80,28 @@ impl Game { self.squares = rects; + // Buttons let btn_h = constants::BUTTON_HEIGHT_MULTIPLIER * min_dimension; let btn_w = board_width * constants::BUTTON_WIDTH_MULTIPLIER; - let btn_y = board_width + + // Bottom row + let bottom_row_y = board_width + board_y + constants::BOTTOM_BUTTON_ROW_OFFSET_MULTIPLIER * self.square_width; let btn_reset_x_offset = (self.board_rect.w - self.square_width) + (self.square_width - btn_w) / 2.; let reset_btn = Button::new( constants::RESET_BUTTON_TEXT, - Rect::new(board_x + btn_reset_x_offset, btn_y, btn_w, btn_h), + Rect::new(board_x + btn_reset_x_offset, bottom_row_y, btn_w, btn_h), UiColor::Yellow, self.sounds.button.clone(), self.font.clone(), ); - let btn_next_x_offset = (self.board_rect.w - 2. * self.square_width) + (self.square_width - btn_w) / 2.; let mut next_btn = Button::new( constants::NEXT_BUTTON_TEXT, - Rect::new(board_x + btn_next_x_offset, btn_y, btn_w, btn_h), + Rect::new(board_x + btn_next_x_offset, bottom_row_y, btn_w, btn_h), UiColor::Green, self.sounds.button.clone(), self.font.clone(), @@ -110,11 +112,14 @@ impl Game { self.gp_btns.insert(ButtonAction::Next, next_btn); self.gp_btns.insert(ButtonAction::Reset, reset_btn); + // Left column + let left_column_x = + board_x - constants::BOTTOM_RIGHT_ROW_OFFSET_MULTIPLIER * self.square_width - btn_w; let rules_button = Button::new( constants::RULES_BUTTON_TEXT, Rect::new( - (board_x - btn_w) / 2., - board_y + (self.square_width - btn_h) / 2., + left_column_x, + board_y + self.board_rect.h - self.square_width + (self.square_width - btn_h) / 2., btn_w, btn_h, ), @@ -124,10 +129,14 @@ impl Game { ); self.rules_btn = Some(rules_button); + // Right column + let right_column_x = board_x + + board_width + + constants::BOTTOM_RIGHT_ROW_OFFSET_MULTIPLIER * self.square_width; let easy_btn = Button::new( constants::EASY_BUTTON_TEXT, Rect::new( - (board_x - btn_w) / 2., + right_column_x, board_y + self.square_width + (self.square_width - btn_h) / 2., btn_w, btn_h, @@ -140,7 +149,7 @@ impl Game { let medium_btn = Button::new( constants::MEDIUM_BUTTON_TEXT, Rect::new( - (board_x - btn_w) / 2., + right_column_x, board_y + 2. * self.square_width + (self.square_width - btn_h) / 2., btn_w, btn_h, @@ -153,7 +162,7 @@ impl Game { let hard_button = Button::new( constants::HARD_BUTTON_TEXT, Rect::new( - (board_x - btn_w) / 2., + right_column_x, board_y + 3. * self.square_width + (self.square_width - btn_h) / 2., btn_w, btn_h,