mirror of
https://code.gri.mw/GUI/grim.git
synced 2026-07-10 08:54:11 +00:00
ui: save mnemonic phrase word on enter key press, remove useless separate function to check back press event
This commit is contained in:
+1
-8
@@ -43,7 +43,7 @@ impl<Platform> PlatformApp<Platform> {
|
||||
impl<Platform: PlatformCallbacks> eframe::App for PlatformApp<Platform> {
|
||||
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<Platform: PlatformCallbacks> eframe::App for PlatformApp<Platform> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// 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)]
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user