mirror of
https://github.com/jwinterm/grim.git
synced 2026-10-17 14:21:24 +02:00
keyboard: show refactoring
This commit is contained in:
+6
-14
@@ -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<Platform> {
|
||||
|
||||
/// Main content.
|
||||
content: Content,
|
||||
/// Keyboard content.
|
||||
keyboard_content: KeyboardContent,
|
||||
|
||||
/// Last window resize direction.
|
||||
resize_direction: Option<ResizeDirection>,
|
||||
@@ -50,7 +48,6 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||
Self {
|
||||
platform,
|
||||
content: Content::default(),
|
||||
keyboard_content: KeyboardContent::default(),
|
||||
resize_direction: None,
|
||||
first_draw: true
|
||||
}
|
||||
@@ -80,8 +77,6 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||
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<Platform: PlatformCallbacks> App<Platform> {
|
||||
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() {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,6 @@ pub struct KeyboardState {
|
||||
pub layout: Arc<KeyboardLayout>,
|
||||
/// Flag to enter uppercase symbol first.
|
||||
pub shift: Arc<AtomicBool>,
|
||||
/// Flag to show window.
|
||||
pub show: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
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)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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`].
|
||||
|
||||
Reference in New Issue
Block a user