slightly nicer modal

still imperfect sizing
This commit is contained in:
🪞👃🪞 2025-04-27 20:18:10 +03:00
parent c06efce910
commit 573bb8ae4c

View file

@ -1,12 +1,28 @@
use crate::*;
impl Perch {
pub fn render_dialog (&self, to: &mut TuiOut) {
match self.mode {
Some(Mode::Edit { .. }) => {},
Some(_) => to.tint_all(Color::Rgb(96,96,96), Color::Rgb(48,48,48), Modifier::DIM),
_ => {}
}
match self.mode {
Some(Mode::Edit { .. }) => {},
Some(Mode::Save { choice }) => Content::render(&self.dialog_save(choice), to),
Some(Mode::Quit { choice }) => Content::render(&self.dialog_quit(choice), to),
Some(Mode::Help { page }) => Content::render(&self.dialog_help(page), to),
_ => {},
}
}
fn dialog (content: impl Content<TuiOut>) -> impl Content<TuiOut> {
let pos = |x|Fill::xy( Align::c(x));
let style = |x|Tui::modify(false, Modifier::DIM, Tui::fg_bg(FG_MODAL, BG_MODAL, x));
let border = |x|Margin::xy(1, 1, Bsp::b(Border(true, Lozenge(true, Default::default())), x));
let bg = |x|Bsp::a(x, Repeat(" "));
pos(style(border(bg(content))))
Bsp::b(
Fill::xy(Tui::fg_bg(Color::Rgb(64,64,64), Color::Rgb(32,32,32), "")),
Fixed::xy(64, 15, Tui::fg_bg(Color::Rgb(255,255,255), Color::Rgb(16,16,16), Bsp::b(
Repeat(" "),
Outer(true, Style::default().fg(Tui::g(96))).enclose(content)
)))
)
}
fn dialog_help (&self, _page: u8) -> impl Content<TuiOut> {
Self::dialog(Bsp::s(
@ -22,7 +38,8 @@ impl Perch {
];
Self::dialog(Bsp::s(
format!("Save {} change(s)?", self.changes),
Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))))
Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))
))
}
fn dialog_quit (&self, choice: u8) -> impl Content<TuiOut> {
let choices = [
@ -32,20 +49,7 @@ impl Perch {
];
Self::dialog(Bsp::s(
format!("Save {} change(s) before exiting?", self.changes),
Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))))
}
pub fn render_dialog (&self, to: &mut TuiOut) {
match self.mode {
Some(Mode::Edit { .. }) => {},
Some(_) => to.tint_all(Color::Rgb(96,96,96), Color::Rgb(48,48,48), Modifier::DIM),
_ => {}
}
match self.mode {
Some(Mode::Edit { .. }) => {},
Some(Mode::Save { choice }) => Content::render(&self.dialog_save(choice), to),
Some(Mode::Quit { choice }) => Content::render(&self.dialog_quit(choice), to),
Some(Mode::Help { page }) => Content::render(&self.dialog_help(page), to),
_ => {},
}
Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))
))
}
}