mirror of
https://github.com/damus-io/notecrumbs.git
synced 2024-09-29 18:10:43 +00:00
Compare commits
2 Commits
5c202fae4d
...
df56cb9fcd
Author | SHA1 | Date | |
---|---|---|---|
|
df56cb9fcd | ||
|
26885f854b |
40
Cargo.lock
generated
40
Cargo.lock
generated
@ -189,6 +189,29 @@ dependencies = [
|
|||||||
"which",
|
"which",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bindgen"
|
||||||
|
version = "0.69.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9ffcebc3849946a7170a05992aac39da343a90676ab392c51a4280981d6379c2"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags 2.4.1",
|
||||||
|
"cexpr",
|
||||||
|
"clang-sys",
|
||||||
|
"lazy_static",
|
||||||
|
"lazycell",
|
||||||
|
"log",
|
||||||
|
"peeking_take_while",
|
||||||
|
"prettyplease",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"regex",
|
||||||
|
"rustc-hash",
|
||||||
|
"shlex",
|
||||||
|
"syn 2.0.41",
|
||||||
|
"which",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bip39"
|
name = "bip39"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
@ -1437,9 +1460,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nostrdb"
|
name = "nostrdb"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
source = "git+https://github.com/damus-io/nostrdb-rs.git?rev=21d0002f5ff62e51c4114e3d15a2ffa4e99b17e8#21d0002f5ff62e51c4114e3d15a2ffa4e99b17e8"
|
source = "git+https://github.com/damus-io/nostrdb-rs.git?rev=71d7ce19d64e15f364d9908e5e34f0409395054c#71d7ce19d64e15f364d9908e5e34f0409395054c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bindgen 0.69.1",
|
||||||
"cc",
|
"cc",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"flatbuffers",
|
"flatbuffers",
|
||||||
@ -1637,6 +1661,16 @@ version = "0.2.17"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "prettyplease"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"syn 2.0.41",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.70"
|
version = "1.0.70"
|
||||||
@ -2061,7 +2095,7 @@ version = "0.58.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "404d98ffda633acd7a3ea68e0e5f160814ee7ae8942c89d60c53f7e0fae99373"
|
checksum = "404d98ffda633acd7a3ea68e0e5f160814ee7ae8942c89d60c53f7e0fae99373"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen 0.63.0",
|
||||||
"cc",
|
"cc",
|
||||||
"flate2",
|
"flate2",
|
||||||
"heck",
|
"heck",
|
||||||
|
@ -13,8 +13,9 @@ hyper-util = { version = "0.1.1", features = ["full"] }
|
|||||||
http-body-util = "0.1"
|
http-body-util = "0.1"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
env_logger = "0.10.1"
|
env_logger = "0.10.1"
|
||||||
nostrdb = { git = "https://github.com/damus-io/nostrdb-rs.git", rev = "21d0002f5ff62e51c4114e3d15a2ffa4e99b17e8" }
|
nostrdb = { git = "https://github.com/damus-io/nostrdb-rs.git", rev = "71d7ce19d64e15f364d9908e5e34f0409395054c" }
|
||||||
#nostrdb = { path = "/home/jb55/src/rust/nostrdb-rs" }
|
#nostrdb = { path = "/home/jb55/src/rust/nostrdb-rs" }
|
||||||
|
#nostrdb = "0.1.6"
|
||||||
#nostr-sdk = { git = "https://github.com/damus-io/nostr-sdk.git", rev = "fc0dc7b38f5060f171228b976b9700c0135245d3" }
|
#nostr-sdk = { git = "https://github.com/damus-io/nostr-sdk.git", rev = "fc0dc7b38f5060f171228b976b9700c0135245d3" }
|
||||||
nostr-sdk = "0.26.0"
|
nostr-sdk = "0.26.0"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
|
117
src/render.rs
117
src/render.rs
@ -2,12 +2,15 @@ use crate::{fonts, Error, Notecrumbs};
|
|||||||
use egui::emath::Rot2;
|
use egui::emath::Rot2;
|
||||||
use egui::epaint::Shadow;
|
use egui::epaint::Shadow;
|
||||||
use egui::{
|
use egui::{
|
||||||
pos2, Color32, FontId, Mesh, Rect, RichText, Rounding, Shape, TextureHandle, Vec2, Visuals,
|
pos2,
|
||||||
|
text::{LayoutJob, TextFormat},
|
||||||
|
Color32, FontFamily, FontId, Mesh, Rect, RichText, Rounding, Shape, 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::{BlockType, Blocks, Note, Transaction};
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
|
|
||||||
impl ProfileRenderData {
|
impl ProfileRenderData {
|
||||||
@ -23,6 +26,7 @@ impl ProfileRenderData {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct NoteData {
|
pub struct NoteData {
|
||||||
|
pub id: Option<[u8; 32]>,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +94,7 @@ impl From<EventId> for EventSource {
|
|||||||
impl NoteData {
|
impl NoteData {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let content = "".to_string();
|
let content = "".to_string();
|
||||||
NoteData { content }
|
NoteData { content, id: None }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,12 +196,16 @@ fn get_profile_render_data(
|
|||||||
|
|
||||||
fn ndb_note_to_data(note: &Note) -> NoteData {
|
fn ndb_note_to_data(note: &Note) -> NoteData {
|
||||||
let content = note.content().to_string();
|
let content = note.content().to_string();
|
||||||
NoteData { content }
|
let id = Some(*note.id());
|
||||||
|
NoteData { content, id }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sdk_note_to_note_data(note: &Event) -> NoteData {
|
fn sdk_note_to_note_data(note: &Event) -> NoteData {
|
||||||
let content = note.content.clone();
|
let content = note.content.clone();
|
||||||
NoteData { content }
|
NoteData {
|
||||||
|
content,
|
||||||
|
id: Some(note.id.to_bytes()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_note_render_data(
|
fn get_note_render_data(
|
||||||
@ -290,7 +298,59 @@ fn setup_visuals(font_data: &egui::FontData, ctx: &egui::Context) {
|
|||||||
fonts::setup_fonts(font_data, ctx);
|
fonts::setup_fonts(font_data, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wrapped_body(ui: &mut egui::Ui, text: &str) {
|
fn wrapped_body_blocks(ui: &mut egui::Ui, note: &Note, blocks: &Blocks) {
|
||||||
|
let size = 50.0;
|
||||||
|
|
||||||
|
let mut job = LayoutJob::default();
|
||||||
|
job.justify = false;
|
||||||
|
job.halign = egui::Align::LEFT;
|
||||||
|
job.wrap = egui::text::TextWrapping {
|
||||||
|
max_rows: 5,
|
||||||
|
break_anywhere: false,
|
||||||
|
overflow_character: Some('…'),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let purple = Color32::from_rgb(0xcc, 0x43, 0xc5);
|
||||||
|
|
||||||
|
for block in blocks.iter(note) {
|
||||||
|
match block.blocktype() {
|
||||||
|
BlockType::Url => job.append(
|
||||||
|
block.as_str(),
|
||||||
|
0.0,
|
||||||
|
TextFormat {
|
||||||
|
font_id: FontId::new(size, FontFamily::Proportional),
|
||||||
|
color: purple,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
BlockType::Hashtag => job.append(
|
||||||
|
&format!("#{}", block.as_str()),
|
||||||
|
0.0,
|
||||||
|
TextFormat {
|
||||||
|
font_id: FontId::new(size, FontFamily::Proportional),
|
||||||
|
color: purple,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
|
||||||
|
_ => job.append(
|
||||||
|
block.as_str(),
|
||||||
|
0.0,
|
||||||
|
TextFormat {
|
||||||
|
font_id: FontId::new(size, FontFamily::Proportional),
|
||||||
|
color: Color32::WHITE,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.label(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wrapped_body_text(ui: &mut egui::Ui, text: &str) {
|
||||||
use egui::text::{LayoutJob, TextFormat};
|
use egui::text::{LayoutJob, TextFormat};
|
||||||
|
|
||||||
let format = TextFormat {
|
let format = TextFormat {
|
||||||
@ -303,15 +363,6 @@ fn wrapped_body(ui: &mut egui::Ui, text: &str) {
|
|||||||
|
|
||||||
let mut job = LayoutJob::single_section(text.to_owned(), format);
|
let mut job = LayoutJob::single_section(text.to_owned(), format);
|
||||||
|
|
||||||
job.justify = false;
|
|
||||||
job.halign = egui::Align::LEFT;
|
|
||||||
job.wrap = egui::text::TextWrapping {
|
|
||||||
max_rows: 4,
|
|
||||||
break_anywhere: false,
|
|
||||||
overflow_character: Some('…'),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
ui.label(job);
|
ui.label(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,14 +405,6 @@ fn note_ui(app: &Notecrumbs, ctx: &egui::Context, note: &NoteRenderData) {
|
|||||||
let pfp = ctx.load_texture("pfp", note.profile.pfp.clone(), Default::default());
|
let pfp = ctx.load_texture("pfp", note.profile.pfp.clone(), Default::default());
|
||||||
let bg = ctx.load_texture("background", app.background.clone(), Default::default());
|
let bg = ctx.load_texture("background", app.background.clone(), Default::default());
|
||||||
|
|
||||||
/*
|
|
||||||
let desired_height = canvas_height - total_margin * 2.0;
|
|
||||||
let desired_width = canvas_width - total_margin * 2.0;
|
|
||||||
let desired_size = Vec2::new(desired_width, desired_height);
|
|
||||||
ui.set_min_size(desired_size);
|
|
||||||
ui.set_max_size(desired_size);
|
|
||||||
*/
|
|
||||||
|
|
||||||
egui::CentralPanel::default()
|
egui::CentralPanel::default()
|
||||||
.frame(
|
.frame(
|
||||||
egui::Frame::default()
|
egui::Frame::default()
|
||||||
@ -389,18 +432,28 @@ fn note_ui(app: &Notecrumbs, ctx: &egui::Context, note: &NoteRenderData) {
|
|||||||
//egui::ScrollArea::vertical().show(ui, |ui| {
|
//egui::ScrollArea::vertical().show(ui, |ui| {
|
||||||
ui.spacing_mut().item_spacing = Vec2::new(10.0, 50.0);
|
ui.spacing_mut().item_spacing = Vec2::new(10.0, 50.0);
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.with_layout(right_aligned(), |ui| {
|
|
||||||
ui.label(RichText::new("damus.io").size(30.0));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
let desired = Vec2::new(desired_width, desired_height / 2.2);
|
let desired = Vec2::new(desired_width, desired_height / 1.5);
|
||||||
ui.set_max_size(desired);
|
ui.set_max_size(desired);
|
||||||
ui.set_min_size(desired);
|
ui.set_min_size(desired);
|
||||||
// only one widget is allowed in here
|
|
||||||
wrapped_body(ui, ¬e.note.content);
|
let mut rendered = false;
|
||||||
|
|
||||||
|
let ok = (|| -> Result<(), nostrdb::Error> {
|
||||||
|
let txn = Transaction::new(&app.ndb)?;
|
||||||
|
let note_id = note.note.id.ok_or(nostrdb::Error::NotFound)?;
|
||||||
|
let note = app.ndb.get_note_by_id(&txn, ¬e_id)?;
|
||||||
|
let blocks =
|
||||||
|
app.ndb.get_blocks_by_key(&txn, note.key().unwrap())?;
|
||||||
|
|
||||||
|
wrapped_body_blocks(ui, ¬e, &blocks);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})();
|
||||||
|
|
||||||
|
if let Err(_) = ok {
|
||||||
|
wrapped_body_text(ui, ¬e.note.content);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
Loading…
Reference in New Issue
Block a user