mirror of
https://github.com/jwinterm/grim.git
synced 2026-10-22 15:58:32 +02:00
ui: save mnemonic phrase word on enter key press, remove useless separate function to check back press event
This commit is contained in:
@@ -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