Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bin/edit/draw_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ pub fn draw_handle_wants_close(ctx: &mut Context, state: &mut State) {
ctx.table_next_row();
ctx.inherit_focus();

if ctx.button("yes", loc(LocId::UnsavedChangesDialogYes)) {
if ctx.shortcut_button("yes", loc(LocId::UnsavedChangesDialogYes), vk::S) {
action = Action::Save;
}
ctx.inherit_focus();
if ctx.button("no", loc(LocId::UnsavedChangesDialogNo)) {
if ctx.shortcut_button("no", loc(LocId::UnsavedChangesDialogNo), vk::N) {
action = Action::Discard;
}
if ctx.button("cancel", loc(LocId::Cancel)) {
Expand Down
44 changes: 44 additions & 0 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,50 @@ impl<'a> Context<'a, '_> {
self.button_activated()
}

pub fn shortcut_button(
&mut self,
classname: &'static str,
text: &str,
shortcut: InputKey,
) -> bool {
self.styled_label_begin(classname);
self.attr_focusable();
if self.is_focused() {
self.attr_reverse();
}
let shortcut_letter = shortcut.value() as u8 as char;
if shortcut_letter.is_ascii_uppercase() {
let mut shortcut_text = String::new();
if shortcut.modifiers_contains(kbmod::CTRL) {
shortcut_text.push_str(self.tui.modifier_translations.ctrl);
shortcut_text.push('+');
}
if shortcut.modifiers_contains(kbmod::ALT) {
shortcut_text.push_str(self.tui.modifier_translations.alt);
shortcut_text.push('+');
}
if shortcut.modifiers_contains(kbmod::SHIFT) {
shortcut_text.push_str(self.tui.modifier_translations.shift);
shortcut_text.push('+');
}
shortcut_text.push(shortcut_letter);
self.styled_label_add_text("[");
let button_text = format!("{} ({})", text, shortcut_text);
self.styled_label_add_text(&button_text);
self.styled_label_add_text("]");
} else {
{
self.styled_label_add_text("[");
self.styled_label_add_text(text);
self.styled_label_add_text("]");
}
}

self.styled_label_end();

self.button_activated()
}

/// Creates a checkbox with the given text.
/// Returns true if the checkbox was activated.
pub fn checkbox(&mut self, classname: &'static str, text: &str, checked: &mut bool) -> bool {
Expand Down