From 72195bda1b6eb1715e5d8f89ddcfd726999f9bdf Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Tue, 17 Jan 2023 07:09:37 +1300 Subject: [PATCH] cleanup --- src/people.rs | 18 +++++++++++------- src/settings.rs | 13 ++++++------- src/ui/feed.rs | 17 +++++------------ src/ui/mod.rs | 5 ++--- src/ui/people/mod.rs | 17 +++++------------ 5 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/people.rs b/src/people.rs index 493e94f8..03c7d907 100644 --- a/src/people.rs +++ b/src/people.rs @@ -310,18 +310,22 @@ impl People { // Finish this later (spawn) let apubkeyhex = pubkeyhex.to_owned(); tokio::spawn(async move { - let size = AVATAR_SIZE * GLOBALS.pixels_per_point_times_100.load(std::sync::atomic::Ordering::Relaxed) / 100; + let size = AVATAR_SIZE + * GLOBALS + .pixels_per_point_times_100 + .load(std::sync::atomic::Ordering::Relaxed) + / 100; if let Ok(image) = image::load_from_memory(&bytes) { // Note: we can't use egui_extras::image::load_image_bytes because we // need to force a resize - let image = image.resize( - size, - size, - image::imageops::FilterType::CatmullRom, - ); // DynamicImage + let image = + image.resize(size, size, image::imageops::FilterType::CatmullRom); // DynamicImage let image_buffer = image.into_rgba8(); // RgbaImage (ImageBuffer) let color_image = ColorImage::from_rgba_unmultiplied( - [image_buffer.width() as usize, image_buffer.height() as usize], + [ + image_buffer.width() as usize, + image_buffer.height() as usize, + ], image_buffer.as_flat_samples().as_slice(), ); GLOBALS.people.avatars_temp.insert(apubkeyhex, color_image); diff --git a/src/settings.rs b/src/settings.rs index bf320354..3fd402ca 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -111,15 +111,15 @@ impl Settings { "light_mode" => settings.light_mode = numstr_to_bool(row.1), "set_client_tag" => settings.set_client_tag = numstr_to_bool(row.1), "override_dpi" => { - if row.1=="" { + if row.1.is_empty() { settings.override_dpi = DEFAULT_OVERRIDE_DPI; } else { settings.override_dpi = match row.1.parse::() { Ok(number) => Some(number), - _ => DEFAULT_OVERRIDE_DPI + _ => DEFAULT_OVERRIDE_DPI, }; } - }, + } _ => {} } } @@ -166,14 +166,13 @@ impl Settings { self.pow, bool_to_numstr(self.offline), bool_to_numstr(self.light_mode), - bool_to_numstr(self.set_client_tag) + bool_to_numstr(self.set_client_tag), ))?; // Save override dpi if let Some(ref dpi) = self.override_dpi { - let mut stmt = db.prepare( - "REPLACE INTO SETTINGS (key, value) VALUES ('override_dpi', ?)", - )?; + let mut stmt = + db.prepare("REPLACE INTO SETTINGS (key, value) VALUES ('override_dpi', ?)")?; stmt.execute((&dpi,))?; } else { // Otherwise delete any such setting diff --git a/src/ui/feed.rs b/src/ui/feed.rs index ffd27076..1614738f 100644 --- a/src/ui/feed.rs +++ b/src/ui/feed.rs @@ -1,9 +1,9 @@ use super::{GossipUi, Page}; -use crate::AVATAR_SIZE_F32; use crate::comms::ToOverlordMessage; use crate::feed::FeedKind; use crate::globals::{Globals, GLOBALS}; use crate::ui::widgets::CopyButton; +use crate::AVATAR_SIZE_F32; use eframe::egui; use egui::{ Align, Color32, Context, Frame, Image, Label, Layout, RichText, ScrollArea, SelectableLabel, @@ -444,18 +444,11 @@ fn render_post_actual( } else { app.placeholder_avatar.clone() }; - let size = AVATAR_SIZE_F32 * GLOBALS.pixels_per_point_times_100.load(Ordering::Relaxed) as f32 / 100.0; + let size = AVATAR_SIZE_F32 + * GLOBALS.pixels_per_point_times_100.load(Ordering::Relaxed) as f32 + / 100.0; if ui - .add( - Image::new( - &avatar, - Vec2 { - x: size, - y: size, - }, - ) - .sense(Sense::click()), - ) + .add(Image::new(&avatar, Vec2 { x: size, y: size }).sense(Sense::click())) .clicked() { app.set_page(Page::Person(event.pubkey.into())); diff --git a/src/ui/mod.rs b/src/ui/mod.rs index ecc1a1fd..d4156604 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -103,7 +103,6 @@ impl Drop for GossipUi { impl GossipUi { fn new(cctx: &eframe::CreationContext<'_>) -> Self { - let settings = GLOBALS.settings.blocking_read().clone(); if let Some(dpi) = settings.override_dpi { @@ -120,7 +119,7 @@ impl GossipUi { // Set global pixels_per_point_times_100, used for image scaling. GLOBALS.pixels_per_point_times_100.store( (cctx.egui_ctx.pixels_per_point() * 100.0) as u32, - Ordering::Relaxed + Ordering::Relaxed, ); if !settings.light_mode { @@ -164,7 +163,7 @@ impl GossipUi { let current_dpi = (cctx.egui_ctx.pixels_per_point() * 72.0) as u32; let (override_dpi, override_dpi_value): (bool, u32) = match settings.override_dpi { Some(v) => (true, v), - None => (false, current_dpi) + None => (false, current_dpi), }; GossipUi { diff --git a/src/ui/people/mod.rs b/src/ui/people/mod.rs index 38ce9d1f..cfd1a82f 100644 --- a/src/ui/people/mod.rs +++ b/src/ui/people/mod.rs @@ -1,8 +1,8 @@ use super::{GossipUi, Page}; -use crate::AVATAR_SIZE_F32; use crate::comms::ToOverlordMessage; use crate::db::DbPerson; use crate::globals::GLOBALS; +use crate::AVATAR_SIZE_F32; use eframe::egui; use egui::{Context, Image, RichText, ScrollArea, Sense, Ui, Vec2}; use std::sync::atomic::Ordering; @@ -73,18 +73,11 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra } else { app.placeholder_avatar.clone() }; - let size = AVATAR_SIZE_F32 * GLOBALS.pixels_per_point_times_100.load(Ordering::Relaxed) as f32 / 100.0; + let size = AVATAR_SIZE_F32 + * GLOBALS.pixels_per_point_times_100.load(Ordering::Relaxed) as f32 + / 100.0; if ui - .add( - Image::new( - &avatar, - Vec2 { - x: size, - y: size, - }, - ) - .sense(Sense::click()), - ) + .add(Image::new(&avatar, Vec2 { x: size, y: size }).sense(Sense::click())) .clicked() { app.set_page(Page::Person(person.pubkey.clone()));