mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 09:36:42 +01:00
allow exiting from modals; add buttons
This commit is contained in:
parent
a4ee3d2912
commit
2e072cb51c
6 changed files with 81 additions and 68 deletions
49
src/view.rs
49
src/view.rs
|
|
@ -4,17 +4,6 @@ pub(crate) use pad::PadStr;
|
|||
|
||||
mod table; pub use self::table::*;
|
||||
|
||||
impl Taggart {
|
||||
pub(crate) const FG_BROWSE: Color = Color::Rgb(255, 192, 0);
|
||||
pub(crate) const BG_BROWSE: Color = Color::Rgb(0, 0, 0);
|
||||
pub(crate) const BG_EDIT: Color = Color::Rgb(48, 128, 0);
|
||||
pub(crate) const FG_EDIT: Color = Color::Rgb(255, 255, 255);
|
||||
pub(crate) const BG_SAVE: Color = Color::Rgb(192, 96, 0);
|
||||
pub(crate) const FG_SAVE: Color = Color::Rgb(255, 255, 255);
|
||||
pub(crate) const BG_QUIT: Color = Color::Rgb(128, 0, 0);
|
||||
pub(crate) const FG_QUIT: Color = Color::Rgb(255, 255, 255);
|
||||
}
|
||||
|
||||
impl Content<TuiOut> for Taggart {
|
||||
fn content (&self) -> impl Render<TuiOut> {
|
||||
let w = self.display.w();
|
||||
|
|
@ -35,11 +24,10 @@ impl Content<TuiOut> for Taggart {
|
|||
Color::Rgb(48,48,48),
|
||||
Modifier::DIM
|
||||
);
|
||||
let message = format!("You have {} unsaved change(s)", self.tasks.len());
|
||||
let modal = Fill::xy(Align::c(Tui::modify(false, Modifier::DIM, Tui::fg_bg(
|
||||
Color::Rgb(255,255,255),
|
||||
Color::Rgb(0, 0, 0),
|
||||
Expand::xy(2, 2, "Save?")))));
|
||||
let message = Bsp::s(format!("Save {} change(s)?", self.tasks.len()),
|
||||
Bsp::s("",
|
||||
Bsp::e(" Clear changes ", Bsp::e(" Continue editing ", " Save "))));
|
||||
let modal = Self::modal(message);
|
||||
Content::render(&modal, to)
|
||||
},
|
||||
Some(Mode::Quit { value }) => {
|
||||
|
|
@ -48,11 +36,10 @@ impl Content<TuiOut> for Taggart {
|
|||
Color::Rgb(48,48,48),
|
||||
Modifier::DIM
|
||||
);
|
||||
let message = format!("You have {} unsaved change(s)", self.tasks.len());
|
||||
let modal = Fill::xy(Align::c(Tui::modify(false, Modifier::DIM, Tui::fg_bg(
|
||||
Color::Rgb(255,255,255),
|
||||
Color::Rgb(0, 0, 0),
|
||||
Expand::xy(2, 2, "Save?")))));
|
||||
let message = Bsp::s(format!("Save {} change(s) before exiting?", self.tasks.len()),
|
||||
Bsp::s("",
|
||||
Bsp::e(" Exit without saving ", Bsp::e(" Cancel ", " Save and exit "))));
|
||||
let modal = Self::modal(message);
|
||||
Content::render(&modal, to)
|
||||
},
|
||||
_ => {},
|
||||
|
|
@ -61,6 +48,26 @@ impl Content<TuiOut> for Taggart {
|
|||
}
|
||||
|
||||
impl Taggart {
|
||||
pub(crate) const FG_BROWSE: Color = Color::Rgb(255, 192, 0);
|
||||
pub(crate) const BG_BROWSE: Color = Color::Rgb(0, 0, 0);
|
||||
pub(crate) const BG_EDIT: Color = Color::Rgb(48, 128, 0);
|
||||
pub(crate) const FG_EDIT: Color = Color::Rgb(255, 255, 255);
|
||||
pub(crate) const BG_SAVE: Color = Color::Rgb(192, 96, 0);
|
||||
pub(crate) const FG_SAVE: Color = Color::Rgb(255, 255, 255);
|
||||
pub(crate) const BG_QUIT: Color = Color::Rgb(128, 0, 0);
|
||||
pub(crate) const FG_QUIT: Color = Color::Rgb(255, 255, 255);
|
||||
pub(crate) const FG_MODAL: Color = Color::Rgb(255, 255, 255);
|
||||
pub(crate) const BG_MODAL: Color = Color::Rgb(0, 0, 0);
|
||||
fn modal (content: impl Content<TuiOut>) -> impl Content<TuiOut> {
|
||||
let position = |x|Fill::xy(
|
||||
Align::c(x));
|
||||
let style = |x|Tui::modify(false, Modifier::DIM,
|
||||
Tui::fg_bg(Self::FG_MODAL, Self::BG_MODAL, x));
|
||||
let border = |x|Margin::xy(1, 1, Bsp::b(
|
||||
Border(true, Lozenge(true, Default::default())),
|
||||
x));
|
||||
position(style(border(content)))
|
||||
}
|
||||
fn title_bar (&self) -> impl Content<TuiOut> {
|
||||
status_bar(
|
||||
Color::Rgb(0, 0, 0),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue