ui: fix wallet tabs state

This commit is contained in:
ardocrat
2025-11-06 14:01:40 +03:00
parent fabd0a90df
commit 7f65471ba1
3 changed files with 28 additions and 19 deletions
+20 -8
View File
@@ -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<AtomicBool>,
@@ -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);
+3 -3
View File
@@ -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);
}
});
+5 -8
View File
@@ -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());