fix ctrl z for remove polygon, now polygon return with there color, sound and teta

This commit is contained in:
2025-07-25 18:35:02 +02:00
parent 29d257eef0
commit 6c360c4222
3 changed files with 24 additions and 12 deletions

View File

@@ -22,15 +22,15 @@ use gui::{load_file_view, music_view};
use iced::Font;
use iced::Theme;
use iced::{
Color, Event, Task,
event::{self, Status},
keyboard::{Key, key::Named},
keyboard::{key::Named, Key},
Color, Event, Task,
};
use std::time::Instant;
use kira::{
AudioManager, AudioManagerSettings, DefaultBackend, sound::static_sound::StaticSoundData,
sound::static_sound::StaticSoundData, AudioManager, AudioManagerSettings, DefaultBackend,
};
const FONT_BYTES: &[u8] = include_bytes!("../fonts/EnvyCodeRNerdFontMono-Regular.ttf");
const FONT: Font = Font::with_name("EnvyCodeR Nerd Font Mono");
@@ -87,7 +87,6 @@ impl Polymusic {
fn new() -> (Self, Task<Message>) {
let manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default())
.expect("Error to load AudioManager");
(
Self {
time_last_frame: Instant::now(),
@@ -120,6 +119,9 @@ impl Polymusic {
self.current_delta,
);
}
Message::ReAddPolygon(poly) => {
self.music.add_polygon_from(self.current_delta, poly);
}
Message::Tick => {
if self.current_delta >= self.music.length {
self.paused = true
@@ -135,10 +137,10 @@ impl Polymusic {
}
}
Message::Remove(i) => {
let name = self.music.remove_polygon(self.current_delta, i);
let poly = self.music.remove_polygon(self.current_delta, i);
self.already_save = false;
self.historic.add(
Message::AddPolygon(name),
Message::ReAddPolygon(poly),
Message::Remove(i),
self.current_delta,
);
@@ -443,6 +445,7 @@ impl Polymusic {
self.update(Message::TogglePaused);
self.update(Message::Tick);
self.update(Message::TogglePaused);
self.update(Message::None);
}
}
}

View File

@@ -1,5 +1,7 @@
use iced::Color;
use crate::polygon_draw::Polygon;
#[derive(Debug, Clone)]
pub enum Message {
None,
@@ -18,6 +20,7 @@ pub enum Message {
ChangeNbPerSec(String),
AddPolygon(String),
ReAddPolygon(Polygon),
ChangeTeta(usize, f32),
Remove(usize),
ChangeSound(usize, String),

View File

@@ -3,16 +3,16 @@ use crate::polygon_draw::*;
use crate::utils::string_to_polygon;
use serde::{Deserialize, Serialize};
use kira::{AudioManager, sound::static_sound::StaticSoundData};
use kira::{sound::static_sound::StaticSoundData, AudioManager};
use iced::event::Status;
use iced::mouse::Cursor;
use iced::widget::canvas::{Event, Geometry};
use iced::{keyboard, Vector};
use iced::{
Size,
mouse::{self, ScrollDelta},
Size,
};
use iced::{Vector, keyboard};
use iced::widget::canvas;
use iced::widget::canvas::Stroke;
@@ -174,17 +174,23 @@ impl Music {
pub fn add_polygon(&mut self, delta: f32, polygon_name: String) {
let current_frame = self.find_poly_frame(delta);
let poly = string_to_polygon(polygon_name);
let mut poly = string_to_polygon(polygon_name);
poly.update();
current_frame.polygons.push(poly);
}
pub fn remove_polygon(&mut self, delta: f32, i: usize) -> String {
pub fn add_polygon_from(&mut self, delta: f32, polygon: Polygon) {
let current_frame = self.find_poly_frame(delta);
current_frame.polygons.push(polygon);
}
pub fn remove_polygon(&mut self, delta: f32, i: usize) -> Polygon {
let pf = self.find_poly_frame(delta);
let mut i = i;
if i == usize::MAX {
i = pf.polygons.len() - 1
}
let out = pf.polygons[i].name.clone();
let out = pf.polygons[i].clone();
pf.polygons.remove(i);
out
}