From c166f21d1e9fcae87dd2ca4d25f4777e9e2a516e Mon Sep 17 00:00:00 2001 From: ardocrat Date: Sun, 23 Jul 2023 17:21:02 +0300 Subject: [PATCH] ui: save mnemonic phrase word on enter key press, remove useless separate function to check back press event --- src/gui/app.rs | 9 +-------- src/gui/views/views.rs | 7 +++++++ src/gui/views/wallets/creation/mnemonic.rs | 11 +++++++++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/gui/app.rs b/src/gui/app.rs index c2d10401..77157feb 100644 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -43,7 +43,7 @@ impl PlatformApp { impl eframe::App for PlatformApp { fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) { // Handle Esc keyboard key event and platform Back button key event. - let back_button_pressed = back_button_pressed(); + let back_button_pressed = BACK_BUTTON_PRESSED.load(Ordering::Relaxed); if ctx.input(|i| i.key_pressed(egui::Key::Escape) || back_button_pressed) { if back_button_pressed { BACK_BUTTON_PRESSED.store(false, Ordering::Relaxed); @@ -70,13 +70,6 @@ impl eframe::App for PlatformApp { } } - - -/// Check if platform Back button was pressed. -fn back_button_pressed() -> bool { - BACK_BUTTON_PRESSED.load(Ordering::Relaxed) -} - #[allow(dead_code)] #[cfg(target_os = "android")] #[allow(non_snake_case)] diff --git a/src/gui/views/views.rs b/src/gui/views/views.rs index 19746f1c..40c2b5f1 100644 --- a/src/gui/views/views.rs +++ b/src/gui/views/views.rs @@ -29,6 +29,13 @@ impl View { /// Default stroke around views. pub const DEFAULT_STROKE: Stroke = Stroke { width: 1.0, color: Colors::STROKE }; + /// Callback on Enter key press event. + pub fn on_enter_key(ui: &mut egui::Ui, cb: impl FnOnce()) { + if ui.ctx().input(|i| i.key_pressed(egui::Key::Enter)) { + (cb)(); + } + } + /// Calculate margin for far left view based on display insets (cutouts). pub fn far_left_inset_margin(ui: &mut egui::Ui) -> f32 { if ui.available_rect_before_wrap().min.x == 0.0 { diff --git a/src/gui/views/wallets/creation/mnemonic.rs b/src/gui/views/wallets/creation/mnemonic.rs index f1014e95..37f12d0c 100644 --- a/src/gui/views/wallets/creation/mnemonic.rs +++ b/src/gui/views/wallets/creation/mnemonic.rs @@ -74,7 +74,7 @@ impl MnemonicSetup { ui.vertical_centered(|ui| { ui.label(RichText::new(t!("wallets.saved_phrase")).size(16.0).color(Colors::GRAY)); }); - ui.add_space(6.0); + ui.add_space(4.0); ScrollArea::vertical() .id_source("confirm_mnemonic_words_list") .auto_shrink([false; 2]) @@ -266,7 +266,8 @@ impl MnemonicSetup { }); }); columns[1].vertical_centered_justified(|ui| { - View::button(ui, t!("continue"), Colors::WHITE, || { + // Callback to save the word. + let mut save = || { // Check if word is valid. let word_index = self.word_num_edit - 1; if !self.mnemonic.is_valid_word(&self.word_edit, word_index) { @@ -291,7 +292,13 @@ impl MnemonicSetup { self.word_num_edit += 1; self.word_edit = "".to_string(); } + }; + // Call save on Enter key press. + View::on_enter_key(ui, || { + (save)(); }); + // Show save button. + View::button(ui, t!("continue"), Colors::WHITE, save); }); }); ui.add_space(6.0);