allow exiting from modals; add buttons

This commit is contained in:
🪞👃🪞 2025-04-04 16:32:53 +03:00
parent a4ee3d2912
commit 2e072cb51c
6 changed files with 81 additions and 68 deletions

View file

@ -1,14 +1,17 @@
use crate::*;
impl Taggart {
pub fn mode_quit (&mut self, event: &Event) {
todo!()
}
pub fn quit_begin (&mut self, input: &TuiIn) {
if self.tasks.len() == 0 {
input.done()
} else {
self.mode = Some(Mode::Quit { value: false })
self.mode = Some(Mode::Quit { value: 1 })
}
}
pub fn mode_quit (&mut self, event: &Event) {
match event {
press!(Esc) => { self.mode = None },
_ => todo!()
}
}
}

View file

@ -1,12 +1,15 @@
use crate::*;
impl Taggart {
pub fn mode_save (&mut self, event: &Event) {
todo!()
}
pub fn save_begin (&mut self) {
if self.tasks.len() > 0 {
self.mode = Some(Mode::Save { value: false })
self.mode = Some(Mode::Save { value: 1 })
}
}
pub fn mode_save (&mut self, event: &Event) {
match event {
press!(Esc) => { self.mode = None },
_ => todo!()
}
}
}

View file

@ -26,10 +26,10 @@ pub enum Mode {
index: usize,
},
Save {
value: bool,
value: u8,
},
Quit {
value: bool,
value: u8,
},
}

View file

@ -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),