qr: fix scan on black theme

This commit is contained in:
ardocrat 2024-05-30 00:07:13 +03:00
parent b5ef950fb9
commit af191831e6
5 changed files with 52 additions and 34 deletions

View file

@ -22,7 +22,7 @@ repeat: Repeat
scan_result: Scan result scan_result: Scan result
back: Back back: Back
share: Share share: Share
theme: Theme theme: 'Theme:'
dark: Dark dark: Dark
light: Light light: Light
wallets: wallets:

View file

@ -22,7 +22,7 @@ repeat: Повторить
scan_result: Результат сканирования scan_result: Результат сканирования
back: Назад back: Назад
share: Поделиться share: Поделиться
theme: Тема theme: 'Тема:'
dark: Тёмная dark: Тёмная
light: Светлая light: Светлая
wallets: wallets:

View file

@ -22,7 +22,7 @@ repeat: Tekrar
scan_result: Tarama sonucu scan_result: Tarama sonucu
back: Geri back: Geri
share: Paylasmak share: Paylasmak
theme: Tema theme: 'Tema:'
dark: Karanlik dark: Karanlik
light: Isik light: Isik
wallets: wallets:

View file

@ -109,7 +109,7 @@ impl Colors {
pub fn gold() -> Color32 { pub fn gold() -> Color32 {
if use_dark() { if use_dark() {
GOLD.linear_multiply(0.85) GOLD.linear_multiply(0.9)
} else { } else {
GOLD GOLD
} }

View file

@ -73,6 +73,52 @@ impl QrCodeContent {
} }
} }
/// Draw QR code image content.
fn qr_image_ui(&mut self, svg: Vec<u8>, 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. /// Draw animated QR code content.
fn animated_ui(&mut self, ui: &mut egui::Ui, text: String, cb: &dyn PlatformCallbacks) { fn animated_ui(&mut self, ui: &mut egui::Ui, text: String, cb: &dyn PlatformCallbacks) {
if !self.has_image() { if !self.has_image() {
@ -108,21 +154,7 @@ impl QrCodeContent {
let svg = svg_list[self.animated_index.unwrap_or(0)].clone(); let svg = svg_list[self.animated_index.unwrap_or(0)].clone();
// Create images from SVG data. // Create images from SVG data.
let size = SizeHint::Size(ui.available_width() as u32, ui.available_width() as u32); self.qr_image_ui(svg, ui);
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);
ui.vertical_centered(|ui| { ui.vertical_centered(|ui| {
let sharing = { let sharing = {
@ -194,21 +226,7 @@ impl QrCodeContent {
let r_state = self.qr_image_state.read(); let r_state = self.qr_image_state.read();
r_state.svg.clone().unwrap() r_state.svg.clone().unwrap()
}; };
let size = SizeHint::Size(ui.available_width() as u32, ui.available_width() as u32); self.qr_image_ui(svg, ui);
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);
// Show QR code text. // Show QR code text.
View::ellipsize_text(ui, text.clone(), 16.0, Colors::inactive_text()); View::ellipsize_text(ui, text.clone(), 16.0, Colors::inactive_text());