-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: begin adding empty cli modules
- Loading branch information
Showing
15 changed files
with
54 additions
and
26 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,44 @@ | ||
use egui::{emath, Color32, Pos2, Rect, Rounding, Sense, Ui, Vec2}; | ||
|
||
use crate::util::gui::egui_display::EguiDisplay; | ||
|
||
use super::Nim; | ||
|
||
const CELL_HEIGHT: usize = 10; | ||
const CELL_WIDTH: usize = 5; | ||
const CELL_MARGIN_Y: usize = 5; | ||
const CELL_MARGIN_X: usize = 3; | ||
|
||
pub fn display(game: &Nim, ui: &mut Ui) { | ||
if let Some(max_cell_count) = game.heaps.iter().max() { | ||
let max_size = Vec2 { | ||
x: (CELL_WIDTH * max_cell_count + CELL_MARGIN_X * (max_cell_count - 1)) as f32, | ||
y: (CELL_HEIGHT * game.heaps.len() + CELL_MARGIN_Y * (game.heaps.len() - 1)) as f32 | ||
}; | ||
impl EguiDisplay for Nim { | ||
fn display(&self, ui: &mut Ui) { | ||
if let Some(max_cell_count) = self.heaps.iter().max() { | ||
let max_size = Vec2 { | ||
x: (CELL_WIDTH * max_cell_count + CELL_MARGIN_X * (max_cell_count - 1)) as f32, | ||
y: (CELL_HEIGHT * self.heaps.len() + CELL_MARGIN_Y * (self.heaps.len() - 1)) as f32 | ||
}; | ||
|
||
let (response, painter) = | ||
ui.allocate_painter(max_size, Sense::drag()); | ||
let (response, painter) = | ||
ui.allocate_painter(max_size, Sense::drag()); | ||
|
||
let to_screen = emath::RectTransform::from_to( | ||
Rect::from_min_size(Pos2::ZERO, max_size), | ||
response.rect, | ||
); | ||
let to_screen = emath::RectTransform::from_to( | ||
Rect::from_min_size(Pos2::ZERO, max_size), | ||
response.rect, | ||
); | ||
|
||
painter.extend(game.heaps.iter().enumerate().map(|(i, heap)| { | ||
(0..(*heap)).map(|j| { | ||
egui::Shape::rect_filled(Rect::from_two_pos( | ||
to_screen * Pos2 { | ||
x: (j * CELL_WIDTH + (j * CELL_MARGIN_X)) as f32, | ||
y: (i * CELL_HEIGHT + (i * CELL_MARGIN_Y)) as f32 | ||
}, | ||
to_screen * Pos2 { | ||
x: (j * CELL_WIDTH + (j * CELL_MARGIN_X) + CELL_WIDTH) as f32, | ||
y: (i * CELL_HEIGHT + (i * CELL_MARGIN_Y) + CELL_HEIGHT) as f32 | ||
} | ||
), Rounding::ZERO, Color32::LIGHT_GRAY) | ||
}).collect::<Vec<_>>() | ||
}).flatten().collect::<Vec<_>>()); | ||
painter.extend(self.heaps.iter().enumerate().map(|(i, heap)| { | ||
(0..(*heap)).map(|j| { | ||
egui::Shape::rect_filled(Rect::from_two_pos( | ||
to_screen * Pos2 { | ||
x: (j * CELL_WIDTH + (j * CELL_MARGIN_X)) as f32, | ||
y: (i * CELL_HEIGHT + (i * CELL_MARGIN_Y)) as f32 | ||
}, | ||
to_screen * Pos2 { | ||
x: (j * CELL_WIDTH + (j * CELL_MARGIN_X) + CELL_WIDTH) as f32, | ||
y: (i * CELL_HEIGHT + (i * CELL_MARGIN_Y) + CELL_HEIGHT) as f32 | ||
} | ||
), Rounding::ZERO, Color32::LIGHT_GRAY) | ||
}).collect::<Vec<_>>() | ||
}).flatten().collect::<Vec<_>>()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use egui::Ui; | ||
|
||
pub trait EguiDisplay { | ||
/// Renders | ||
fn display(&self, ui: &mut Ui); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod egui_display; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod cli; | ||
#[cfg(feature = "egui")] | ||
pub mod gui; | ||
pub mod move_natural; | ||
pub mod state; |