diff --git a/README.md b/README.md index 9309291..47d84ca 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ WIP! - [ ] Cache profile pictures - [ ] HTML note page -Very alpha. I mean look at the current design... +Very alpha. The design is still a bit rough, but getting there: -![wip](https://cdn.jb55.com/s/nevent1qqstj0wgdgplzypp5fjlg5vdr9mcex5me7elhcvh2trk0836y69q9cgsn6gzr.png) +![wip](https://cdn.jb55.com/s/note1hy7us6sr7ygzrgn973gc6xth3jdfhnanl0sew5k8v70r5f52qtss0pwcha.png) diff --git a/src/main.rs b/src/main.rs index 40bf566..6e7914a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,8 @@ use std::sync::Arc; use tokio::net::TcpListener; use crate::error::Error; -use crate::render::NoteRenderData; use nostr_sdk::prelude::*; -use nostrdb::{Config, Ndb, Transaction}; +use nostrdb::{Config, Ndb}; use std::time::Duration; use lru::LruCache; @@ -110,7 +109,7 @@ async fn serve( // render_data is always returned, it just might be empty let partial_render_data = match render::get_render_data(&app, &nip19) { - Err(err) => { + Err(_err) => { return Ok(Response::builder() .status(StatusCode::BAD_REQUEST) .body(Full::new(Bytes::from( diff --git a/src/nip19.rs b/src/nip19.rs index eb8aee0..788fe2e 100644 --- a/src/nip19.rs +++ b/src/nip19.rs @@ -1,5 +1,4 @@ use crate::error::Error; -use crate::Target; use nostr_sdk::nips::nip19::Nip19; use nostr_sdk::prelude::*; diff --git a/src/render.rs b/src/render.rs index f84fccb..8d6d059 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,13 +1,9 @@ use crate::{fonts, Error, Notecrumbs}; -use egui::{ - pos2, Color32, ColorImage, FontId, Label, Rect, RichText, Rounding, TextureHandle, Vec2, - Visuals, -}; +use egui::{Color32, FontId, RichText, Rounding, Vec2, Visuals}; use log::{debug, info, warn}; use nostr_sdk::nips::nip19::Nip19; use nostr_sdk::prelude::*; use nostrdb::{Note, Transaction}; -use std::sync::Arc; impl ProfileRenderData { pub fn default(pfp: egui::ImageData) -> Self { @@ -274,48 +270,13 @@ pub fn get_render_data(app: &Notecrumbs, target: &Nip19) -> Result usize { - if index >= s.len() { - s.len() - } else { - let lower_bound = index.saturating_sub(3); - let new_index = s.as_bytes()[lower_bound..=index] - .iter() - .rposition(|b| is_utf8_char_boundary(*b)); - - // SAFETY: we know that the character boundary will be within four bytes - unsafe { lower_bound + new_index.unwrap_unchecked() } - } -} - -#[inline] -fn is_utf8_char_boundary(c: u8) -> bool { - // This is bit magic equivalent to: b < 128 || b >= 192 - (c as i8) >= -0x40 -} - -fn ui_abbreviate_name(ui: &mut egui::Ui, name: &str, len: usize) { - if name.len() > len { - let closest = floor_char_boundary(name, len); - heading(ui, &name[..closest]); - heading(ui, "..."); - } else { - heading(ui, name); - } -} - -fn render_username(app: &Notecrumbs, ui: &mut egui::Ui, profile: &ProfileRenderData) { +fn render_username(ui: &mut egui::Ui, profile: &ProfileRenderData) { #[cfg(feature = "profiling")] puffin::profile_function!(); let name = format!("@{}", profile.name); ui.label(RichText::new(&name).size(30.0).color(Color32::DARK_GRAY)); } -fn heading(ui: &mut egui::Ui, text: impl Into) { - ui.label(text.into().size(40.0)); -} - fn setup_visuals(font_data: &egui::FontData, ctx: &egui::Context) { let mut visuals = Visuals::dark(); visuals.override_text_color = Some(Color32::WHITE); @@ -374,19 +335,6 @@ fn note_frame_align() -> egui::Layout { } } -fn quoted_text_align() -> egui::Layout { - use egui::{Align, Direction, Layout}; - - Layout { - main_dir: Direction::TopDown, - main_wrap: false, - main_align: Align::Center, - main_justify: false, - cross_align: Align::Center, - cross_justify: false, - } -} - fn note_ui(app: &Notecrumbs, ctx: &egui::Context, note: &NoteRenderData) { setup_visuals(&app.font_data, ctx); @@ -394,7 +342,7 @@ fn note_ui(app: &Notecrumbs, ctx: &egui::Context, note: &NoteRenderData) { let inner_margin = 60.0; let canvas_width = 1200.0; let canvas_height = 630.0; - let canvas_size = Vec2::new(canvas_width, canvas_height); + //let canvas_size = Vec2::new(canvas_width, canvas_height); let total_margin = outer_margin + inner_margin; let pfp = ctx.load_texture("pfp", note.profile.pfp.clone(), Default::default()); @@ -441,7 +389,7 @@ fn note_ui(app: &Notecrumbs, ctx: &egui::Context, note: &NoteRenderData) { ui.horizontal(|ui| { ui.image(&pfp); - render_username(app, ui, ¬e.profile); + render_username(ui, ¬e.profile); ui.with_layout(right_aligned(), discuss_on_damus); }); }); @@ -463,8 +411,6 @@ fn discuss_on_damus(ui: &mut egui::Ui) { } fn profile_ui(app: &Notecrumbs, ctx: &egui::Context, profile: &ProfileRenderData) { - use egui::{FontId, RichText}; - let pfp = ctx.load_texture("pfp", profile.pfp.clone(), Default::default()); setup_visuals(&app.font_data, ctx); @@ -472,7 +418,7 @@ fn profile_ui(app: &Notecrumbs, ctx: &egui::Context, profile: &ProfileRenderData ui.vertical(|ui| { ui.horizontal(|ui| { ui.image(&pfp); - render_username(app, ui, &profile); + render_username(ui, &profile); }); //body(ui, &profile.about); });