diff --git a/img/logo.png b/img/logo.png index 7440957..79685bb 100644 Binary files a/img/logo.png and b/img/logo.png differ diff --git a/img/logo_light.png b/img/logo_light.png index d0a0ab0..f333ce8 100644 Binary files a/img/logo_light.png and b/img/logo_light.png differ diff --git a/src/gui/views/qr.rs b/src/gui/views/qr.rs index 1f69cd8..e0690ff 100644 --- a/src/gui/views/qr.rs +++ b/src/gui/views/qr.rs @@ -16,10 +16,8 @@ use std::mem::size_of; use std::sync::Arc; use parking_lot::RwLock; use std::thread; -use egui::{SizeHint, TextureHandle, TextureOptions}; +use egui::{SizeHint, TextureHandle}; use egui::epaint::RectShape; -use egui::load::SizedTexture; -use egui_extras::image::load_svg_bytes_with_size; use image::{ExtendedColorType, ImageEncoder}; use image::codecs::png::{CompressionType, FilterType, PngEncoder}; use qrcodegen::QrCode; @@ -251,19 +249,7 @@ impl QrCodeContent { let mut content_rect = ui.allocate_ui_at_rect(rect, |ui| { ui.add_space(10.0); 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)); + self.texture_handle = Some(View::svg_image(ui, "qr_code", svg.as_slice(), Some(size))); ui.add_space(10.0); }).response.rect; diff --git a/src/gui/views/views.rs b/src/gui/views/views.rs index 0568b96..4f91528 100644 --- a/src/gui/views/views.rs +++ b/src/gui/views/views.rs @@ -17,14 +17,16 @@ use std::sync::Arc; use parking_lot::RwLock; use lazy_static::lazy_static; -use egui::{Align, Button, CursorIcon, Layout, lerp, PointerState, Rect, Response, Rgba, RichText, Sense, Spinner, TextBuffer, TextStyle, Widget}; +use egui::{Align, Button, CursorIcon, Layout, lerp, PointerState, Rect, Response, Rgba, RichText, Sense, SizeHint, Spinner, TextBuffer, TextStyle, TextureHandle, TextureOptions, Widget}; use egui::epaint::{Color32, FontId, RectShape, Rounding, Stroke}; use egui::epaint::text::TextWrapping; +use egui::load::SizedTexture; use egui::os::OperatingSystem; use egui::text::{LayoutJob, TextFormat}; use egui::text_edit::TextEditState; -use crate::AppConfig; +use egui_extras::image::load_svg_bytes_with_size; +use crate::AppConfig; use crate::gui::Colors; use crate::gui::icons::{CHECK_SQUARE, CLIPBOARD_TEXT, COPY, EYE, EYE_SLASH, SCAN, SQUARE}; use crate::gui::platform::PlatformCallbacks; @@ -636,6 +638,26 @@ impl View { Stroke { width: 1.0, color }); } + /// Draw SVG image from provided data with optional provided size. + pub fn svg_image(ui: &mut egui::Ui, + name: &str, + svg: &[u8], + size: Option) -> TextureHandle { + let color_img = load_svg_bytes_with_size(svg, size).unwrap(); + // Create image texture. + let texture_handle = ui.ctx().load_texture(name, + color_img.clone(), + TextureOptions::default()); + 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)); + texture_handle + } + /// Draw application logo image with name and version. pub fn app_logo_name_version(ui: &mut egui::Ui) { ui.add_space(-1.0);