diff --git a/src/gui/colors.rs b/src/gui/colors.rs index 9f1cb3a2..10147988 100644 --- a/src/gui/colors.rs +++ b/src/gui/colors.rs @@ -44,7 +44,6 @@ const BLUE_DARK: Color32 = const FILL: Color32 = Color32::from_gray(244); const FILL_DARK: Color32 = Color32::from_gray(26); -const FILL_DEEP: Color32 = Color32::from_gray(238); const FILL_DEEP_DARK: Color32 = Color32::from_gray(32); const FILL_LITE: Color32 = Color32::from_gray(249); @@ -85,6 +84,7 @@ fn use_dark() -> bool { } impl Colors { + pub const FILL_DEEP: Color32 = Color32::from_gray(238); pub const TRANSPARENT: Color32 = Color32::from_rgba_premultiplied(0, 0, 0, 0); pub const STROKE: Color32 = Color32::from_gray(200); @@ -172,7 +172,7 @@ impl Colors { if use_dark() { FILL_DEEP_DARK } else { - FILL_DEEP + Self::FILL_DEEP } } diff --git a/src/gui/views/modal.rs b/src/gui/views/modal.rs index 1cab0609..478471a4 100755 --- a/src/gui/views/modal.rs +++ b/src/gui/views/modal.rs @@ -14,7 +14,7 @@ use egui::epaint::{RectShape, Shadow}; use egui::os::OperatingSystem; -use egui::{Align2, CornerRadius, RichText, Stroke, StrokeKind, UiBuilder, Vec2}; +use egui::{Align2, Color32, CornerRadius, RichText, Stroke, StrokeKind, UiBuilder, Vec2}; use lazy_static::lazy_static; use parking_lot::RwLock; use std::sync::atomic::{AtomicBool, Ordering}; @@ -43,6 +43,8 @@ pub struct Modal { title: Option, /// Flag to check first content render. first_draw: Arc, + /// Background color. + fill: Color32, } impl Modal { @@ -61,6 +63,7 @@ impl Modal { closeable: Arc::new(AtomicBool::new(true)), title: None, first_draw: Arc::new(AtomicBool::new(true)), + fill: Colors::fill(), } } @@ -295,6 +298,12 @@ impl Modal { (align, offset) } + /// Set custom background color. + pub fn set_background_color(&self, color: Color32) { + let mut w_state = MODAL_STATE.write(); + w_state.modal.as_mut().unwrap().fill = color; + } + /// Draw provided content. fn content_ui(&self, ui: &mut egui::Ui, @@ -312,7 +321,7 @@ impl Modal { sw: 8.0 as u8, se: 8.0 as u8, } - }, Colors::fill(), Stroke::NONE, StrokeKind::Outside); + }, self.fill, Stroke::NONE, StrokeKind::Outside); let bg_idx = ui.painter().add(bg_shape.clone()); rect.min += egui::emath::vec2(6.0, 0.0); diff --git a/src/gui/views/wallets/wallet/account/content.rs b/src/gui/views/wallets/wallet/account/content.rs index 2698cd9f..1e8cdb43 100644 --- a/src/gui/views/wallets/wallet/account/content.rs +++ b/src/gui/views/wallets/wallet/account/content.rs @@ -311,14 +311,14 @@ impl WalletAccountContent { match result { QrScanResult::Address(a) => { if let Some(data) = wallet.get_data() { - //if data.info.amount_currently_spendable > 0 { + if data.info.amount_currently_spendable > 0 { let address = Some(a.to_string()); self.send_content = Some(SendRequestContent::new(address)); Modal::new(SEND_MODAL_ID) .position(ModalPosition::CenterTop) .title(t!("wallets.send")) .show(); - //} + } } } QrScanResult::Slatepack(m) => { diff --git a/src/gui/views/wallets/wallet/content.rs b/src/gui/views/wallets/wallet/content.rs index 83295295..54ac5a50 100644 --- a/src/gui/views/wallets/wallet/content.rs +++ b/src/gui/views/wallets/wallet/content.rs @@ -208,7 +208,11 @@ impl WalletContentContainer for WalletContent { bottom: 1.0 as i8, }, fill: if top_panel_expanded { - Colors::fill_lite() + if self.transport_content.qr_address_content.is_some() { + Colors::FILL_DEEP + } else { + Colors::fill_lite() + } } else { Colors::TRANSPARENT }, diff --git a/src/gui/views/wallets/wallet/transport/content.rs b/src/gui/views/wallets/wallet/transport/content.rs index 442e0e14..35c531bc 100644 --- a/src/gui/views/wallets/wallet/transport/content.rs +++ b/src/gui/views/wallets/wallet/transport/content.rs @@ -14,6 +14,7 @@ use egui::{Align, CornerRadius, Layout, RichText, StrokeKind}; +use crate::AppConfig; use crate::gui::icons::{CIRCLE_HALF, DOTS_THREE_CIRCLE, PLUGS, PLUGS_CONNECTED, POWER, QR_CODE, SHIELD_CHECKERED, SHIELD_SLASH, WARNING_CIRCLE, WRENCH}; use crate::gui::platform::PlatformCallbacks; use crate::gui::views::wallets::wallet::transport::settings::WalletTransportSettingsContent; @@ -40,6 +41,10 @@ impl WalletContentContainer for WalletTransportContent { fn container_ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) { if let Some(content) = self.qr_address_content.as_mut() { + let dark_theme = AppConfig::dark_theme().unwrap_or(false); + // Set light theme for better scanning. + AppConfig::set_dark_theme(false); + crate::setup_visuals(ui.ctx()); // Draw QR code content. ui.add_space(6.0); content.ui(ui, cb); @@ -49,6 +54,9 @@ impl WalletContentContainer for WalletTransportContent { }); }); ui.add_space(6.0); + // Set color theme back. + AppConfig::set_dark_theme(dark_theme); + crate::setup_visuals(ui.ctx()); } else if let Some(content) = self.settings_content.as_mut() { let mut closed = false; content.ui(ui, wallet, cb, || { diff --git a/src/gui/views/wallets/wallet/txs/content.rs b/src/gui/views/wallets/wallet/txs/content.rs index 1ac52a99..f4d5d938 100644 --- a/src/gui/views/wallets/wallet/txs/content.rs +++ b/src/gui/views/wallets/wallet/txs/content.rs @@ -52,7 +52,7 @@ impl WalletContentContainer for WalletTransactionsContent { match m.id { TX_INFO_MODAL => { if let Some(content) = self.tx_info_content.as_mut() { - content.ui(ui, w, cb); + content.ui(ui, m, w, cb); } } CANCEL_TX_CONFIRMATION_MODAL => { diff --git a/src/gui/views/wallets/wallet/txs/tx.rs b/src/gui/views/wallets/wallet/txs/tx.rs index f2988b1c..476b5499 100644 --- a/src/gui/views/wallets/wallet/txs/tx.rs +++ b/src/gui/views/wallets/wallet/txs/tx.rs @@ -19,6 +19,7 @@ use grin_util::ToHex; use grin_wallet_libwallet::TxLogEntryType; use std::fs; +use crate::AppConfig; use crate::gui::icons::{CIRCLE_HALF, COPY, CUBE, FILE_ARCHIVE, FILE_TEXT, HASH_STRAIGHT, PROHIBIT, QR_CODE, SEAL_CHECK}; use crate::gui::platform::PlatformCallbacks; use crate::gui::views::wallets::wallet::proof::PaymentProofContent; @@ -54,7 +55,11 @@ impl WalletTransactionContent { } /// Draw [`Modal`] content. - pub fn ui(&mut self, ui: &mut egui::Ui, wallet: &Wallet, cb: &dyn PlatformCallbacks) { + pub fn ui(&mut self, + ui: &mut egui::Ui, + modal: &Modal, + wallet: &Wallet, + cb: &dyn PlatformCallbacks) { // Check values and setup transaction data. let wallet_data = wallet.get_data(); if wallet_data.is_none() { @@ -73,6 +78,12 @@ impl WalletTransactionContent { let tx = txs.get(0).unwrap(); if let Some(content) = self.qr_code_content.as_mut() { + let dark_theme = AppConfig::dark_theme().unwrap_or(false); + // Set light theme for better scanning. + AppConfig::set_dark_theme(false); + crate::setup_visuals(ui.ctx()); + modal.set_background_color(Colors::FILL_DEEP); + ui.add_space(6.0); content.ui(ui, cb); @@ -93,7 +104,11 @@ impl WalletTransactionContent { }); }); }); + // Set color theme back. + AppConfig::set_dark_theme(dark_theme); + crate::setup_visuals(ui.ctx()); } else { + modal.set_background_color(Colors::fill()); // Show transaction information. self.info_ui(ui, tx, wallet, cb);