Add ability to advance lines
This commit is contained in:
parent
f8cd155293
commit
66daa5bd0e
|
@ -22,6 +22,21 @@ impl Lyrics {
|
||||||
self.lines[line_no].set_content(new_content);
|
self.lines[line_no].set_content(new_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn advance_line(&mut self, current_line: usize) {
|
||||||
|
let new_line = current_line + 1;
|
||||||
|
|
||||||
|
if new_line == self.lines.len() {
|
||||||
|
self.lines.push(Lyric::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
self.lines.get_mut(new_line)
|
||||||
|
.expect("Unexpected .advance_line with index beyond # of lines")
|
||||||
|
.select();
|
||||||
|
self.lines.get_mut(current_line)
|
||||||
|
.unwrap()
|
||||||
|
.deselect();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn view(&mut self) -> Element<Message> {
|
pub fn view(&mut self) -> Element<Message> {
|
||||||
self.lines.iter_mut()
|
self.lines.iter_mut()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
@ -52,10 +67,19 @@ impl Lyric {
|
||||||
&self.value,
|
&self.value,
|
||||||
move|new_value| Message::LyricChanged { line_no, new_value },
|
move|new_value| Message::LyricChanged { line_no, new_value },
|
||||||
)
|
)
|
||||||
|
.on_submit(Message::LineAdvanced(line_no))
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_content(&mut self, content: String) {
|
pub fn set_content(&mut self, content: String) {
|
||||||
self.value = content;
|
self.value = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn select(&mut self) {
|
||||||
|
self.state.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn deselect(&mut self) {
|
||||||
|
self.state.unfocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ pub enum Message {
|
||||||
line_no: usize,
|
line_no: usize,
|
||||||
new_value: String,
|
new_value: String,
|
||||||
},
|
},
|
||||||
|
LineAdvanced(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sandbox for DelyriumApp {
|
impl Sandbox for DelyriumApp {
|
||||||
|
@ -42,6 +43,9 @@ impl Sandbox for DelyriumApp {
|
||||||
Message::LyricChanged { line_no, new_value } => {
|
Message::LyricChanged { line_no, new_value } => {
|
||||||
self.lyrics_component.update_line(new_value, line_no);
|
self.lyrics_component.update_line(new_value, line_no);
|
||||||
},
|
},
|
||||||
|
Message::LineAdvanced(current_line) => {
|
||||||
|
self.lyrics_component.advance_line(current_line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue