diff --git a/src/date_ago.rs b/src/date_ago.rs index 7e0a3558..c737c881 100644 --- a/src/date_ago.rs +++ b/src/date_ago.rs @@ -1,4 +1,3 @@ - use nostr_proto::Unixtime; pub fn date_ago(then: Unixtime) -> String { @@ -13,8 +12,7 @@ pub fn date_ago(then: Unixtime) -> String { format!("{}s", seconds) } else if seconds < 90 { "1m".to_string() - } - else if minutes < 45.0 { + } else if minutes < 45.0 { format!("{}m", minutes as i64) } else if minutes < 90.0 { "1h".to_string() @@ -27,7 +25,7 @@ pub fn date_ago(then: Unixtime) -> String { } else if days < 45.0 { "1m".to_string() } else if days < 365.0 { - format!("{}m", (days/30.0) as i64) + format!("{}m", (days / 30.0) as i64) } else if years < 1.5 { "1y".to_string() } else { diff --git a/src/globals.rs b/src/globals.rs index 4137ffb9..5c5c796f 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -7,7 +7,6 @@ use rusqlite::Connection; use std::collections::HashMap; use std::sync::atomic::AtomicBool; use tokio::sync::{broadcast, mpsc, Mutex}; -use tracing::info; /// Only one of these is ever created, via lazy_static!, and represents /// global state for the rust application @@ -75,7 +74,6 @@ pub async fn get_feed() -> Vec { .filter(|e| e.in_reply_to.is_none()) // only root events .cloned() .collect(); - let len = GLOBALS.event_relateds.lock().await.len(); feed.sort_unstable_by(|a, b| a.last_reply_at.cmp(&b.last_reply_at)); feed.iter().map(|e| e.id).collect() } @@ -91,7 +89,6 @@ pub fn blocking_get_feed() -> Vec { //.filter(|e| e.in_reply_to.is_none()) // only root events .cloned() .collect(); - let len = GLOBALS.event_relateds.blocking_lock().len(); feed.sort_unstable_by(|a, b| a.last_reply_at.cmp(&b.last_reply_at)); feed.iter().map(|e| e.id).collect() } diff --git a/src/ui/about.rs b/src/ui/about.rs index 1db918c4..09429ec6 100644 --- a/src/ui/about.rs +++ b/src/ui/about.rs @@ -1,9 +1,8 @@ use super::GossipUi; use eframe::egui; -use egui::{Align, Context, FontFamily, Layout, RichText, TextStyle, Ui, vec2}; +use egui::{Align, Context, Layout, RichText, TextStyle, Ui}; pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) { - ui.with_layout(Layout::top_down(Align::Center), |ui| { ui.add_space(30.0); @@ -70,5 +69,4 @@ We are storing data on your system in this file: {}. This data is only used loca .text_style(TextStyle::Small) ); }); - } diff --git a/src/ui/feed.rs b/src/ui/feed.rs index 807550db..cad96aca 100644 --- a/src/ui/feed.rs +++ b/src/ui/feed.rs @@ -1,39 +1,40 @@ use super::GossipUi; use eframe::egui; -use egui::{Context, ScrollArea, TextStyle, Ui}; -use tracing::info; +use egui::{Context, ScrollArea, Ui}; pub(super) fn update(_app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) { - let feed = crate::globals::blocking_get_feed(); let screen_rect = ctx.input().screen_rect; // Rect - let scroll_delta = ctx.input().scroll_delta; // Vec2 - ScrollArea::vertical().show(ui, |ui| { for id in feed.iter().rev() { // Stop rendering at the bottom of the window: let pos2 = ui.next_widget_position(); - if pos2.y > screen_rect.max.y { break; } + if pos2.y > screen_rect.max.y { + break; + } if let Some(event) = crate::globals::GLOBALS.events.blocking_lock().get(id) { - ui.label(crate::date_ago::date_ago(event.created_at)); - if let Some(person) = crate::globals::GLOBALS.people.blocking_lock().get(&event.pubkey) { + if let Some(person) = crate::globals::GLOBALS + .people + .blocking_lock() + .get(&event.pubkey) + { if let Some(name) = &person.name { - ui.label(&format!("{}", name)); + ui.label(name); } else { - ui.label(&format!("{}", event.pubkey.as_hex_string())); + ui.label(event.pubkey.as_hex_string()); } } else { - ui.label(&format!("{}", event.pubkey.as_hex_string())); + ui.label(event.pubkey.as_hex_string()); } - ui.label(&format!("{}", event.content)); + ui.label(&event.content); ui.separator(); } else { - ui.label(&format!("-- missing event --")); + ui.label("-- missing event --".to_string()); ui.separator(); } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 24a3cefb..daea8ea7 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -7,8 +7,8 @@ mod stats; mod style; mod you; -use crate::error::Error; use crate::about::About; +use crate::error::Error; use eframe::{egui, IconData, Theme}; use egui::{ColorImage, Context, ImageData, TextureHandle, TextureOptions}; @@ -55,7 +55,7 @@ enum Page { struct GossipUi { page: Page, about: About, - icon: TextureHandle + icon: TextureHandle, } impl GossipUi { @@ -79,11 +79,8 @@ impl GossipUi { let pixels = image_buffer.as_flat_samples(); let icon_texture_handle = cctx.egui_ctx.load_texture( "icon", - ImageData::Color(ColorImage::from_rgba_unmultiplied( - size, - pixels.as_slice(), - )), - TextureOptions::default() // magnification, minification + ImageData::Color(ColorImage::from_rgba_unmultiplied(size, pixels.as_slice())), + TextureOptions::default(), // magnification, minification ); GossipUi { @@ -128,4 +125,3 @@ impl eframe::App for GossipUi { }); } } - diff --git a/src/ui/style.rs b/src/ui/style.rs index 34a50b8a..b2526964 100644 --- a/src/ui/style.rs +++ b/src/ui/style.rs @@ -1,6 +1,8 @@ use eframe::{egui, epaint}; use egui::style::{Selection, Visuals, Widgets}; -use egui::{Color32, FontData, FontDefinitions, FontFamily, FontId, FontTweak, Rounding, Stroke, TextStyle}; +use egui::{ + Color32, FontData, FontDefinitions, FontFamily, FontId, FontTweak, Rounding, Stroke, TextStyle, +}; use epaint::Shadow; use std::collections::BTreeMap; @@ -67,50 +69,77 @@ pub(super) fn light_mode_visuals() -> Visuals { pub(super) fn text_styles() -> BTreeMap { let mut text_styles: BTreeMap = BTreeMap::new(); - text_styles.insert(TextStyle::Small, FontId { - size: 12.0, - family: FontFamily::Proportional, - }); + text_styles.insert( + TextStyle::Small, + FontId { + size: 12.0, + family: FontFamily::Proportional, + }, + ); - text_styles.insert(TextStyle::Body, FontId { - size: 14.0, - family: FontFamily::Proportional, - }); + text_styles.insert( + TextStyle::Body, + FontId { + size: 14.0, + family: FontFamily::Proportional, + }, + ); - text_styles.insert(TextStyle::Monospace, FontId { - size: 14.0, - family: FontFamily::Monospace, - }); + text_styles.insert( + TextStyle::Monospace, + FontId { + size: 14.0, + family: FontFamily::Monospace, + }, + ); - text_styles.insert(TextStyle::Button, FontId { - size: 15.0, - family: FontFamily::Proportional, - }); + text_styles.insert( + TextStyle::Button, + FontId { + size: 15.0, + family: FontFamily::Proportional, + }, + ); - text_styles.insert(TextStyle::Heading, FontId { - size: 16.0, - family: FontFamily::Name("BoldOblique".into()), - }); + text_styles.insert( + TextStyle::Heading, + FontId { + size: 16.0, + family: FontFamily::Name("BoldOblique".into()), + }, + ); - text_styles.insert(TextStyle::Name("Bold".into()), FontId { - size: 14.0, - family: FontFamily::Name("Bold".into()), - }); + text_styles.insert( + TextStyle::Name("Bold".into()), + FontId { + size: 14.0, + family: FontFamily::Name("Bold".into()), + }, + ); - text_styles.insert(TextStyle::Name("MonoBold".into()), FontId { - size: 14.0, - family: FontFamily::Name("MonoBold".into()), - }); + text_styles.insert( + TextStyle::Name("MonoBold".into()), + FontId { + size: 14.0, + family: FontFamily::Name("MonoBold".into()), + }, + ); - text_styles.insert(TextStyle::Name("MonoOblique".into()), FontId { - size: 14.0, - family: FontFamily::Name("MonoOblique".into()), - }); + text_styles.insert( + TextStyle::Name("MonoOblique".into()), + FontId { + size: 14.0, + family: FontFamily::Name("MonoOblique".into()), + }, + ); - text_styles.insert(TextStyle::Name("MonoBoldOblique".into()), FontId { - size: 14.0, - family: FontFamily::Name("MonoBoldOblique".into()), - }); + text_styles.insert( + TextStyle::Name("MonoBoldOblique".into()), + FontId { + size: 14.0, + family: FontFamily::Name("MonoBoldOblique".into()), + }, + ); text_styles } @@ -128,7 +157,6 @@ pub(super) fn text_styles() -> BTreeMap { * MonoBoldOblique */ pub(super) fn font_definitions() -> FontDefinitions { - let mut font_data: BTreeMap = BTreeMap::new(); let mut families = BTreeMap::new(); @@ -190,7 +218,9 @@ pub(super) fn font_definitions() -> FontDefinitions { font_data.insert( "DejaVuSansOblique".to_owned(), - FontData::from_static(include_bytes!("../../fonts/DejaVuSans/DejaVuSans-Oblique.ttf")), + FontData::from_static(include_bytes!( + "../../fonts/DejaVuSans/DejaVuSans-Oblique.ttf" + )), ); font_data.insert( @@ -211,7 +241,9 @@ pub(super) fn font_definitions() -> FontDefinitions { font_data.insert( "DejaVuSansBoldOblique".to_owned(), - FontData::from_static(include_bytes!("../../fonts/DejaVuSans/DejaVuSans-BoldOblique.ttf")), + FontData::from_static(include_bytes!( + "../../fonts/DejaVuSans/DejaVuSans-BoldOblique.ttf" + )), ); font_data.insert( @@ -232,13 +264,14 @@ pub(super) fn font_definitions() -> FontDefinitions { font_data.insert( "InconsolataRegular".to_owned(), - FontData::from_static(include_bytes!("../../fonts/inconsolata/Inconsolata-SemiCondensedLight.ttf")).tweak( - FontTweak { - scale: 1.1, // Make it bigger. Inconsolata is smaller than DejaVu. - y_offset_factor: 0.0, - y_offset: 0.0, - }, - ), + FontData::from_static(include_bytes!( + "../../fonts/inconsolata/Inconsolata-SemiCondensedLight.ttf" + )) + .tweak(FontTweak { + scale: 1.1, // Make it bigger. Inconsolata is smaller than DejaVu. + y_offset_factor: 0.0, + y_offset: 0.0, + }), ); font_data.insert( @@ -265,18 +298,21 @@ pub(super) fn font_definitions() -> FontDefinitions { font_data.insert( "InconsolataBold".to_owned(), - FontData::from_static(include_bytes!("../../fonts/inconsolata/Inconsolata-SemiCondensedSemiBold.ttf")).tweak( - FontTweak { - scale: 1.1, // Make it bigger. Inconsolata is smaller than DejaVu. - y_offset_factor: 0.0, - y_offset: 0.0, - }, - ), + FontData::from_static(include_bytes!( + "../../fonts/inconsolata/Inconsolata-SemiCondensedSemiBold.ttf" + )) + .tweak(FontTweak { + scale: 1.1, // Make it bigger. Inconsolata is smaller than DejaVu. + y_offset_factor: 0.0, + y_offset: 0.0, + }), ); font_data.insert( "DejaVuSansMonoBold".to_owned(), - FontData::from_static(include_bytes!("../../fonts/DejaVuSans/DejaVuSansMono-Bold.ttf")), + FontData::from_static(include_bytes!( + "../../fonts/DejaVuSans/DejaVuSansMono-Bold.ttf" + )), ); font_data.insert( @@ -298,7 +334,9 @@ pub(super) fn font_definitions() -> FontDefinitions { font_data.insert( "DejaVuSansMonoOblique".to_owned(), - FontData::from_static(include_bytes!("../../fonts/DejaVuSans/DejaVuSansMono-Oblique.ttf")), + FontData::from_static(include_bytes!( + "../../fonts/DejaVuSans/DejaVuSansMono-Oblique.ttf" + )), ); families.insert( @@ -314,7 +352,9 @@ pub(super) fn font_definitions() -> FontDefinitions { font_data.insert( "DejaVuSansMonoBoldOblique".to_owned(), - FontData::from_static(include_bytes!("../../fonts/DejaVuSans/DejaVuSansMono-BoldOblique.ttf")), + FontData::from_static(include_bytes!( + "../../fonts/DejaVuSans/DejaVuSansMono-BoldOblique.ttf" + )), ); families.insert( @@ -331,4 +371,3 @@ pub(super) fn font_definitions() -> FontDefinitions { families, } } -