menu: appearance + controls (#22)

This commit is contained in:
Jens K.
2024-12-23 10:39:53 +01:00
committed by GitHub
parent c9b444e91a
commit 98ee2bc16b
3 changed files with 125 additions and 14 deletions

View File

@@ -211,6 +211,10 @@ impl<T> Clock<T> {
&self.mode
}
pub fn is_running(&self) -> bool {
self.mode == Mode::Tick
}
pub fn is_edit_mode(&mut self) -> bool {
matches!(self.mode, Mode::Editable(_, _))
}

View File

@@ -7,21 +7,38 @@ use ratatui::{
style::{Modifier, Style},
symbols,
text::{Line, Span},
widgets::{Block, Borders, Widget},
widgets::{Block, Borders, Cell, Row, Table, Widget},
};
#[derive(Debug, Clone)]
pub struct Footer {
show_menu: bool,
running_clock: bool,
selected_content: Content,
content_labels: BTreeMap<Content, String>,
edit_mode: bool,
}
pub struct FooterArgs {
pub show_menu: bool,
pub running_clock: bool,
pub selected_content: Content,
pub edit_mode: bool,
}
impl Footer {
pub fn new(show_menu: bool, selected_content: Content) -> Self {
pub fn new(args: FooterArgs) -> Self {
let FooterArgs {
show_menu,
running_clock,
selected_content,
edit_mode,
} = args;
Self {
show_menu,
running_clock,
selected_content,
edit_mode,
content_labels: BTreeMap::from([
(Content::Countdown, "[c]ountdown".into()),
(Content::Timer, "[t]imer".into()),
@@ -34,7 +51,7 @@ impl Footer {
impl Widget for Footer {
fn render(self, area: Rect, buf: &mut Buffer) {
let [border_area, menu_area] =
Layout::vertical([Constraint::Length(1), Constraint::Fill(0)]).areas(area);
Layout::vertical([Constraint::Length(2), Constraint::Percentage(100)]).areas(area);
Block::new()
.borders(Borders::TOP)
.title(format! {"[m]enu {:} ", if self.show_menu {""} else {""}})
@@ -42,12 +59,7 @@ impl Widget for Footer {
.render(border_area, buf);
// show menu
if self.show_menu {
let [title_area, labels_area] =
Layout::horizontal([Constraint::Length(12), Constraint::Fill(0)]).areas(menu_area);
Span::styled("screens", Style::default().add_modifier(Modifier::BOLD))
.render(title_area, buf);
let spans: Vec<Span> = self
let content_labels: Vec<Span> = self
.content_labels
.iter()
.enumerate()
@@ -65,7 +77,74 @@ impl Widget for Footer {
Span::styled(label, style)
})
.collect();
Line::from(spans).render(labels_area, buf);
const SPACE: &str = " ";
let widths = [Constraint::Length(12), Constraint::Percentage(100)];
Table::new(
[
// content
Row::new(vec![
Cell::from(Span::styled(
"screens",
Style::default().add_modifier(Modifier::BOLD),
)),
Cell::from(Line::from(content_labels)),
]),
// format
Row::new(vec![
Cell::from(Span::styled(
"appearance",
Style::default().add_modifier(Modifier::BOLD),
)),
Cell::from(Line::from(vec![
Span::from("[,]change style"),
Span::from(SPACE),
Span::from("[.]toggle deciseconds"),
])),
]),
// edit
Row::new(vec![
Cell::from(Span::styled(
"controls",
Style::default().add_modifier(Modifier::BOLD),
)),
Cell::from(Line::from({
if self.edit_mode {
vec![
Span::from("[e]dit done"),
Span::from(SPACE),
Span::from("[← →]edit selection"),
Span::from(SPACE),
Span::from("[↑]edit up"),
Span::from(SPACE),
Span::from("[↓]edit down"),
]
} else {
let mut spans = vec![
Span::from(if self.running_clock {
"[s]top"
} else {
"[s]tart"
}),
Span::from(SPACE),
Span::from("[r]eset"),
Span::from(SPACE),
Span::from("[e]dit"),
];
if self.selected_content == Content::Pomodoro {
spans.extend_from_slice(&[
Span::from(SPACE),
Span::from("[← →]switch work/pause"),
]);
}
spans
}
})),
]),
],
widths,
)
.render(menu_area, buf);
}
}
}