add remove point
This commit is contained in:
@@ -57,6 +57,7 @@ enum Message {
|
||||
LengthChange(String),
|
||||
ChangeDelta(f32),
|
||||
AddPoint,
|
||||
RemovePoint,
|
||||
}
|
||||
|
||||
struct MyApp {
|
||||
@@ -173,6 +174,9 @@ impl MyApp {
|
||||
Message::AddPoint => {
|
||||
self.music.add_point(self.current_delta);
|
||||
}
|
||||
Message::RemovePoint => {
|
||||
self.music.remove_point(self.current_delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +319,8 @@ impl MyApp {
|
||||
delta_to_string(self.music.length)
|
||||
))
|
||||
.size(20.0),
|
||||
button("Add Point").on_press(Message::AddPoint)
|
||||
button("Add Point").on_press(Message::AddPoint),
|
||||
button("Remove Point").on_press(Message::RemovePoint),
|
||||
]
|
||||
.spacing(20),
|
||||
column![
|
||||
|
||||
17
src/music.rs
17
src/music.rs
@@ -35,6 +35,17 @@ impl Music {
|
||||
&mut self.poly_frame.last_mut().unwrap().1
|
||||
}
|
||||
}
|
||||
fn find_index_frame(&mut self, delta: f32) -> usize {
|
||||
if let Some(i) = self
|
||||
.poly_frame
|
||||
.windows(2)
|
||||
.position(|w| w[0].0 <= delta && delta < w[1].0)
|
||||
{
|
||||
i
|
||||
} else {
|
||||
self.poly_frame.len() - 1
|
||||
}
|
||||
}
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~PUBLIC~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
pub fn current_frame(&self, delta: f32) -> &PolygonFrame {
|
||||
if let Some(i) = self
|
||||
@@ -121,6 +132,12 @@ impl Music {
|
||||
self.poly_frame
|
||||
.insert(pos, (delta, self.current_frame(delta).clone()));
|
||||
}
|
||||
pub fn remove_point(&mut self, delta: f32) {
|
||||
let i = self.find_index_frame(delta);
|
||||
if i != 0 {
|
||||
self.poly_frame.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_polygon(&mut self, delta: f32, polygon_name: String) {
|
||||
let current_frame = self.find_poly_frame(delta);
|
||||
|
||||
Reference in New Issue
Block a user