pause and play, first step for the time line
This commit is contained in:
47
src/utils.rs
47
src/utils.rs
@@ -1,5 +1,5 @@
|
||||
use crate::Polygon;
|
||||
use iced::Color;
|
||||
use iced::{Color, widget::canvas::path::lyon_path::geom::euclid::num::Floor};
|
||||
use kira::sound::static_sound::StaticSoundData;
|
||||
pub fn string_to_color<S: AsRef<str>>(s: S) -> Color {
|
||||
match s.as_ref() {
|
||||
@@ -11,65 +11,82 @@ pub fn string_to_color<S: AsRef<str>>(s: S) -> Color {
|
||||
_ => Color::BLACK,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn delta_to_string(delta: f32) -> String {
|
||||
let time = [
|
||||
((delta / 60.0) as u32),
|
||||
((delta % 60.0) as u32),
|
||||
((delta * 100.0) % 100.0) as u32,
|
||||
];
|
||||
let mut time_str = [String::new(), String::new(), String::new()];
|
||||
for i in 0..3 {
|
||||
if time[i] < 10 {
|
||||
time_str[i] = format!("0{}", time[i]);
|
||||
} else {
|
||||
time_str[i] = time[i].to_string();
|
||||
}
|
||||
}
|
||||
|
||||
format!("{}:{}:{}", time_str[0], time_str[1], time_str[2])
|
||||
}
|
||||
pub fn str_to_sec(str: &str) -> f32 {
|
||||
let parts: Vec<&str> = str.split(':').collect();
|
||||
|
||||
let min: f32 = parts[0].parse().expect("str of music length not valid");
|
||||
let sec: f32 = parts[1].parse().expect("str of music length not valid");
|
||||
let cs: f32 = parts[2].parse().expect("str of music length not valid");
|
||||
min * 60.0 + sec + (cs / 100.0)
|
||||
}
|
||||
|
||||
pub fn string_to_polygon<S: AsRef<str>>(str: S) -> Polygon {
|
||||
let s = str.as_ref();
|
||||
let mut poly: Polygon;
|
||||
if s.starts_with("Ngon") {
|
||||
if let Ok(sides) = s.trim_start_matches("Ngon").parse::<u8>() {
|
||||
return Polygon::n_gon(0.0, sides, dummy_sound());
|
||||
poly = Polygon::n_gon(0.0, sides, dummy_sound());
|
||||
} else {
|
||||
return Polygon::n_gon(0.0, 0, dummy_sound());
|
||||
poly = Polygon::n_gon(0.0, 0, dummy_sound());
|
||||
}
|
||||
} else {
|
||||
match s {
|
||||
"Segment" => {
|
||||
poly = Polygon::segment(0.0, dummy_sound());
|
||||
poly.name = "Segment".to_string();
|
||||
}
|
||||
"Triangle" => {
|
||||
poly = Polygon::triangle(0.0, dummy_sound());
|
||||
poly.name = "Triangle".to_string();
|
||||
}
|
||||
"Square" => {
|
||||
poly = Polygon::square(0.0, dummy_sound());
|
||||
poly.name = "Square".to_string();
|
||||
}
|
||||
"Nr6In30" => {
|
||||
poly = Polygon::nr_6_in_30(0.0, dummy_sound());
|
||||
poly.name = "Nr6In30".to_string();
|
||||
}
|
||||
"Nr7In30" => {
|
||||
poly = Polygon::nr_7_in_30(0.0, dummy_sound());
|
||||
poly.name = "Nr7In30".to_string();
|
||||
}
|
||||
"Nr8In30" => {
|
||||
poly = Polygon::nr_8_in_30(0.0, dummy_sound());
|
||||
poly.name = "Nr8In30".to_string();
|
||||
}
|
||||
"Nr9In30" => {
|
||||
poly = Polygon::nr_9_in_30(0.0, dummy_sound());
|
||||
poly.name = "Nr9In30".to_string();
|
||||
}
|
||||
"Nr8In42" => {
|
||||
poly = Polygon::nr_8_in_42(0.0, dummy_sound());
|
||||
poly.name = "Nr8In42".to_string();
|
||||
}
|
||||
"Nr9In42" => {
|
||||
poly = Polygon::nr_9_in_42(0.0, dummy_sound());
|
||||
poly.name = "Nr9In42".to_string();
|
||||
}
|
||||
"Nr10aIn42" => {
|
||||
poly = Polygon::nr_10a_in_42(0.0, dummy_sound());
|
||||
poly.name = "Nr10aIn42".to_string();
|
||||
}
|
||||
"Nr10bIn42" => {
|
||||
poly = Polygon::nr_10b_in_42(0.0, dummy_sound());
|
||||
poly.name = "Nr10bIn42".to_string();
|
||||
}
|
||||
_ => poly = Polygon::n_gon(0.0, 0, dummy_sound()),
|
||||
}
|
||||
poly
|
||||
}
|
||||
poly.name = s.to_string();
|
||||
poly
|
||||
}
|
||||
fn dummy_sound() -> StaticSoundData {
|
||||
StaticSoundData::from_file("assets/tick.ogg").expect("Fail to load audio")
|
||||
|
||||
Reference in New Issue
Block a user