From 9c2a3d5d726c8ca8c601c888d579e2516ed2131d Mon Sep 17 00:00:00 2001 From: Dukantic Date: Sat, 5 Jul 2025 20:28:00 +0200 Subject: [PATCH] better view --- saves/polymusic.json | 39 ++++++++++++++++----------- src/main.rs | 64 +++++++++++++++++++++++++------------------- src/polygon_draw.rs | 13 +++------ src/utils.rs | 12 +++++++++ 4 files changed, 76 insertions(+), 52 deletions(-) create mode 100644 src/utils.rs diff --git a/saves/polymusic.json b/saves/polymusic.json index afcdc79..e9a9b96 100644 --- a/saves/polymusic.json +++ b/saves/polymusic.json @@ -1,19 +1,9 @@ { "poly_frame": { - "teta": 1.3752483, + "teta": 4.3590484, "polygons": [ { - "global_teta": 0.0, - "points_teta": [ - 0.0, - 3.1415927 - ], - "sound_name": "A_LA.ogg", - "name": "Segment", - "color_name": "Pink" - }, - { - "global_teta": 0.0, + "global_teta": 0.48619887, "points_teta": [ 1.0471976, 1.2566371, @@ -22,12 +12,29 @@ 5.0265484, 5.2359877 ], - "sound_name": "D_RE.ogg", + "sound_name": "B_SI.ogg", "name": "Nr6In30", - "color_name": "Black" + "color_name": "Blue" + }, + { + "global_teta": 0.0, + "points_teta": [ + 0.44879895, + 1.3463968, + 2.0943952, + 2.2439947, + 4.039191, + 4.1887903, + 4.9367886, + 5.8343863 + ], + "sound_name": "D_RE.ogg", + "name": "Nr8In42", + "color_name": "Cyan" } ] }, - "nb_sec_for_rev": 8.0, - "file_name": "polymusic.json" + "nb_sec_for_rev": 3.5, + "file_name": "polymusic.json", + "show_save_panel": true } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6092359..d3c1a04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,17 @@ mod polygon_draw; +use polygon_draw::{Polygon, PolygonFrame}; + +mod utils; +use utils::string_to_color; use std::fs; use iced::{ - Color, Element, Task, Theme, + Color, Element, Length, Task, Theme, time::{self, Duration}, widget::{Column, button, canvas, column, container, pick_list, row, slider, text}, }; -use polygon_draw::{Polygon, PolygonFrame}; + use serde::{Deserialize, Serialize}; use std::f32::consts::PI; @@ -170,14 +174,7 @@ impl MyApp { self.poly_frame.polygons[i].global_teta = teta; } Message::ChangeColor(i, s) => { - let c = match s.as_str() { - "Green" => Color::from_rgb(0.0, 1.0, 0.0), - "Blue" => Color::from_rgb(0.0, 0.0, 1.0), - "Cyan" => Color::from_rgb(0.0, 1.0, 1.0), - "Yellow" => Color::from_rgb(1.0, 1.0, 0.0), - "Pink" => Color::from_rgb(1.0, 0.0, 1.0), - _ => Color::BLACK, - }; + let c = string_to_color(&s); self.poly_frame.polygons[i].color = c; self.poly_frame.polygons[i].color_name = s; } @@ -219,25 +216,28 @@ impl MyApp { .map(|e| e.path().file_name().unwrap().to_str().unwrap().to_string()) .collect(); entries.sort(); - - row![ - text(&polygon.name), + column![ + row![ + text(&polygon.name), + button("Remove").on_press(Message::Remove(i)), + pick_list( + ["Black", "Blue", "Green", "Pink", "Yellow", "Cyan"] + .map(|s| s.to_string()) + .to_vec(), + Some(&polygon.color_name), + move |s| { Message::ChangeColor(current_index, s) } + ), + pick_list(entries, Some(&polygon.sound_name), move |s| { + Message::ChangeSound(current_index, s) + }), + ] + .spacing(20), slider(0.0..=2.0 * PI, polygon.global_teta, move |f| { Message::ChangeTeta(current_index, f) }) .step(PI / 84f32), // 84 | 4 for do PI / 4 - button("Remove").on_press(Message::Remove(i)), - pick_list( - ["Black", "Blue", "Green", "Pink", "Yellow", "Cyan"] - .map(|s| s.to_string()) - .to_vec(), - Some(&polygon.color_name), - move |s| { Message::ChangeColor(current_index, s) } - ), - pick_list(entries, Some(&polygon.sound_name), move |s| { - Message::ChangeSound(current_index, s) - }), ] + .spacing(20) .into() }) .collect(); @@ -275,7 +275,11 @@ impl MyApp { text("Polymusic").size(32.0), row(save_panel).spacing(20), row![ - container(canvas(&self.poly_frame).height(500).width(500)), + container( + canvas(&self.poly_frame) + .height(Length::FillPortion(2)) + .width(Length::FillPortion(1)) + ), column![ text(txt_nb_rev), row![ @@ -286,10 +290,16 @@ impl MyApp { pick_list(all_options, Some("Choose polygon".to_string()), |s| { Message::AddPolygon(s) }), - polygon_column, - ], + polygon_column.spacing(10), + ] + .spacing(10) + .height(Length::FillPortion(2)) + .width(Length::FillPortion(2)), ] .spacing(20), + row![text("futur time line")] + .height(Length::FillPortion(1)) + .width(Length::FillPortion(1)), ] .spacing(25) .padding(25) diff --git a/src/polygon_draw.rs b/src/polygon_draw.rs index 5b74ed5..c9b0326 100644 --- a/src/polygon_draw.rs +++ b/src/polygon_draw.rs @@ -1,3 +1,5 @@ +use crate::utils::string_to_color; + use std::f32::consts::PI; use iced::Vector; @@ -55,7 +57,7 @@ impl canvas::Program for PolygonFrame { _cursor: mouse::Cursor, ) -> Vec { let mut frame = canvas::Frame::new(renderer, bounds.size()); - let radius = frame.size().width / 2.0 - 32.0; + let radius = frame.size().width.min(frame.size().height) / 2.0 - 32.0; let mut vec = Vector::new(0.0, -radius); let c = frame.center(); // Draw Circle @@ -127,14 +129,7 @@ impl Polygon { let path = format!("./assets/{0}", &self.sound_name); eprintln!("path:{path}"); self.sound = StaticSoundData::from_file(&path).expect("fail to load the sound"); - self.color = match self.color_name.as_str() { - "Green" => Color::from_rgb(0.0, 1.0, 0.0), - "Blue" => Color::from_rgb(0.0, 0.0, 1.0), - "Cyan" => Color::from_rgb(0.0, 1.0, 1.0), - "Yellow" => Color::from_rgb(1.0, 1.0, 0.0), - "Pink" => Color::from_rgb(1.0, 0.0, 1.0), - _ => Color::BLACK, - }; + self.color = string_to_color(&self.color_name); } pub fn sound_to_play_btw(&self, before: f32, after: f32) -> Vec<&StaticSoundData> { let mut sound_to_play: Vec<&StaticSoundData> = vec![]; diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..3d2ffa9 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,12 @@ +use iced::Color; + +pub fn string_to_color>(s: S) -> Color { + match s.as_ref() { + "Green" => Color::from_rgb(0.0, 1.0, 0.0), + "Blue" => Color::from_rgb(0.0, 0.0, 1.0), + "Cyan" => Color::from_rgb(0.0, 1.0, 1.0), + "Yellow" => Color::from_rgb(1.0, 1.0, 0.0), + "Pink" => Color::from_rgb(1.0, 0.0, 1.0), + _ => Color::BLACK, + } +}