ui: remove on_back callback from content container

This commit is contained in:
ardocrat
2025-05-30 22:11:16 +03:00
parent acfb5fec1a
commit 0621154902
15 changed files with 91 additions and 150 deletions
+27 -30
View File
@@ -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 {
-4
View File
@@ -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);
-4
View File
@@ -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")
-4
View File
@@ -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());
-4
View File
@@ -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());
-4
View File
@@ -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());
-4
View File
@@ -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());
-4
View File
@@ -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());
-4
View File
@@ -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);
-2
View File
@@ -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.
+39 -44
View File
@@ -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<String>) {
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;
+1 -4
View File
@@ -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 {
+19 -30
View File
@@ -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.
+5 -4
View File
@@ -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));
@@ -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")));