Added margin around chessboard
This commit is contained in:
@@ -803,7 +803,6 @@ impl eframe::App for ChessApp {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Main content area with chess board and move history
|
||||
egui::CentralPanel::default()
|
||||
.frame(egui::Frame::default().fill(background_color))
|
||||
@@ -817,16 +816,24 @@ impl eframe::App for ChessApp {
|
||||
let board_size = board_max_width.min(board_max_height);
|
||||
let history_width = total_width * 0.20;
|
||||
|
||||
// Total width of both elements plus spacing
|
||||
let total_content_width = board_size + 5.0 + history_width;
|
||||
// Add margin around the board (20 pixels on each side)
|
||||
let board_margin = 20.0;
|
||||
let effective_board_size = board_size - 2.0 * board_margin;
|
||||
|
||||
// Center the entire content horizontally and vertically
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
// Chess board (left side)
|
||||
// Chess board with margin (left side)
|
||||
ui.vertical(|ui| {
|
||||
// Add vertical spacing above the board
|
||||
ui.add_space(board_margin);
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
// Add horizontal spacing to the left of the board
|
||||
ui.add_space(board_margin);
|
||||
|
||||
let (board_response, board_painter) = ui.allocate_painter(
|
||||
egui::Vec2::new(board_size, board_size),
|
||||
egui::Vec2::new(effective_board_size, effective_board_size),
|
||||
egui::Sense::click(),
|
||||
);
|
||||
|
||||
@@ -835,7 +842,7 @@ impl eframe::App for ChessApp {
|
||||
.player_color
|
||||
.as_ref()
|
||||
.map_or(true, |c| c == "white");
|
||||
let tile_size = board_size / 8.0;
|
||||
let tile_size = effective_board_size / 8.0;
|
||||
let board_top_left = board_response.rect.left_top();
|
||||
|
||||
// Draw board and pieces
|
||||
@@ -905,12 +912,19 @@ impl eframe::App for ChessApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add horizontal spacing to the right of the board
|
||||
ui.add_space(board_margin);
|
||||
});
|
||||
|
||||
// Add vertical spacing below the board
|
||||
ui.add_space(board_margin);
|
||||
});
|
||||
|
||||
// Add spacing between board and move history
|
||||
ui.add_space(15.0);
|
||||
|
||||
// Move History (right side) - match the board height
|
||||
// Move History (right side) - match the board height including margins
|
||||
ui.vertical(|ui| {
|
||||
egui::Frame::default()
|
||||
.fill(if self.dark_mode {
|
||||
@@ -922,20 +936,21 @@ impl eframe::App for ChessApp {
|
||||
.inner_margin(egui::Margin::same(8))
|
||||
.show(ui, |ui| {
|
||||
ui.set_width(history_width);
|
||||
ui.set_height(board_size); // Match board height
|
||||
ui.set_height(board_size); // Match total board height including margins
|
||||
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.heading("Move History");
|
||||
ui.heading(egui::RichText::new("Move History").color(text_color));
|
||||
ui.separator();
|
||||
|
||||
// Scroll area for move history
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(board_size - 50.0)
|
||||
.max_height(board_size - 50.0) // Based on board height
|
||||
.show(ui, |ui| {
|
||||
// Use actual move history from game_state
|
||||
if let Ok(game_state) = self.game_state.lock() {
|
||||
for (i, move_text) in game_state.move_history.iter().enumerate() {
|
||||
ui.horizontal(|ui| {
|
||||
// Alternate background based on dark mode
|
||||
// Alternate background
|
||||
if i % 2 == 0 {
|
||||
ui.visuals_mut().widgets.noninteractive.bg_fill =
|
||||
if self.dark_mode {
|
||||
@@ -952,10 +967,7 @@ impl eframe::App for ChessApp {
|
||||
};
|
||||
}
|
||||
|
||||
// Move text color
|
||||
ui.label(egui::RichText::new(move_text.to_string())
|
||||
.size(16.0)
|
||||
.color(text_color));
|
||||
ui.label(egui::RichText::new(move_text.to_string()).size(16.0).color(text_color));
|
||||
|
||||
if ui.small_button("📋").clicked() {
|
||||
info!("Copy move: {}", move_text);
|
||||
@@ -970,12 +982,8 @@ impl eframe::App for ChessApp {
|
||||
if game_state.move_history.is_empty() {
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add_space(20.0);
|
||||
ui.label(egui::RichText::new("No moves yet")
|
||||
.size(16.0)
|
||||
.color(text_color));
|
||||
ui.label(egui::RichText::new("Game will start soon...")
|
||||
.size(14.0)
|
||||
.color(text_color));
|
||||
ui.label(egui::RichText::new("No moves yet").size(16.0).color(text_color));
|
||||
ui.label(egui::RichText::new("Game will start soon...").size(14.0).color(text_color));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user