fix
This commit is contained in:
22
src/main.rs
22
src/main.rs
@@ -1,4 +1,6 @@
|
|||||||
mod polygon_draw;
|
mod polygon_draw;
|
||||||
|
use iced::advanced::graphics::core::SmolStr;
|
||||||
|
use iced::keyboard::{Key, Modifiers};
|
||||||
use polygon_draw::Polygon;
|
use polygon_draw::Polygon;
|
||||||
|
|
||||||
mod music;
|
mod music;
|
||||||
@@ -14,7 +16,7 @@ use std::fs;
|
|||||||
|
|
||||||
use iced::widget::{TextInput, column, text};
|
use iced::widget::{TextInput, column, text};
|
||||||
use iced::{
|
use iced::{
|
||||||
Color, Length, Padding, Task, Theme, padding,
|
Color, Length, Padding, Task, Theme, keyboard,
|
||||||
widget::{Column, button, canvas, container, pick_list, row, scrollable, slider},
|
widget::{Column, button, canvas, container, pick_list, row, scrollable, slider},
|
||||||
};
|
};
|
||||||
use iced::{Element, Font, Subscription};
|
use iced::{Element, Font, Subscription};
|
||||||
@@ -129,6 +131,7 @@ impl MyApp {
|
|||||||
self.music.set_sound(self.current_delta, i, sound, s);
|
self.music.set_sound(self.current_delta, i, sound, s);
|
||||||
}
|
}
|
||||||
Message::Save => {
|
Message::Save => {
|
||||||
|
dbg!("Save file");
|
||||||
let json = serde_json::to_string_pretty(&self.music).unwrap();
|
let json = serde_json::to_string_pretty(&self.music).unwrap();
|
||||||
fs::write(format!("./saves/{0}.pmx", &self.music.file_name), json).unwrap();
|
fs::write(format!("./saves/{0}.pmx", &self.music.file_name), json).unwrap();
|
||||||
self.all_saves = load_path_saves();
|
self.all_saves = load_path_saves();
|
||||||
@@ -210,7 +213,7 @@ impl MyApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::ChangeNbPerSec(s) => {
|
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() {
|
if mut_s.len() != s.len() {
|
||||||
match mut_s.parse::<f32>() {
|
match mut_s.parse::<f32>() {
|
||||||
Ok(val) => {
|
Ok(val) => {
|
||||||
@@ -382,7 +385,7 @@ impl MyApp {
|
|||||||
.size(28),
|
.size(28),
|
||||||
]
|
]
|
||||||
.width(Length::FillPortion(10)),
|
.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))
|
.on_input(|new_value| Message::ChangeNbPerSec(new_value))
|
||||||
.size(28)
|
.size(28)
|
||||||
.width(Length::FillPortion(2)),
|
.width(Length::FillPortion(2)),
|
||||||
@@ -423,9 +426,18 @@ impl MyApp {
|
|||||||
|
|
||||||
fn subscription(&self) -> iced::Subscription<Message> {
|
fn subscription(&self) -> iced::Subscription<Message> {
|
||||||
if self.paused {
|
if self.paused {
|
||||||
Subscription::none() // ➝ désactive toutes les subscriptions
|
Subscription::none()
|
||||||
} else {
|
} 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,
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ pub struct Polygon {
|
|||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
pub color_name: String,
|
pub color_name: String,
|
||||||
|
#[serde(skip)]
|
||||||
pub show_color_picker: bool,
|
pub show_color_picker: bool,
|
||||||
}
|
}
|
||||||
#[warn(dead_code)]
|
#[warn(dead_code)]
|
||||||
|
|||||||
Reference in New Issue
Block a user