summaryrefslogtreecommitdiffstats
path: root/examples/game_of_life/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/game_of_life/src/main.rs')
-rw-r--r--examples/game_of_life/src/main.rs30
1 files changed, 13 insertions, 17 deletions
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index e951d734..96840143 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -18,7 +18,7 @@ use iced::{
use std::time::{Duration, Instant};
pub fn main() -> iced::Result {
- env_logger::builder().format_timestamp(None).init();
+ tracing_subscriber::fmt::init();
GameOfLife::run(Settings {
antialiasing: true,
@@ -406,12 +406,9 @@ mod grid {
*interaction = Interaction::None;
}
- let cursor_position =
- if let Some(position) = cursor.position_in(bounds) {
- position
- } else {
- return (event::Status::Ignored, None);
- };
+ let Some(cursor_position) = cursor.position_in(bounds) else {
+ return (event::Status::Ignored, None);
+ };
let cell = Cell::at(self.project(cursor_position, bounds.size()));
let is_populated = self.state.contains(&cell);
@@ -472,7 +469,7 @@ mod grid {
* (1.0 / self.scaling),
))
}
- _ => None,
+ Interaction::None => None,
};
let event_status = match interaction {
@@ -550,7 +547,7 @@ mod grid {
frame.translate(center);
frame.scale(self.scaling);
frame.translate(self.translation);
- frame.scale(Cell::SIZE as f32);
+ frame.scale(Cell::SIZE);
let region = self.visible_region(frame.size());
@@ -576,7 +573,7 @@ mod grid {
frame.translate(center);
frame.scale(self.scaling);
frame.translate(self.translation);
- frame.scale(Cell::SIZE as f32);
+ frame.scale(Cell::SIZE);
frame.fill_rectangle(
Point::new(cell.j as f32, cell.i as f32),
@@ -591,7 +588,7 @@ mod grid {
let text = Text {
color: Color::WHITE,
- size: 14.0,
+ size: 14.0.into(),
position: Point::new(frame.width(), frame.height()),
horizontal_alignment: alignment::Horizontal::Right,
vertical_alignment: alignment::Vertical::Bottom,
@@ -610,8 +607,7 @@ mod grid {
frame.fill_text(Text {
content: format!(
- "{} cell{} @ {:?} ({})",
- cell_count,
+ "{cell_count} cell{} @ {:?} ({})",
if cell_count == 1 { "" } else { "s" },
self.last_tick_duration,
self.last_queued_ticks
@@ -630,7 +626,7 @@ mod grid {
frame.translate(center);
frame.scale(self.scaling);
frame.translate(self.translation);
- frame.scale(Cell::SIZE as f32);
+ frame.scale(Cell::SIZE);
let region = self.visible_region(frame.size());
let rows = region.rows();
@@ -677,7 +673,7 @@ mod grid {
Interaction::None if cursor.is_over(bounds) => {
mouse::Interaction::Crosshair
}
- _ => mouse::Interaction::default(),
+ Interaction::None => mouse::Interaction::default(),
}
}
}
@@ -793,7 +789,7 @@ mod grid {
}
}
- for (cell, amount) in adjacent_life.iter() {
+ for (cell, amount) in &adjacent_life {
match amount {
2 => {}
3 => {
@@ -834,7 +830,7 @@ mod grid {
}
impl Cell {
- const SIZE: usize = 20;
+ const SIZE: u16 = 20;
fn at(position: Point) -> Cell {
let i = (position.y / Cell::SIZE as f32).ceil() as isize;