From 65156b19700061c33ee7ca54e65a384bf64a7fce Mon Sep 17 00:00:00 2001 From: Dukantic Date: Thu, 17 Jul 2025 22:18:44 +0200 Subject: [PATCH] fix --- src/main.rs | 22 +++++++++++++++++----- src/polygon_draw.rs | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 247f114..9ea75d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ mod polygon_draw; +use iced::advanced::graphics::core::SmolStr; +use iced::keyboard::{Key, Modifiers}; use polygon_draw::Polygon; mod music; @@ -14,7 +16,7 @@ use std::fs; use iced::widget::{TextInput, column, text}; use iced::{ - Color, Length, Padding, Task, Theme, padding, + Color, Length, Padding, Task, Theme, keyboard, widget::{Column, button, canvas, container, pick_list, row, scrollable, slider}, }; use iced::{Element, Font, Subscription}; @@ -129,6 +131,7 @@ impl MyApp { self.music.set_sound(self.current_delta, i, sound, s); } Message::Save => { + dbg!("Save file"); let json = serde_json::to_string_pretty(&self.music).unwrap(); fs::write(format!("./saves/{0}.pmx", &self.music.file_name), json).unwrap(); self.all_saves = load_path_saves(); @@ -210,7 +213,7 @@ impl MyApp { } } Message::ChangeNbPerSec(s) => { - let mut_s = s.trim_end_matches(" rev/sec"); + let mut_s = s.trim_end_matches(" sec/rev"); if mut_s.len() != s.len() { match mut_s.parse::() { Ok(val) => { @@ -382,7 +385,7 @@ impl MyApp { .size(28), ] .width(Length::FillPortion(10)), - TextInput::new("1.0", &format!("{:.1} rev/sec", &self.music.nb_sec_for_rev)) + TextInput::new("1.0", &format!("{:.1} sec/rev", &self.music.nb_sec_for_rev)) .on_input(|new_value| Message::ChangeNbPerSec(new_value)) .size(28) .width(Length::FillPortion(2)), @@ -423,9 +426,18 @@ impl MyApp { fn subscription(&self) -> iced::Subscription { if self.paused { - Subscription::none() // ➝ désactive toutes les subscriptions + Subscription::none() } else { - iced::time::every(std::time::Duration::from_millis(16)).map(|_| Message::Tick) + Subscription::batch(vec![ + iced::time::every(std::time::Duration::from_millis(16)).map(|_| Message::Tick), + iced::keyboard::on_key_press(|key: Key, modifiers: Modifiers| { + println!("Key pressed: {:?}, Modifiers: {:?}", key, modifiers); + match (key, modifiers) { + (Key::Character(c), m) if m.control() && c == "s" => Some(Message::Save), + _ => None, + } + }), + ]) } } diff --git a/src/polygon_draw.rs b/src/polygon_draw.rs index 036c023..064c214 100644 --- a/src/polygon_draw.rs +++ b/src/polygon_draw.rs @@ -194,6 +194,7 @@ pub struct Polygon { #[serde(skip)] pub color: Color, pub color_name: String, + #[serde(skip)] pub show_color_picker: bool, } #[warn(dead_code)]