qr: fix scan on black theme
This commit is contained in:
parent
b5ef950fb9
commit
af191831e6
5 changed files with 52 additions and 34 deletions
|
@ -22,7 +22,7 @@ repeat: Repeat
|
|||
scan_result: Scan result
|
||||
back: Back
|
||||
share: Share
|
||||
theme: Theme
|
||||
theme: 'Theme:'
|
||||
dark: Dark
|
||||
light: Light
|
||||
wallets:
|
||||
|
|
|
@ -22,7 +22,7 @@ repeat: Повторить
|
|||
scan_result: Результат сканирования
|
||||
back: Назад
|
||||
share: Поделиться
|
||||
theme: Тема
|
||||
theme: 'Тема:'
|
||||
dark: Тёмная
|
||||
light: Светлая
|
||||
wallets:
|
||||
|
|
|
@ -22,7 +22,7 @@ repeat: Tekrar
|
|||
scan_result: Tarama sonucu
|
||||
back: Geri
|
||||
share: Paylasmak
|
||||
theme: Tema
|
||||
theme: 'Tema:'
|
||||
dark: Karanlik
|
||||
light: Isik
|
||||
wallets:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
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());
|
||||
|
|
Loading…
Reference in a new issue