Browse Source

utilities/dialogs: add cursot Unfocused state as default

jmap-eventsource
Manos Pitsidianakis 1 year ago
parent
commit
e01275cd93
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 47
      src/components/utilities/dialogs.rs

47
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<T: 'static + PartialEq + Debug + Clone + Sync + Send> 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<T: PartialEq + Debug + Clone + Sync + Send, F: 'static + Sync + Send> 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(),

Loading…
Cancel
Save