wip5 (66e): kk

This commit is contained in:
🪞👃🪞 2024-12-09 17:53:08 +01:00
parent 5507b71973
commit 7d78811f68
4 changed files with 117 additions and 118 deletions

View file

@ -112,6 +112,9 @@ impl Render<Tui> for Styled<&str> {
} }
pub trait BorderStyle: Send + Sync + Copy { pub trait BorderStyle: Send + Sync + Copy {
fn wrap <W: Render<Tui>> (self, w: W) -> Bordered<Self, W> {
Bordered(self, w)
}
const NW: &'static str = ""; const NW: &'static str = "";
const N: &'static str = ""; const N: &'static str = "";
const NE: &'static str = ""; const NE: &'static str = "";

View file

@ -52,8 +52,7 @@ impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> {
} }
} }
impl<'a> Content<Tui> for PhraseView<'a> { render!(|self: PhraseView<'a>|{
fn content (&self) -> impl Render<Tui> {
let Self { let Self {
focused, entered, size, focused, entered, size,
phrase, view_mode, buffer, phrase, view_mode, buffer,
@ -140,8 +139,7 @@ impl<'a> Content<Tui> for PhraseView<'a> {
Tui::push_y(1, Widget::new(|to|Ok(Some(to)), cursor)) Tui::push_y(1, Widget::new(|to|Ok(Some(to)), cursor))
)), )),
)))) ))))
} });
}
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum PhraseViewMode { pub enum PhraseViewMode {

View file

@ -63,14 +63,13 @@ render!(|self: PhraseListView<'a>|{
} }
}); });
let border_color = if *focused {Color::Rgb(100, 110, 40)} else {Color::Rgb(70, 80, 50)}; let border_color = if *focused {Color::Rgb(100, 110, 40)} else {Color::Rgb(70, 80, 50)};
let border = Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(border_color)); let content = Tui::bg(Color::Rgb(28, 35, 25), Tui::fill_xy(content));
let content = content.fill_xy().bg(Color::Rgb(28, 35, 25)).border(border);
let title_color = if *focused {Color::Rgb(150, 160, 90)} else {Color::Rgb(120, 130, 100)}; let title_color = if *focused {Color::Rgb(150, 160, 90)} else {Color::Rgb(120, 130, 100)};
let upper_left = format!("[{}] {title}", if *entered {""} else {" "}); let upper_left = format!("[{}] {title}", if *entered {""} else {" "});
let upper_right = format!("({})", phrases.len()); let upper_right = format!("({})", phrases.len());
lay!( lay!(
content, Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(border_color)).wrap(content),
Tui::fg(title_color, upper_left.to_string()).push_x(1).align_nw().fill_xy(), Tui::fill_xy(Tui::at_nw(Tui::push_x(1, Tui::fg(title_color, upper_left.to_string())))),
Tui::fg(title_color, upper_right.to_string()).pull_x(1).align_ne().fill_xy(), Tui::fill_xy(Tui::at_ne(Tui::pull_x(1, Tui::fg(title_color, upper_right.to_string())))),
) )
}); });

View file

@ -35,28 +35,27 @@ impl<'a> PhraseSelector<'a> {
} }
// TODO: Display phrases always in order of appearance // TODO: Display phrases always in order of appearance
impl<'a> Content<Tui> for PhraseSelector<'a> { render!(|self:PhraseSelector<'a>|{
fn content (&self) -> impl Render<Tui> {
let Self { title, phrase, focused, entered } = self; let Self { title, phrase, focused, entered } = self;
let content = Layers::new(move|add|{ let content = Layers::new(move|add|{
if let Some((instant, Some(phrase))) = phrase { if let Some((instant, Some(phrase))) = phrase {
let Phrase { ref name, color, length, .. } = *phrase.read().unwrap(); let Phrase { ref name, color, length, .. } = *phrase.read().unwrap();
let length = PhraseLength::new(length, None); let length = PhraseLength::new(length, None);
let length = length.align_e().fill_x(); let length = Tui::fill_x(Tui::at_e(length));
let row1 = lay!(format!(" ").align_w().fill_x(), length).fill_x(); let row1 = Tui::fill_x(lay!(Tui::fill_x(Tui::at_w(format!(" "))), length));
let row2 = format!(" {name}"); let row2 = format!(" {name}");
let row2 = TuiStyle::bold(row2, true); let row2 = Tui::bold(true, row2);
add(&Tui::bg(color.base.rgb, Tui::fill_x(Tui::to_south(row1, row2))))?; add(&Tui::bg(color.base.rgb, Tui::fill_x(Tui::to_south(row1, row2))))?;
} }
Ok(()) Ok(())
}); });
let border_color = if *focused {Color::Rgb(100, 110, 40)} else {Color::Rgb(70, 80, 50)}; let border_color = if *focused {Color::Rgb(100, 110, 40)} else {Color::Rgb(70, 80, 50)};
let border = Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(border_color)); let border = Lozenge(Style::default().bg(Color::Rgb(40, 50, 30)).fg(border_color));
let content = content.fill_xy().bg(Color::Rgb(28, 35, 25)).border(border); //let content = Tui::bg(Color::Rgb(28, 35, 25), Tui::fill_xy(content)).border(border);
let content = Tui::bg(Color::Rgb(28, 35, 25), Tui::fill_xy(content));
let title_color = if *focused {Color::Rgb(150, 160, 90)} else {Color::Rgb(120, 130, 100)}; let title_color = if *focused {Color::Rgb(150, 160, 90)} else {Color::Rgb(120, 130, 100)};
lay!( Tui::over(
content, border.wrap(content),
TuiStyle::fg(*title, title_color).push_x(1).align_nw().fill_xy(), Tui::fill_xy(Tui::at_nw(Tui::push_x(1, Tui::fg(title_color, *title)))),
) )
} });
}