mirror of
https://github.com/jwinterm/grim.git
synced 2026-10-19 06:48:33 +02:00
modal: move focus setup to the root content
This commit is contained in:
+14
-14
@@ -13,22 +13,15 @@
|
||||
// limitations under the License.
|
||||
|
||||
use egui::epaint::RectShape;
|
||||
use egui::{Align, Context, CornerRadius, CursorIcon, Layout, Modifiers, ResizeDirection, Stroke, StrokeKind, UiBuilder, ViewportCommand};
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use egui::{Align, Context, CornerRadius, CursorIcon, LayerId, Layout, Modifiers, Order, ResizeDirection, Stroke, StrokeKind, UiBuilder, ViewportCommand};
|
||||
|
||||
use crate::gui::icons::{ARROWS_IN, ARROWS_OUT, CARET_DOWN, MOON, SUN, X};
|
||||
use crate::gui::platform::PlatformCallbacks;
|
||||
use crate::gui::views::{Content, Modal, TitlePanel, View};
|
||||
use crate::gui::views::{Content, KeyboardContent, 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.
|
||||
static ref BACK_BUTTON_PRESSED: AtomicBool = AtomicBool::new(false);
|
||||
}
|
||||
|
||||
/// Implements ui entry point and contains platform-specific callbacks.
|
||||
pub struct App<Platform> {
|
||||
/// Handles platform-specific functionality.
|
||||
@@ -75,14 +68,10 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||
}
|
||||
|
||||
// Handle Esc keyboard key event.
|
||||
let back_pressed = BACK_BUTTON_PRESSED.load(Ordering::Relaxed);
|
||||
if back_pressed || ctx.input_mut(|i| i.consume_key(Modifiers::NONE, egui::Key::Escape)) {
|
||||
if ctx.input_mut(|i| i.consume_key(Modifiers::NONE, egui::Key::Escape)) {
|
||||
if Modal::on_back() {
|
||||
self.content.on_back(&self.platform);
|
||||
}
|
||||
if back_pressed {
|
||||
BACK_BUTTON_PRESSED.store(false, Ordering::Relaxed);
|
||||
}
|
||||
// Request repaint to update previous content.
|
||||
ctx.request_repaint();
|
||||
}
|
||||
@@ -147,6 +136,17 @@ impl<Platform: PlatformCallbacks> App<Platform> {
|
||||
ctx.input(|i| i.viewport().focused.unwrap_or(true)) {
|
||||
self.platform.clear_user_attention();
|
||||
}
|
||||
|
||||
// Show modal or keyboard window above others.
|
||||
ctx.move_to_top(LayerId::new(Order::Middle, egui::Id::new(Modal::WINDOW_ID)));
|
||||
let keyboard_showing = if let Some(l) = ctx.top_layer_id() {
|
||||
l.id == egui::Id::new(KeyboardContent::WINDOW_ID)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
if keyboard_showing {
|
||||
ctx.move_to_top(LayerId::new(Order::Middle, egui::Id::new(KeyboardContent::WINDOW_ID)));
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw custom desktop window frame content.
|
||||
|
||||
+6
-16
@@ -14,14 +14,14 @@
|
||||
|
||||
use egui::epaint::{RectShape, Shadow};
|
||||
use egui::os::OperatingSystem;
|
||||
use egui::{Align2, CornerRadius, Order, RichText, Stroke, StrokeKind, UiBuilder, Vec2};
|
||||
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! {
|
||||
@@ -49,6 +49,8 @@ impl Modal {
|
||||
const DEFAULT_MARGIN: f32 = 8.0;
|
||||
/// Maximum width of the content.
|
||||
const DEFAULT_WIDTH: f32 = Content::SIDE_PANEL_WIDTH - (2.0 * Self::DEFAULT_MARGIN);
|
||||
/// Modal content [`egui::Window`] id.
|
||||
pub const WINDOW_ID: &'static str = "modal_window";
|
||||
|
||||
/// Create closeable [`Modal`] with center position.
|
||||
pub fn new(id: &'static str) -> Self {
|
||||
@@ -226,7 +228,7 @@ impl Modal {
|
||||
|
||||
// Show main content window at given position.
|
||||
let (content_align, content_offset) = self.modal_position();
|
||||
let res = egui::Window::new("modal_window")
|
||||
egui::Window::new(Self::WINDOW_ID)
|
||||
.title_bar(false)
|
||||
.resizable(false)
|
||||
.collapsible(false)
|
||||
@@ -248,19 +250,7 @@ impl Modal {
|
||||
title_ui(title, ui);
|
||||
}
|
||||
self.content_ui(ui, add_content);
|
||||
|
||||
}).unwrap().response;
|
||||
|
||||
// Show modal or keyboard window above others.
|
||||
ctx.move_to_top(res.layer_id);
|
||||
let keyboard_showing = if let Some(l) = ctx.top_layer_id() {
|
||||
l.id == egui::Id::new(KeyboardContent::WINDOW_ID)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
if keyboard_showing {
|
||||
ctx.move_to_top(egui::LayerId::new(Order::Middle, egui::Id::new(KeyboardContent::WINDOW_ID)))
|
||||
}
|
||||
});
|
||||
|
||||
// Setup first draw flag.
|
||||
if Self::first_draw() {
|
||||
|
||||
Reference in New Issue
Block a user