From af191831e668828f13bb98ac926eadff8abb87f4 Mon Sep 17 00:00:00 2001 From: ardocrat Date: Thu, 30 May 2024 00:07:13 +0300 Subject: [PATCH] qr: fix scan on black theme --- locales/en.yml | 2 +- locales/ru.yml | 2 +- locales/tr.yml | 2 +- src/gui/colors.rs | 2 +- src/gui/views/qr.rs | 78 ++++++++++++++++++++++++++++----------------- 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/locales/en.yml b/locales/en.yml index ff7a2e3..17f5544 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -22,7 +22,7 @@ repeat: Repeat scan_result: Scan result back: Back share: Share -theme: Theme +theme: 'Theme:' dark: Dark light: Light wallets: diff --git a/locales/ru.yml b/locales/ru.yml index 6598540..228fb48 100644 --- a/locales/ru.yml +++ b/locales/ru.yml @@ -22,7 +22,7 @@ repeat: Повторить scan_result: Результат сканирования back: Назад share: Поделиться -theme: Тема +theme: 'Тема:' dark: Тёмная light: Светлая wallets: diff --git a/locales/tr.yml b/locales/tr.yml index dedb615..9ec1d37 100644 --- a/locales/tr.yml +++ b/locales/tr.yml @@ -22,7 +22,7 @@ repeat: Tekrar scan_result: Tarama sonucu back: Geri share: Paylasmak -theme: Tema +theme: 'Tema:' dark: Karanlik light: Isik wallets: diff --git a/src/gui/colors.rs b/src/gui/colors.rs index eab2b1d..f7cc67b 100644 --- a/src/gui/colors.rs +++ b/src/gui/colors.rs @@ -109,7 +109,7 @@ impl Colors { pub fn gold() -> Color32 { if use_dark() { - GOLD.linear_multiply(0.85) + GOLD.linear_multiply(0.9) } else { GOLD } diff --git a/src/gui/views/qr.rs b/src/gui/views/qr.rs index 5512421..e8f5f4f 100644 --- a/src/gui/views/qr.rs +++ b/src/gui/views/qr.rs @@ -73,6 +73,52 @@ impl QrCodeContent { } } + /// Draw QR code image content. + fn qr_image_ui(&mut self, svg: Vec, ui: &mut egui::Ui) { + let mut rect = ui.available_rect_before_wrap(); + rect.min += egui::emath::vec2(5.0, 0.0); + rect.max -= egui::emath::vec2(5.0, 0.0); + + // Create background shape. + let mut bg_shape = egui::epaint::RectShape { + rect, + rounding: egui::Rounding::same(3.0), + fill: egui::Color32::WHITE, + stroke: egui::Stroke::NONE, + fill_texture_id: Default::default(), + uv: egui::Rect::ZERO + }; + let bg_idx = ui.painter().add(bg_shape); + + // Draw QR code image content. + let mut content_rect = ui.allocate_ui_at_rect(rect, |ui| { + let size = SizeHint::Size(ui.available_width() as u32, ui.available_width() as u32); + let color_img = load_svg_bytes_with_size(svg.as_slice(), Some(size)).unwrap(); + // Create image texture. + let texture_handle = ui.ctx().load_texture("qr_code", + color_img.clone(), + TextureOptions::default()); + self.texture_handle = Some(texture_handle.clone()); + let img_size = egui::emath::vec2(color_img.width() as f32, + color_img.height() as f32); + let sized_img = SizedTexture::new(texture_handle.id(), img_size); + // Add image to content. + ui.add_space(5.0); + ui.add(egui::Image::from_texture(sized_img) + .max_height(ui.available_width()) + .fit_to_original_size(1.0)); + ui.add_space(5.0); + }).response.rect; + + // Setup background shape to be painted behind main content. + content_rect.min -= egui::emath::vec2(5.0, 0.0); + content_rect.max += egui::emath::vec2(5.0, 0.0); + bg_shape.rect = content_rect; + ui.painter().set(bg_idx, bg_shape); + + ui.add_space(6.0); + } + /// Draw animated QR code content. fn animated_ui(&mut self, ui: &mut egui::Ui, text: String, cb: &dyn PlatformCallbacks) { if !self.has_image() { @@ -108,21 +154,7 @@ impl QrCodeContent { let svg = svg_list[self.animated_index.unwrap_or(0)].clone(); // Create images from SVG data. - let size = SizeHint::Size(ui.available_width() as u32, ui.available_width() as u32); - let color_img = load_svg_bytes_with_size(svg.as_slice(), Some(size)).unwrap(); - // Create image texture. - let texture_handle = ui.ctx().load_texture("qr_code", - color_img.clone(), - TextureOptions::default()); - self.texture_handle = Some(texture_handle.clone()); - let img_size = egui::emath::vec2(color_img.width() as f32, - color_img.height() as f32); - let sized_img = SizedTexture::new(texture_handle.id(), img_size); - // Add image to content. - ui.add(egui::Image::from_texture(sized_img) - .max_height(ui.available_width()) - .fit_to_original_size(1.0)); - ui.add_space(10.0); + self.qr_image_ui(svg, ui); ui.vertical_centered(|ui| { let sharing = { @@ -194,21 +226,7 @@ impl QrCodeContent { let r_state = self.qr_image_state.read(); r_state.svg.clone().unwrap() }; - let size = SizeHint::Size(ui.available_width() as u32, ui.available_width() as u32); - let color_img = load_svg_bytes_with_size(svg.as_slice(), Some(size)).unwrap(); - // Create image texture. - let texture_handle = ui.ctx().load_texture("qr_code", - color_img.clone(), - TextureOptions::default()); - self.texture_handle = Some(texture_handle.clone()); - let img_size = egui::emath::vec2(color_img.width() as f32, - color_img.height() as f32); - let sized_img = SizedTexture::new(texture_handle.id(), img_size); - // Add image to content. - ui.add(egui::Image::from_texture(sized_img) - .max_height(ui.available_width()) - .fit_to_original_size(1.0)); - ui.add_space(6.0); + self.qr_image_ui(svg, ui); // Show QR code text. View::ellipsize_text(ui, text.clone(), 16.0, Colors::inactive_text());