ui: optimize logo

This commit is contained in:
ardocrat 2024-07-07 20:19:56 +03:00
parent 891ab0a9c4
commit 0c4d6ea01b
4 changed files with 26 additions and 18 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View file

@ -16,10 +16,8 @@ use std::mem::size_of;
use std::sync::Arc; use std::sync::Arc;
use parking_lot::RwLock; use parking_lot::RwLock;
use std::thread; use std::thread;
use egui::{SizeHint, TextureHandle, TextureOptions}; use egui::{SizeHint, TextureHandle};
use egui::epaint::RectShape; use egui::epaint::RectShape;
use egui::load::SizedTexture;
use egui_extras::image::load_svg_bytes_with_size;
use image::{ExtendedColorType, ImageEncoder}; use image::{ExtendedColorType, ImageEncoder};
use image::codecs::png::{CompressionType, FilterType, PngEncoder}; use image::codecs::png::{CompressionType, FilterType, PngEncoder};
use qrcodegen::QrCode; use qrcodegen::QrCode;
@ -251,19 +249,7 @@ impl QrCodeContent {
let mut content_rect = ui.allocate_ui_at_rect(rect, |ui| { let mut content_rect = ui.allocate_ui_at_rect(rect, |ui| {
ui.add_space(10.0); ui.add_space(10.0);
let size = SizeHint::Size(ui.available_width() as u32, ui.available_width() as u32); 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(); self.texture_handle = Some(View::svg_image(ui, "qr_code", svg.as_slice(), Some(size)));
// 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.add_space(10.0);
}).response.rect; }).response.rect;

View file

@ -17,14 +17,16 @@ use std::sync::Arc;
use parking_lot::RwLock; use parking_lot::RwLock;
use lazy_static::lazy_static; 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::{Color32, FontId, RectShape, Rounding, Stroke};
use egui::epaint::text::TextWrapping; use egui::epaint::text::TextWrapping;
use egui::load::SizedTexture;
use egui::os::OperatingSystem; use egui::os::OperatingSystem;
use egui::text::{LayoutJob, TextFormat}; use egui::text::{LayoutJob, TextFormat};
use egui::text_edit::TextEditState; 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::Colors;
use crate::gui::icons::{CHECK_SQUARE, CLIPBOARD_TEXT, COPY, EYE, EYE_SLASH, SCAN, SQUARE}; use crate::gui::icons::{CHECK_SQUARE, CLIPBOARD_TEXT, COPY, EYE, EYE_SLASH, SCAN, SQUARE};
use crate::gui::platform::PlatformCallbacks; use crate::gui::platform::PlatformCallbacks;
@ -636,6 +638,26 @@ impl View {
Stroke { width: 1.0, color }); 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<SizeHint>) -> 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. /// Draw application logo image with name and version.
pub fn app_logo_name_version(ui: &mut egui::Ui) { pub fn app_logo_name_version(ui: &mut egui::Ui) {
ui.add_space(-1.0); ui.add_space(-1.0);