add phrase names

This commit is contained in:
🪞👃🪞 2024-10-11 13:56:56 +03:00
parent 4081c23aea
commit 0c5967a915
2 changed files with 8 additions and 3 deletions

View file

@ -46,8 +46,11 @@ impl Content for PhrasePool<Tui> {
fn content (&self) -> impl Widget<Engine = Tui> {
let content = col!(
(i, phrase) in self.phrases.iter().enumerate() => Layers::new(|add|{
let color = phrase.read().unwrap().color;
add(&format!(" {i}").fixed_y(2).bg(if i == self.phrase {
let Phrase { ref name, color, .. } = *phrase.read().unwrap();
add(&col!(
format!(" {i}"),
format!(" {}", name.read().unwrap()),
).fill_x().bg(if i == self.phrase {
color //Color::Rgb(40, 50, 30)
} else {
color //Color::Rgb(28, 35, 25)
@ -96,12 +99,14 @@ impl Handle<Tui> for PhrasePool<Tui> {
},
key!(KeyCode::Char('a')) => { // append new
let mut phrase = Phrase::default();
phrase.name = Arc::new(RwLock::new("(no name)".to_string()));
phrase.color = random_color();
self.phrases.push(Arc::new(RwLock::new(phrase)));
self.phrase = self.phrases.len() - 1;
},
key!(KeyCode::Char('i')) => { // insert new
let mut phrase = Phrase::default();
phrase.name = Arc::new(RwLock::new("(no name)".to_string()));
phrase.color = random_color();
self.phrases.insert(self.phrase, Arc::new(RwLock::new(phrase)));
self.phrase += 1;