mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
add Phrase::duplicate and PhrasePool::index_of()
This commit is contained in:
parent
e002d2e51a
commit
d2cda0c54d
2 changed files with 14 additions and 1 deletions
|
|
@ -140,6 +140,14 @@ impl<E: Engine> PhrasePool<E> {
|
|||
pub fn phrase (&self) -> &Arc<RwLock<Phrase>> {
|
||||
&self.phrases[self.phrase]
|
||||
}
|
||||
pub fn index_of (&self, phrase: &Phrase) -> Option<usize> {
|
||||
for i in 0..self.phrases.len() {
|
||||
if *self.phrases[i].read().unwrap() == *phrase {
|
||||
return Some(i)
|
||||
}
|
||||
}
|
||||
return None
|
||||
}
|
||||
}
|
||||
impl<E: Engine> PhraseEditor<E> {
|
||||
pub fn new () -> Self {
|
||||
|
|
@ -179,6 +187,11 @@ impl Phrase {
|
|||
color: color.unwrap_or_else(random_color)
|
||||
}
|
||||
}
|
||||
pub fn duplicate (&self) -> Self {
|
||||
let mut clone = self.clone();
|
||||
clone.uuid = uuid::Uuid::new_v4();
|
||||
clone
|
||||
}
|
||||
pub fn toggle_loop (&mut self) {
|
||||
self.loop_on = !self.loop_on;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ impl Handle<Tui> for PhrasePool<Tui> {
|
|||
self.phrase += 1;
|
||||
},
|
||||
key!(KeyCode::Char('d')) => { // insert duplicate
|
||||
let mut phrase = (*self.phrases[self.phrase].read().unwrap()).clone();
|
||||
let mut phrase = self.phrases[self.phrase].read().unwrap().duplicate();
|
||||
phrase.color = random_color_near(phrase.color, 0.2);
|
||||
self.phrases.insert(self.phrase + 1, Arc::new(RwLock::new(phrase)));
|
||||
self.phrase += 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue