diff options
Diffstat (limited to 'examples/game_of_life')
-rw-r--r-- | examples/game_of_life/Cargo.toml | 12 | ||||
-rw-r--r-- | examples/game_of_life/README.md | 4 | ||||
-rw-r--r-- | examples/game_of_life/src/main.rs | 30 |
3 files changed, 21 insertions, 25 deletions
diff --git a/examples/game_of_life/Cargo.toml b/examples/game_of_life/Cargo.toml index f0a794fb..7596844c 100644 --- a/examples/game_of_life/Cargo.toml +++ b/examples/game_of_life/Cargo.toml @@ -6,8 +6,10 @@ edition = "2021" publish = false [dependencies] -iced = { path = "../..", features = ["canvas", "tokio", "debug"] } -tokio = { version = "1.0", features = ["sync"] } -itertools = "0.9" -rustc-hash = "1.1" -env_logger = "0.9" +iced.workspace = true +iced.features = ["debug", "canvas", "tokio"] + +itertools = "0.12" +rustc-hash.workspace = true +tokio = { workspace = true, features = ["sync"] } +tracing-subscriber = "0.3" diff --git a/examples/game_of_life/README.md b/examples/game_of_life/README.md index aa39201c..60033c1a 100644 --- a/examples/game_of_life/README.md +++ b/examples/game_of_life/README.md @@ -7,9 +7,7 @@ It runs a simulation in a background thread while allowing interaction with a `C The __[`main`]__ file contains the relevant code of the example. <div align="center"> - <a href="https://gfycat.com/WhichPaltryChick"> - <img src="https://thumbs.gfycat.com/WhichPaltryChick-size_restricted.gif"> - </a> + <img src="https://iced.rs/examples/game_of_life.gif"> </div> You can run it with `cargo run`: 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; |