From 9673c7d7194b3eaecea561589de0662a281a6454 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Wed, 28 May 2025 13:46:44 +0300 Subject: [PATCH] keyboard: show refactoring --- src/gui/app.rs | 20 ++++++------------ src/gui/views/input/edit.rs | 2 +- src/gui/views/input/keyboard.rs | 37 ++++++--------------------------- src/gui/views/input/types.rs | 3 --- src/gui/views/modal.rs | 6 ++---- 5 files changed, 15 insertions(+), 53 deletions(-) diff --git a/src/gui/app.rs b/src/gui/app.rs index 1333e4a..d3ae3cb 100755 --- a/src/gui/app.rs +++ b/src/gui/app.rs @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::sync::atomic::{AtomicBool, Ordering}; +use egui::epaint::RectShape; +use egui::{Align, Context, CornerRadius, CursorIcon, Layout, Modifiers, ResizeDirection, Stroke, StrokeKind, UiBuilder, ViewportCommand}; use lazy_static::lazy_static; -use egui::{Align, Context, CornerRadius, CursorIcon, Layout, Modifiers, ResizeDirection, Stroke, UiBuilder, ViewportCommand, StrokeKind}; -use egui::epaint::{RectShape}; +use std::sync::atomic::{AtomicBool, Ordering}; -use crate::AppConfig; -use crate::gui::Colors; use crate::gui::icons::{ARROWS_IN, ARROWS_OUT, CARET_DOWN, MOON, SUN, X}; use crate::gui::platform::PlatformCallbacks; -use crate::gui::views::{Content, KeyboardContent, Modal, TitlePanel, View}; +use crate::gui::views::{Content, Modal, TitlePanel, View}; +use crate::gui::Colors; use crate::wallet::ExternalConnection; +use crate::AppConfig; lazy_static! { /// State to check if platform Back button was pressed. @@ -36,8 +36,6 @@ pub struct App { /// Main content. content: Content, - /// Keyboard content. - keyboard_content: KeyboardContent, /// Last window resize direction. resize_direction: Option, @@ -50,7 +48,6 @@ impl App { Self { platform, content: Content::default(), - keyboard_content: KeyboardContent::default(), resize_direction: None, first_draw: true } @@ -80,8 +77,6 @@ impl App { if back_pressed || ctx.input_mut(|i| i.consume_key(Modifiers::NONE, egui::Key::Escape)) { if Modal::on_back() { self.content.on_back(&self.platform); - } else if KeyboardContent::window_showing() { - KeyboardContent::hide_window(); } if back_pressed { BACK_BUTTON_PRESSED.store(false, Ordering::Relaxed); @@ -137,9 +132,6 @@ impl App { self.content.ui(ui, &self.platform); } - // Show soft keyboard content. - self.keyboard_content.window_ui(ctx); - // Provide incoming data to wallets. if let Some(data) = crate::consume_incoming_data() { if !data.is_empty() { diff --git a/src/gui/views/input/edit.rs b/src/gui/views/input/edit.rs index e471ebe..937398a 100644 --- a/src/gui/views/input/edit.rs +++ b/src/gui/views/input/edit.rs @@ -161,7 +161,7 @@ impl TextEdit { if self.enter_pressed { KeyboardContent::unshift(); } - KeyboardContent::show_window(self.numeric); + KeyboardContent::default().window_ui(self.numeric, ui.ctx()); } }); }); diff --git a/src/gui/views/input/keyboard.rs b/src/gui/views/input/keyboard.rs index 97eaf6d..d499d39 100644 --- a/src/gui/views/input/keyboard.rs +++ b/src/gui/views/input/keyboard.rs @@ -51,15 +51,7 @@ impl KeyboardContent { const MAX_WIDTH_NUMBERS: f32 = 400.0; /// Draw keyboard content as separate [`Window`]. - pub fn window_ui(&mut self, ctx: &egui::Context) { - // Setup state. - if !KeyboardContent::window_showing() { - self.state = KeyboardState::default(); - return; - } else { - let r_state = WINDOW_STATE.read(); - self.state = (*r_state).clone(); - } + pub fn window_ui(&mut self, numeric: bool, ctx: &egui::Context) { let width = ctx.screen_rect().width(); let layer_id = egui::Window::new("soft_keyboard") .title_bar(false) @@ -86,7 +78,11 @@ impl KeyboardContent { }) .show(ctx, |ui| { ui.set_min_width(width); - let numeric = *self.state.layout == KeyboardLayout::NUMBERS; + // Setup state. + { + let r_state = WINDOW_STATE.read(); + self.state = (*r_state).clone(); + } // Calculate content width. let side_insets = View::get_left_inset() + View::get_right_inset(); let available_width = width - side_insets; @@ -493,30 +489,9 @@ impl KeyboardContent { None } - /// Check if keyboard is showing. - pub fn window_showing() -> bool { - let r_state = WINDOW_STATE.read(); - r_state.show.load(Ordering::Relaxed) - } - - /// Show keyboard. - pub fn show_window(numeric: bool) { - let mut w_state = WINDOW_STATE.write(); - if numeric { - w_state.layout = Arc::new(KeyboardLayout::NUMBERS); - } - w_state.show.store(true, Ordering::Relaxed); - } - /// Emulate stop of Shift key press. pub fn unshift() { let r_state = WINDOW_STATE.read(); r_state.shift.store(false, Ordering::Relaxed); } - - /// Hide keyboard window. - pub fn hide_window() { - let r_state = WINDOW_STATE.read(); - r_state.show.store(false, Ordering::Relaxed); - } } \ No newline at end of file diff --git a/src/gui/views/input/types.rs b/src/gui/views/input/types.rs index afb61cc..b49184c 100644 --- a/src/gui/views/input/types.rs +++ b/src/gui/views/input/types.rs @@ -36,8 +36,6 @@ pub struct KeyboardState { pub layout: Arc, /// Flag to enter uppercase symbol first. pub shift: Arc, - /// Flag to show window. - pub show: Arc, } impl Default for KeyboardState { @@ -46,7 +44,6 @@ impl Default for KeyboardState { last_event: Arc::new(None), layout: Arc::new(KeyboardLayout::TEXT), shift: Arc::new(AtomicBool::new(false)), - show: Arc::new(AtomicBool::new(false)), } } } \ No newline at end of file diff --git a/src/gui/views/modal.rs b/src/gui/views/modal.rs index e0f4295..697ceef 100755 --- a/src/gui/views/modal.rs +++ b/src/gui/views/modal.rs @@ -14,14 +14,14 @@ use egui::epaint::{RectShape, Shadow}; use egui::os::OperatingSystem; -use egui::{Align2, CornerRadius, RichText, Stroke, UiBuilder, Vec2, StrokeKind}; +use egui::{Align2, CornerRadius, RichText, Stroke, StrokeKind, UiBuilder, Vec2}; use lazy_static::lazy_static; use parking_lot::RwLock; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use crate::gui::views::types::{ModalPosition, ModalState}; -use crate::gui::views::{Content, KeyboardContent, View}; +use crate::gui::views::{Content, View}; use crate::gui::Colors; lazy_static! { @@ -77,8 +77,6 @@ impl Modal { pub fn close() { let mut w_nav = MODAL_STATE.write(); w_nav.modal = None; - // Hide keyboard. - KeyboardContent::hide_window(); } /// Setup possibility to close [`Modal`].