mirror of
https://github.com/damus-io/notecrumbs.git
synced 2024-09-20 21:56:33 +00:00
cleanup some stuff
This commit is contained in:
parent
3b566b23f0
commit
63899c9c68
@ -22,7 +22,7 @@ WIP!
|
|||||||
- [ ] Cache profile pictures
|
- [ ] Cache profile pictures
|
||||||
- [ ] HTML note page
|
- [ ] 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)
|
||||||
|
|
||||||
|
@ -12,9 +12,8 @@ use std::sync::Arc;
|
|||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::render::NoteRenderData;
|
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use nostrdb::{Config, Ndb, Transaction};
|
use nostrdb::{Config, Ndb};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use lru::LruCache;
|
use lru::LruCache;
|
||||||
@ -110,7 +109,7 @@ async fn serve(
|
|||||||
|
|
||||||
// render_data is always returned, it just might be empty
|
// render_data is always returned, it just might be empty
|
||||||
let partial_render_data = match render::get_render_data(&app, &nip19) {
|
let partial_render_data = match render::get_render_data(&app, &nip19) {
|
||||||
Err(err) => {
|
Err(_err) => {
|
||||||
return Ok(Response::builder()
|
return Ok(Response::builder()
|
||||||
.status(StatusCode::BAD_REQUEST)
|
.status(StatusCode::BAD_REQUEST)
|
||||||
.body(Full::new(Bytes::from(
|
.body(Full::new(Bytes::from(
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::Target;
|
|
||||||
use nostr_sdk::nips::nip19::Nip19;
|
use nostr_sdk::nips::nip19::Nip19;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
use crate::{fonts, Error, Notecrumbs};
|
use crate::{fonts, Error, Notecrumbs};
|
||||||
use egui::{
|
use egui::{Color32, FontId, RichText, Rounding, Vec2, Visuals};
|
||||||
pos2, Color32, ColorImage, FontId, Label, Rect, RichText, Rounding, TextureHandle, Vec2,
|
|
||||||
Visuals,
|
|
||||||
};
|
|
||||||
use log::{debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
use nostr_sdk::nips::nip19::Nip19;
|
use nostr_sdk::nips::nip19::Nip19;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use nostrdb::{Note, Transaction};
|
use nostrdb::{Note, Transaction};
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
impl ProfileRenderData {
|
impl ProfileRenderData {
|
||||||
pub fn default(pfp: egui::ImageData) -> Self {
|
pub fn default(pfp: egui::ImageData) -> Self {
|
||||||
@ -274,48 +270,13 @@ pub fn get_render_data(app: &Notecrumbs, target: &Nip19) -> Result<PartialRender
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
fn render_username(ui: &mut egui::Ui, profile: &ProfileRenderData) {
|
||||||
pub fn floor_char_boundary(s: &str, index: usize) -> 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) {
|
|
||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
puffin::profile_function!();
|
puffin::profile_function!();
|
||||||
let name = format!("@{}", profile.name);
|
let name = format!("@{}", profile.name);
|
||||||
ui.label(RichText::new(&name).size(30.0).color(Color32::DARK_GRAY));
|
ui.label(RichText::new(&name).size(30.0).color(Color32::DARK_GRAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn heading(ui: &mut egui::Ui, text: impl Into<RichText>) {
|
|
||||||
ui.label(text.into().size(40.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn setup_visuals(font_data: &egui::FontData, ctx: &egui::Context) {
|
fn setup_visuals(font_data: &egui::FontData, ctx: &egui::Context) {
|
||||||
let mut visuals = Visuals::dark();
|
let mut visuals = Visuals::dark();
|
||||||
visuals.override_text_color = Some(Color32::WHITE);
|
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) {
|
fn note_ui(app: &Notecrumbs, ctx: &egui::Context, note: &NoteRenderData) {
|
||||||
setup_visuals(&app.font_data, ctx);
|
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 inner_margin = 60.0;
|
||||||
let canvas_width = 1200.0;
|
let canvas_width = 1200.0;
|
||||||
let canvas_height = 630.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 total_margin = outer_margin + inner_margin;
|
||||||
let pfp = ctx.load_texture("pfp", note.profile.pfp.clone(), Default::default());
|
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.horizontal(|ui| {
|
||||||
ui.image(&pfp);
|
ui.image(&pfp);
|
||||||
render_username(app, ui, ¬e.profile);
|
render_username(ui, ¬e.profile);
|
||||||
ui.with_layout(right_aligned(), discuss_on_damus);
|
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) {
|
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());
|
let pfp = ctx.load_texture("pfp", profile.pfp.clone(), Default::default());
|
||||||
setup_visuals(&app.font_data, ctx);
|
setup_visuals(&app.font_data, ctx);
|
||||||
|
|
||||||
@ -472,7 +418,7 @@ fn profile_ui(app: &Notecrumbs, ctx: &egui::Context, profile: &ProfileRenderData
|
|||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.image(&pfp);
|
ui.image(&pfp);
|
||||||
render_username(app, ui, &profile);
|
render_username(ui, &profile);
|
||||||
});
|
});
|
||||||
//body(ui, &profile.about);
|
//body(ui, &profile.about);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user