From e01275cd93eeb673160273d5a3de12aa22ac91da Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Wed, 25 Nov 2020 21:01:18 +0200 Subject: [PATCH] utilities/dialogs: add cursot Unfocused state as default --- src/components/utilities/dialogs.rs | 47 ++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/src/components/utilities/dialogs.rs b/src/components/utilities/dialogs.rs index 8221d069..dcf66df9 100644 --- a/src/components/utilities/dialogs.rs +++ b/src/components/utilities/dialogs.rs @@ -29,6 +29,7 @@ const CANCEL_LENGTH: usize = "Cancel".len(); #[derive(Debug, Copy, PartialEq, Clone)] enum SelectorCursor { + Unfocused, /// Cursor is at an entry Entry(usize), /// Cursor is located on the Ok button @@ -177,6 +178,27 @@ impl Component for UIDialo } return true; } + (UIEvent::Input(Key::Down), SelectorCursor::Unfocused) => { + if self.single_only { + for c in self.content.row_iter(0..(width - 1), 0) { + self.content[c] + .set_fg(highlighted_attrs.fg) + .set_bg(highlighted_attrs.bg) + .set_attrs(highlighted_attrs.attrs); + } + self.entries[0].1 = true; + } else { + for c in self.content.row_iter(0..3, 0) { + self.content[c] + .set_fg(highlighted_attrs.fg) + .set_bg(highlighted_attrs.bg) + .set_attrs(highlighted_attrs.attrs); + } + } + self.cursor = SelectorCursor::Entry(0); + self.dirty = true; + return true; + } (UIEvent::Input(Key::Up), SelectorCursor::Entry(c)) if c > 0 => { if self.single_only { // Redraw selection @@ -531,6 +553,29 @@ impl Component for UIConfirmationDialog { self.dirty = true; return true; } + (UIEvent::Input(ref key), SelectorCursor::Unfocused) + if shortcut!(key == shortcuts["general"]["scroll_down"]) => + { + if self.single_only { + for c in self.content.row_iter(0..(width - 1), 0) { + self.content[c] + .set_fg(highlighted_attrs.fg) + .set_bg(highlighted_attrs.bg) + .set_attrs(highlighted_attrs.attrs); + } + self.entries[0].1 = true; + } else { + for c in self.content.row_iter(0..3, 0) { + self.content[c] + .set_fg(highlighted_attrs.fg) + .set_bg(highlighted_attrs.bg) + .set_attrs(highlighted_attrs.attrs); + } + } + self.cursor = SelectorCursor::Entry(0); + self.dirty = true; + return true; + } (UIEvent::Input(ref key), SelectorCursor::Entry(c)) if c < self.entries.len().saturating_sub(1) && shortcut!(key == shortcuts["general"]["scroll_down"]) => @@ -767,7 +812,7 @@ impl Selec single_only, entries: identifiers, content, - cursor: SelectorCursor::Entry(0), + cursor: SelectorCursor::Unfocused, vertical_alignment: Alignment::Center, horizontal_alignment: Alignment::Center, title: title.to_string(),