From 0621154902da31ccc4281974df178ac681640bb2 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Fri, 30 May 2025 22:11:16 +0300 Subject: [PATCH] ui: remove on_back callback from content container --- src/gui/views/content.rs | 57 ++++++------- src/gui/views/network/connections.rs | 4 - src/gui/views/network/settings.rs | 4 - src/gui/views/network/setup/dandelion.rs | 4 - src/gui/views/network/setup/node.rs | 4 - src/gui/views/network/setup/p2p.rs | 4 - src/gui/views/network/setup/pool.rs | 4 - src/gui/views/network/setup/stratum.rs | 4 - src/gui/views/settings/content.rs | 4 - src/gui/views/types.rs | 2 - src/gui/views/wallets/content.rs | 83 +++++++++---------- src/gui/views/wallets/creation/content.rs | 5 +- src/gui/views/wallets/creation/mnemonic.rs | 49 +++++------ src/gui/views/wallets/wallet/content.rs | 9 +- .../wallets/wallet/settings/connection.rs | 4 - 15 files changed, 91 insertions(+), 150 deletions(-) diff --git a/src/gui/views/content.rs b/src/gui/views/content.rs index 02e5eee3..f157b21e 100644 --- a/src/gui/views/content.rs +++ b/src/gui/views/content.rs @@ -88,33 +88,7 @@ impl ContentContainer for Content { } } - fn on_back(&mut self, cb: &dyn PlatformCallbacks) -> bool { - if Modal::on_back() { - if self.wallets.on_back(cb) { - Self::show_exit_modal(); - return false; - } - } - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) { - self.content_ui(ui, cb); - } -} - -impl Content { - /// Default width of side panel at application UI. - pub const SIDE_PANEL_WIDTH: f32 = 400.0; - /// Desktop window title height. - pub const WINDOW_TITLE_HEIGHT: f32 = 38.0; - /// Margin of window frame at desktop. - pub const WINDOW_FRAME_MARGIN: f32 = 6.0; - - /// Identifier for exit confirmation [`Modal`]. - pub const EXIT_CONFIRMATION_MODAL: &'static str = "exit_confirmation_modal"; - - fn content_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) { let dual_panel = Self::is_dual_panel_mode(ui.ctx()); let (is_panel_open, mut panel_width) = network_panel_state_width(ui.ctx(), dual_panel); if self.network.showing_settings() { @@ -150,14 +124,37 @@ impl Content { .title(t!("crash_report")) .show(); } else if OperatingSystem::from_target_os() == OperatingSystem::Android && - AppConfig::android_integrated_node_warning_needed() { - Modal::new(ANDROID_INTEGRATED_NODE_WARNING_MODAL) - .title(t!("network.node")) - .show(); + AppConfig::android_integrated_node_warning_needed() { + Modal::new(ANDROID_INTEGRATED_NODE_WARNING_MODAL) + .title(t!("network.node")) + .show(); } self.first_draw = false; } } +} + +impl Content { + /// Default width of side panel at application UI. + pub const SIDE_PANEL_WIDTH: f32 = 400.0; + /// Desktop window title height. + pub const WINDOW_TITLE_HEIGHT: f32 = 38.0; + /// Margin of window frame at desktop. + pub const WINDOW_FRAME_MARGIN: f32 = 6.0; + + /// Identifier for exit confirmation [`Modal`]. + pub const EXIT_CONFIRMATION_MODAL: &'static str = "exit_confirmation_modal"; + + /// Called to navigate back, return `true` if action was not consumed. + pub fn on_back(&mut self, cb: &dyn PlatformCallbacks) -> bool { + if Modal::on_back() { + if self.wallets.on_back(cb) { + Self::show_exit_modal(); + return false; + } + } + true + } /// Check if ui can show [`NetworkContent`] and [`WalletsContent`] at same time. pub fn is_dual_panel_mode(ctx: &egui::Context) -> bool { diff --git a/src/gui/views/network/connections.rs b/src/gui/views/network/connections.rs index 82fc9bdf..9a48694c 100644 --- a/src/gui/views/network/connections.rs +++ b/src/gui/views/network/connections.rs @@ -58,10 +58,6 @@ impl ContentContainer for ConnectionsContent { } } - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, _: &dyn PlatformCallbacks) { ui.add_space(2.0); diff --git a/src/gui/views/network/settings.rs b/src/gui/views/network/settings.rs index 7fa83cde..8a89ff7d 100644 --- a/src/gui/views/network/settings.rs +++ b/src/gui/views/network/settings.rs @@ -70,10 +70,6 @@ impl ContentContainer for NetworkSettings { } } - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) { ScrollArea::vertical() .id_salt("node_settings_scroll") diff --git a/src/gui/views/network/setup/dandelion.rs b/src/gui/views/network/setup/dandelion.rs index 24c608b8..e66f2636 100644 --- a/src/gui/views/network/setup/dandelion.rs +++ b/src/gui/views/network/setup/dandelion.rs @@ -80,10 +80,6 @@ impl ContentContainer for DandelionSetup { } } - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, _: &dyn PlatformCallbacks) { View::sub_title(ui, format!("{} {}", GRAPH, "Dandelion")); View::horizontal_line(ui, Colors::stroke()); diff --git a/src/gui/views/network/setup/node.rs b/src/gui/views/network/setup/node.rs index b7735d19..a2e61713 100644 --- a/src/gui/views/network/setup/node.rs +++ b/src/gui/views/network/setup/node.rs @@ -92,10 +92,6 @@ impl ContentContainer for NodeSetup { } } - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, _: &dyn PlatformCallbacks) { View::sub_title(ui, format!("{} {}", COMPUTER_TOWER, t!("network_settings.server"))); View::horizontal_line(ui, Colors::stroke()); diff --git a/src/gui/views/network/setup/p2p.rs b/src/gui/views/network/setup/p2p.rs index 01a3c536..638838cc 100644 --- a/src/gui/views/network/setup/p2p.rs +++ b/src/gui/views/network/setup/p2p.rs @@ -143,10 +143,6 @@ impl ContentContainer for P2PSetup { } } - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, _: &dyn PlatformCallbacks) { View::sub_title(ui, format!("{} {}", HANDSHAKE, t!("network_settings.p2p_server"))); View::horizontal_line(ui, Colors::stroke()); diff --git a/src/gui/views/network/setup/pool.rs b/src/gui/views/network/setup/pool.rs index 4fabcb7a..c791279b 100644 --- a/src/gui/views/network/setup/pool.rs +++ b/src/gui/views/network/setup/pool.rs @@ -84,10 +84,6 @@ impl ContentContainer for PoolSetup { } } - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, _: &dyn PlatformCallbacks) { View::sub_title(ui, format!("{} {}", CHART_SCATTER, t!("network_settings.tx_pool"))); View::horizontal_line(ui, Colors::stroke()); diff --git a/src/gui/views/network/setup/stratum.rs b/src/gui/views/network/setup/stratum.rs index 2c1030c8..ed980f0e 100644 --- a/src/gui/views/network/setup/stratum.rs +++ b/src/gui/views/network/setup/stratum.rs @@ -121,10 +121,6 @@ impl ContentContainer for StratumSetup { } } - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, _: &dyn PlatformCallbacks) { View::sub_title(ui, format!("{} {}", HARD_DRIVES, t!("network_mining.server"))); View::horizontal_line(ui, Colors::stroke()); diff --git a/src/gui/views/settings/content.rs b/src/gui/views/settings/content.rs index 4c3ecc53..700df29d 100644 --- a/src/gui/views/settings/content.rs +++ b/src/gui/views/settings/content.rs @@ -44,10 +44,6 @@ impl ContentContainer for SettingsContent { fn modal_ui(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks) { } - fn on_back(&mut self, cb: &dyn PlatformCallbacks) -> bool { - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) { ui.add_space(6.0); diff --git a/src/gui/views/types.rs b/src/gui/views/types.rs index 809e141a..b55c533c 100644 --- a/src/gui/views/types.rs +++ b/src/gui/views/types.rs @@ -57,8 +57,6 @@ pub trait ContentContainer { fn modal_ids(&self) -> Vec<&'static str>; /// Draw modal content. fn modal_ui(&mut self, ui: &mut egui::Ui, modal: &Modal, cb: &dyn PlatformCallbacks); - /// Handle back key action, return `false` when consumed inside container. - fn on_back(&mut self, cb: &dyn PlatformCallbacks) -> bool; /// Draw container content. fn container_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks); /// Draw content, to call by parent container. diff --git a/src/gui/views/wallets/content.rs b/src/gui/views/wallets/content.rs index cb362a8b..e6a3f830 100644 --- a/src/gui/views/wallets/content.rs +++ b/src/gui/views/wallets/content.rs @@ -127,40 +127,6 @@ impl ContentContainer for WalletsContent { } } - fn on_back(&mut self, cb: &dyn PlatformCallbacks) -> bool { - if self.showing_settings() { - // Close settings. - self.settings_content = None; - return false; - } else if self.creating_wallet() { - // Close wallet creation. - let creation = self.creation_content.as_mut().unwrap(); - if creation.on_back() { - self.creation_content = None; - } - return false; - } else { - if self.showing_wallet() { - let content = self.wallet_content.as_mut().unwrap(); - // Close opened QR code scanner. - if content.qr_scan_showing() { - cb.stop_camera(); - content.close_qr_scan(); - return false; - } - // Close account list. - if content.account_list_showing() { - content.close_qr_scan(); - return false; - } - // Close opened wallet. - self.wallet_content = None; - return false; - } - } - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) { if let Some(data) = crate::consume_incoming_data() { if !data.is_empty() { @@ -319,6 +285,39 @@ impl ContentContainer for WalletsContent { } impl WalletsContent { + /// Called to navigate back, return `true` if action was not consumed. + pub fn on_back(&mut self, cb: &dyn PlatformCallbacks) -> bool { + if self.showing_settings() { + // Close settings. + self.settings_content = None; + return false; + } else if self.creating_wallet() { + // Close wallet creation. + let creation = self.creation_content.as_mut().unwrap(); + if creation.on_back() { + self.creation_content = None; + } + return false; + } else if self.showing_wallet() { + let content = self.wallet_content.as_mut().unwrap(); + // Close opened QR code scanner. + if content.qr_scan_showing() { + cb.stop_camera(); + content.close_qr_scan(); + return false; + } + // Close account list. + if content.account_list_showing() { + content.close_qr_scan(); + return false; + } + // Close opened wallet. + self.wallet_content = None; + return false; + } + true + } + /// Check if opened wallet is showing. pub fn showing_wallet(&self) -> bool { if let Some(wallet_content) = &self.wallet_content { @@ -358,7 +357,11 @@ impl WalletsContent { self.show_opening_modal(w, data); } } else { - self.show_wallet_selection_modal(data); + self.wallet_selection_content = WalletsModal::new(None, data, true); + Modal::new(SELECT_WALLET_MODAL) + .position(ModalPosition::Center) + .title(t!("network_settings.choose_wallet")) + .show(); } } @@ -371,15 +374,6 @@ impl WalletsContent { .show(); } - /// Show wallet selection with provided optional data. - fn show_wallet_selection_modal(&mut self, data: Option) { - self.wallet_selection_content = WalletsModal::new(None, data, true); - Modal::new(SELECT_WALLET_MODAL) - .position(ModalPosition::Center) - .title(t!("network_settings.choose_wallet")) - .show(); - } - /// Draw [`TitlePanel`] content. fn title_ui(&mut self, ui: &mut egui::Ui, @@ -475,6 +469,7 @@ impl WalletsContent { self.wallet_content.as_mut().unwrap().close_account_list(); return; } + self.wallet_content = None; }); } else if self.creating_wallet() { let mut close = false; diff --git a/src/gui/views/wallets/creation/content.rs b/src/gui/views/wallets/creation/content.rs index c0b0d31b..2bea5f56 100644 --- a/src/gui/views/wallets/creation/content.rs +++ b/src/gui/views/wallets/creation/content.rs @@ -86,11 +86,8 @@ impl ContentContainer for WalletCreationContent { } } - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { - true + fn container_ui(&mut self, _: &mut egui::Ui, _: &dyn PlatformCallbacks) { } - - fn container_ui(&mut self, _: &mut egui::Ui, _: &dyn PlatformCallbacks) {} } impl WalletCreationContent { diff --git a/src/gui/views/wallets/creation/mnemonic.rs b/src/gui/views/wallets/creation/mnemonic.rs index 02039f9a..0682a5d4 100644 --- a/src/gui/views/wallets/creation/mnemonic.rs +++ b/src/gui/views/wallets/creation/mnemonic.rs @@ -66,10 +66,6 @@ impl ContentContainer for MnemonicSetup { } } - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { - true - } - fn container_ui(&mut self, _: &mut egui::Ui, _: &dyn PlatformCallbacks) { } } @@ -78,34 +74,8 @@ impl MnemonicSetup { /// Draw content for phrase import step. pub fn import_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) { self.ui(ui, cb); - ui.add_space(10.0); - // Show mode and type setup. - self.mode_type_ui(ui); - - ui.add_space(12.0); - View::horizontal_line(ui, Colors::item_stroke()); - ui.add_space(6.0); - - // Show words setup. - self.word_list_ui(ui, true); - } - /// Draw content for phrase confirmation step. - pub fn confirm_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) { - self.ui(ui, cb); - - ui.add_space(4.0); - ui.vertical_centered(|ui| { - let text = format!("{}:", t!("wallets.recovery_phrase")); - ui.label(RichText::new(text).size(16.0).color(Colors::gray())); - }); - ui.add_space(4.0); - self.word_list_ui(ui, true); - } - - /// Draw mode and size setup. - fn mode_type_ui(&mut self, ui: &mut egui::Ui) { // Show mode setup. let mut mode = self.mnemonic.mode(); ui.columns(2, |columns| { @@ -146,6 +116,25 @@ impl MnemonicSetup { if size != self.mnemonic.size() { self.mnemonic.set_size(size); } + + ui.add_space(12.0); + View::horizontal_line(ui, Colors::item_stroke()); + ui.add_space(6.0); + + // Show words setup. + self.word_list_ui(ui, true); + } + /// Draw content for phrase confirmation step. + pub fn confirm_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) { + self.ui(ui, cb); + + ui.add_space(4.0); + ui.vertical_centered(|ui| { + let text = format!("{}:", t!("wallets.recovery_phrase")); + ui.label(RichText::new(text).size(16.0).color(Colors::gray())); + }); + ui.add_space(4.0); + self.word_list_ui(ui, true); } /// Draw grid of words for mnemonic phrase. diff --git a/src/gui/views/wallets/wallet/content.rs b/src/gui/views/wallets/wallet/content.rs index d3ad2c41..283c8dc6 100644 --- a/src/gui/views/wallets/wallet/content.rs +++ b/src/gui/views/wallets/wallet/content.rs @@ -44,11 +44,12 @@ pub struct WalletContent { } impl ContentContainer for WalletContent { - fn modal_ids(&self) -> Vec<&'static str> { vec![] } + fn modal_ids(&self) -> Vec<&'static str> { + vec![] + } - fn modal_ui(&mut self, _: &mut egui::Ui, _: &Modal, _: &dyn PlatformCallbacks) {} - - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { true } + fn modal_ui(&mut self, _: &mut egui::Ui, _: &Modal, _: &dyn PlatformCallbacks) { + } fn container_ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks) { ui.ctx().request_repaint_after(Duration::from_millis(1000)); diff --git a/src/gui/views/wallets/wallet/settings/connection.rs b/src/gui/views/wallets/wallet/settings/connection.rs index c0e83b56..9840d923 100644 --- a/src/gui/views/wallets/wallet/settings/connection.rs +++ b/src/gui/views/wallets/wallet/settings/connection.rs @@ -61,10 +61,6 @@ impl ContentContainer for ConnectionSettings { } } - fn on_back(&mut self, _: &dyn PlatformCallbacks) -> bool { - true - } - fn container_ui(&mut self, ui: &mut egui::Ui, _: &dyn PlatformCallbacks) { ui.add_space(2.0); View::sub_title(ui, format!("{} {}", GLOBE, t!("wallets.conn_method")));