From 73b7af9777a7d5e13a5b4921d531247b694e3359 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 3 Oct 2024 18:51:02 -0700 Subject: [PATCH] Continuing update --- iced-tetris/Cargo.lock | 61 +++++++++++++++++++++++++++++++++++++++++ iced-tetris/Cargo.toml | 2 +- iced-tetris/src/main.rs | 27 +++++++++++++----- 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/iced-tetris/Cargo.lock b/iced-tetris/Cargo.lock index 4ccbd9d..27cf8e4 100644 --- a/iced-tetris/Cargo.lock +++ b/iced-tetris/Cargo.lock @@ -1028,6 +1028,12 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "float_next_after" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8" + [[package]] name = "font-types" version = "0.6.0" @@ -1509,6 +1515,7 @@ dependencies = [ "iced_core", "iced_futures", "log", + "lyon_path", "once_cell", "raw-window-handle", "rustc-hash 2.0.0", @@ -1572,6 +1579,7 @@ dependencies = [ "iced_glyphon", "iced_graphics", "log", + "lyon", "once_cell", "rustc-hash 2.0.0", "thiserror", @@ -1786,6 +1794,58 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" +[[package]] +name = "lyon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e7f9cda98b5430809e63ca5197b06c7d191bf7e26dfc467d5a3f0290e2a74f" +dependencies = [ + "lyon_algorithms", + "lyon_tessellation", +] + +[[package]] +name = "lyon_algorithms" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3bca95f9a4955b3e4a821fbbcd5edfbd9be2a9a50bb5758173e5358bfb4c623" +dependencies = [ + "lyon_path", + "num-traits", +] + +[[package]] +name = "lyon_geom" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edecfb8d234a2b0be031ab02ebcdd9f3b9ee418fb35e265f7a540a48d197bff9" +dependencies = [ + "arrayvec", + "euclid", + "num-traits", +] + +[[package]] +name = "lyon_path" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c08a606c7a59638d6c6aa18ac91a06aa9fb5f765a7efb27e6a4da58700740d7" +dependencies = [ + "lyon_geom", + "num-traits", +] + +[[package]] +name = "lyon_tessellation" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579d42360a4b09846eff2feef28f538696c7d6c7439bfa65874ff3cbe0951b2c" +dependencies = [ + "float_next_after", + "lyon_path", + "num-traits", +] + [[package]] name = "malloc_buf" version = "0.0.6" @@ -1923,6 +1983,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] diff --git a/iced-tetris/Cargo.toml b/iced-tetris/Cargo.toml index 46b2aa8..290747e 100644 --- a/iced-tetris/Cargo.toml +++ b/iced-tetris/Cargo.toml @@ -7,7 +7,7 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -iced = { version = "0.13.1", features = ["tokio"] } +iced = { version = "0.13.1", features = ["tokio", "canvas"] } chrono = "0.4.19" rand = "0.8.4" tetris-logic = { path = "../tetris-logic" } diff --git a/iced-tetris/src/main.rs b/iced-tetris/src/main.rs index efeb2da..703135f 100644 --- a/iced-tetris/src/main.rs +++ b/iced-tetris/src/main.rs @@ -8,8 +8,8 @@ use tetris_logic::{BlockGrid, MoveDirection, Tetromino}; */ use iced::{ - widget::{button, text}, - Element, Subscription, Task, + widget::{button, canvas, text}, + Element, Renderer, Subscription, Task, Theme, }; use tetris_logic::{BlockGrid, MoveDirection, Tetromino}; @@ -96,8 +96,8 @@ fn subscription(_state: &Tetris) -> Subscription { Subscription::batch([time_subscription, keyboard_subscription]) } -fn view(_state: &Tetris) -> Element { - button(text("FOO")).on_press(Message::Up).into() +fn view(state: &Tetris) -> Element { + canvas(state).into() } struct Tetris { @@ -202,8 +202,21 @@ impl Application for Tetris { } */ -/* -impl<'a> canvas::Program for Tetris { +impl canvas::Program for Tetris { + type State = (); + + fn draw( + &self, + state: &Self::State, + renderer: &Renderer, + theme: &Theme, + bounds: iced::Rectangle, + _cursor: iced::mouse::Cursor, + ) -> Vec> { + todo!() + } + + /* fn draw(&self, bounds: Rectangle, _cursor: canvas::Cursor) -> Vec { let game_width = bounds.width / 3.0; let block_length = game_width / 10.0; @@ -267,8 +280,8 @@ impl<'a> canvas::Program for Tetris { vec![background, frame.into_geometry()] } + */ } -*/ /* fn handle_keypress(key_code: keyboard::KeyCode) -> Option {