From 7f65471ba11a0f77030cfbefb3301d1ccbd46518 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Thu, 6 Nov 2025 14:01:40 +0300 Subject: [PATCH] ui: fix wallet tabs state --- src/gui/views/file_pick.rs | 28 ++++++++++++++++++------- src/gui/views/views.rs | 6 +++--- src/gui/views/wallets/wallet/content.rs | 13 +++++------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/gui/views/file_pick.rs b/src/gui/views/file_pick.rs index b974d368..2c767d11 100644 --- a/src/gui/views/file_pick.rs +++ b/src/gui/views/file_pick.rs @@ -33,6 +33,9 @@ pub struct FilePickContent { /// Content type. content_type: FilePickContentType, + /// Flag to check if button is active. + active: bool, + /// Flag to check if file is picking. file_picking: Arc, @@ -49,6 +52,7 @@ impl FilePickContent { pub fn new(content_type: FilePickContentType) -> Self { Self { content_type, + active: false, file_picking: Arc::new(AtomicBool::new(false)), parse_file: true, file_parsing: Arc::new(AtomicBool::new(false)), @@ -62,8 +66,13 @@ impl FilePickContent { self } + /// Enable or disable the button. + pub fn set_active(&mut self, active: bool) { + self.active = active; + } + /// Draw content with provided callback to return path of the file. - pub fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks, on_pick: impl FnOnce(String)) { + pub fn ui(&mut self, ui: &mut egui::Ui, cb: &dyn PlatformCallbacks, pick: impl FnOnce(String)) { if self.file_picking.load(Ordering::Relaxed) { View::small_loading_spinner(ui); // Check file pick result. @@ -86,7 +95,7 @@ impl FilePickContent { r_res.clone().unwrap() }; // Callback on result. - on_pick(text); + pick(text); // Clear result. let mut w_res = self.file_parsing_result.write(); *w_res = None; @@ -104,7 +113,7 @@ impl FilePickContent { || { if let Some(path) = cb.pick_file() { if !self.parse_file { - on_pick(path); + pick(path); return; } self.on_file_pick(path); @@ -115,7 +124,7 @@ impl FilePickContent { View::item_button(ui, r, ARCHIVE_BOX, Some(Colors::blue()), || { if let Some(path) = cb.pick_file() { if !self.parse_file { - on_pick(path); + pick(path); return; } self.on_file_pick(path); @@ -123,12 +132,15 @@ impl FilePickContent { }); } FilePickContentType::Tab => { - let active = self.file_parsing.load(Ordering::Relaxed) || - self.file_picking.load(Ordering::Relaxed); - View::tab_button(ui, ARCHIVE_BOX, Some(Colors::blue()), Some(active), |_| { + let active = match self.active { + true => Some(self.file_parsing.load(Ordering::Relaxed) || + self.file_picking.load(Ordering::Relaxed)), + false => None + }; + View::tab_button(ui, ARCHIVE_BOX, Some(Colors::blue()), active, |_| { if let Some(path) = cb.pick_file() { if !self.parse_file { - on_pick(path); + pick(path); return; } self.on_file_pick(path); diff --git a/src/gui/views/views.rs b/src/gui/views/views.rs index 6dc48204..b6f9156b 100644 --- a/src/gui/views/views.rs +++ b/src/gui/views/views.rs @@ -203,7 +203,7 @@ impl View { ui.scope(|ui| { let text_color = if let Some(c) = color { if selected.is_none() { - Colors::inactive_text().gamma_multiply(1.2) + Colors::inactive_text() } else { c } @@ -214,7 +214,7 @@ impl View { false => Colors::item_button_text() } } else { - Colors::inactive_text().gamma_multiply(1.2) + Colors::inactive_text() } }; @@ -245,7 +245,7 @@ impl View { }; br.surrender_focus(); - if br.clicked() { + if br.clicked() && active_not_selected { action(ui); } }); diff --git a/src/gui/views/wallets/wallet/content.rs b/src/gui/views/wallets/wallet/content.rs index ae0ac045..5143ba5d 100644 --- a/src/gui/views/wallets/wallet/content.rs +++ b/src/gui/views/wallets/wallet/content.rs @@ -357,17 +357,14 @@ impl WalletContent { self.current_tab = Box::new(WalletTransactions::new(None)); }); }); + let active = if has_wallet_data { Some(false) } else { None }; columns[1].vertical_centered_justified(|ui| { if wallet.invoice_creating() { ui.add_space(4.0); View::small_loading_spinner(ui); } else { - let active = if has_wallet_data { - Some(false) - } else { - None - }; - View::tab_button(ui, FILE_ARROW_DOWN, Some(Colors::green()), active, |_| { + let (icon, color) = (FILE_ARROW_DOWN, Some(Colors::green())); + View::tab_button(ui, icon, color, active, |_| { self.invoice_request_content = Some(InvoiceRequestContent::default()); Modal::new(INVOICE_MODAL_ID) .position(ModalPosition::CenterTop) @@ -381,6 +378,7 @@ impl WalletContent { ui.add_space(4.0); View::small_loading_spinner(ui); } else { + self.file_pick_tab_button.set_active(active.is_some()); self.file_pick_tab_button.ui(ui, cb, |m| { wallet.task(WalletTask::OpenMessage(m)); }); @@ -403,8 +401,7 @@ impl WalletContent { } }); } - let settings_index = if tabs_amount == 5 { 4 } else { 3 }; - columns[settings_index].vertical_centered_justified(|ui| { + columns[tabs_amount - 1].vertical_centered_justified(|ui| { let active = Some(current_type == WalletTabType::Settings); View::tab_button(ui, GEAR_FINE, None, active, |ui| { ExternalConnection::check(None, ui.ctx());