dominus demo

This commit is contained in:
William Casarin 2022-11-07 00:11:21 -08:00
parent 28c5ddbc80
commit 8d0bfdfb24
4 changed files with 75 additions and 49 deletions

View File

@ -1,2 +1,3 @@
[build] [build]
filehash = false filehash = true
public_url = "/webv3/"

View File

@ -7,7 +7,7 @@
<head> <head>
<!-- change this to your project name --> <!-- change this to your project name -->
<title>eframe template</title> <title>dominus</title>
<!-- config for our rust wasm binary. go to https://trunkrs.dev/assets/#rust for more customization --> <!-- config for our rust wasm binary. go to https://trunkrs.dev/assets/#rust for more customization -->
<link data-trunk rel="rust" data-wasm-opt="2" /> <link data-trunk rel="rust" data-wasm-opt="2" />

View File

@ -1,8 +1,8 @@
use egui::{Align, Layout, RichText, WidgetText}; //use egui::{Align, Layout, RichText, WidgetText};
use egui_extras::RetainedImage; use egui_extras::RetainedImage;
//use nostr_rust::events::Event; //use nostr_rust::events::Event;
use poll_promise::Promise; use poll_promise::Promise;
use std::borrow::{Borrow, Cow}; //use std::borrow::{Borrow, Cow};
use std::collections::HashMap; use std::collections::HashMap;
use crate::Event; use crate::Event;
@ -16,6 +16,8 @@ pub struct Damus {
// Example stuff: // Example stuff:
label: String, label: String,
n_panels: u32,
#[serde(skip)] #[serde(skip)]
events: Vec<Event>, events: Vec<Event>,
@ -35,6 +37,7 @@ impl Default for Damus {
events: vec![], events: vec![],
img_cache: HashMap::new(), img_cache: HashMap::new(),
value: 2.7, value: 2.7,
n_panels: 1,
} }
} }
} }
@ -82,10 +85,10 @@ fn fetch_img(ctx: &egui::Context, url: &str) -> Promise<ehttp::Result<RetainedIm
promise promise
} }
fn render_pfp(ctx: &egui::Context, img_cache: &mut ImageCache, ui: &mut egui::Ui, url: String) { fn render_pfp(ui: &mut egui::Ui, img_cache: &mut ImageCache, url: String) {
let m_cached_promise = img_cache.get_mut(&url); let m_cached_promise = img_cache.get_mut(&url);
if m_cached_promise.is_none() { if m_cached_promise.is_none() {
img_cache.insert(url.clone(), fetch_img(ctx, &url)); img_cache.insert(url.clone(), fetch_img(ui.ctx(), &url));
} }
match img_cache[&url].ready() { match img_cache[&url].ready() {
@ -110,10 +113,10 @@ fn render_username(ui: &mut egui::Ui, pk: &str) {
}); });
} }
fn render_event(ctx: &egui::Context, img_cache: &mut ImageCache, ui: &mut egui::Ui, ev: &Event) { fn render_event(ui: &mut egui::Ui, img_cache: &mut ImageCache, ev: &Event) {
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| { ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
let damus_pic = "https://damus.io/img/damus.svg".into(); let damus_pic = "https://damus.io/img/damus.svg".into();
let jb55_pic = "http://cdn.jb55.com/img/red-me.jpg".into(); let jb55_pic = "https://damus.io/img/red-me.jpg".into();
let pic = let pic =
if ev.pub_key == "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245" { if ev.pub_key == "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245" {
jb55_pic jb55_pic
@ -121,7 +124,7 @@ fn render_event(ctx: &egui::Context, img_cache: &mut ImageCache, ui: &mut egui::
damus_pic damus_pic
}; };
render_pfp(ctx, img_cache, ui, pic); render_pfp(ui, img_cache, pic);
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| { ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
render_username(ui, &ev.pub_key); render_username(ui, &ev.pub_key);
@ -131,59 +134,76 @@ fn render_event(ctx: &egui::Context, img_cache: &mut ImageCache, ui: &mut egui::
}); });
} }
fn timeline_view(ctx: &egui::Context, app: &mut Damus, ui: &mut egui::Ui) { fn timeline_view(ui: &mut egui::Ui, app: &mut Damus) {
//let row_height = 100_f32;
//let total_rows = app.events.len();
ui.heading("Timeline"); ui.heading("Timeline");
egui::ScrollArea::both().show(ui, |ui| { egui::ScrollArea::vertical()
for ev in &app.events { .auto_shrink([false; 2])
ui.separator(); .show(ui, |ui| {
render_event(ctx, &mut app.img_cache, ui, ev); for ev in &app.events {
} ui.separator();
}); render_event(ui, &mut app.img_cache, ev);
}
/*
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.label("powered by ");
ui.hyperlink_to("egui", "https://github.com/emilk/egui");
ui.label(" and ");
ui.hyperlink_to(
"eframe",
"https://github.com/emilk/egui/tree/master/crates/eframe",
);
ui.label(".");
}); });
});
*/
} }
fn render_damus(ctx: &egui::Context, _frame: &mut eframe::Frame, app: &mut Damus) { fn render_damus(ctx: &egui::Context, _frame: &mut eframe::Frame, app: &mut Damus) {
#[cfg(not(target_arch = "wasm32"))] // no File->Quit on web pages!
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| { egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
// The top panel is often a good place for a menu bar: ui.horizontal_wrapped(|ui| {
egui::menu::bar(ui, |ui| { ui.visuals_mut().button_frame = false;
ui.menu_button("File", |ui| { egui::widgets::global_dark_light_mode_switch(ui);
if ui.button("Quit").clicked() {
_frame.close(); if ui
.add(egui::Button::new("+").frame(false))
.on_hover_text("Add Timeline")
.clicked()
{
app.n_panels += 1;
}
if app.n_panels != 1 {
if ui
.add(egui::Button::new("-").frame(false))
.on_hover_text("Add Timeline")
.clicked()
{
app.n_panels -= 1;
} }
}); }
}); });
}); });
egui::SidePanel::left("side_panel").show(ctx, |ui| timeline_view(ctx, app, ui)); let screen_size = ctx.input().screen_rect.width();
let calc_panel_width = (screen_size / app.n_panels as f32) - 30.0;
let min_width = 300.0;
let need_scroll = calc_panel_width < min_width;
let panel_width = if need_scroll {
min_width
} else {
calc_panel_width
};
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
// The central panel the region left after adding TopPanel's and SidePanel's egui::ScrollArea::horizontal()
.auto_shrink([false; 2])
ui.heading("Damus Desktop"); .show(ui, |ui| {
ui.hyperlink("https://damus.io"); for ind in 0..app.n_panels {
egui::warn_if_debug_build(ui); timeline_panel(ui, app, panel_width, ind);
}
});
}); });
} }
fn timeline_panel(ui: &mut egui::Ui, app: &mut Damus, panel_width: f32, ind: u32) {
egui::SidePanel::left(format!("l{}", ind))
.resizable(false)
.max_width(panel_width)
.min_width(panel_width)
.show_inside(ui, |ui| {
timeline_view(ui, app);
});
}
impl eframe::App for Damus { impl eframe::App for Damus {
/// Called by the frame work to save state before shutdown. /// Called by the frame work to save state before shutdown.
fn save(&mut self, storage: &mut dyn eframe::Storage) { fn save(&mut self, storage: &mut dyn eframe::Storage) {
@ -204,7 +224,7 @@ impl eframe::App for Damus {
created_at: 1667781968, created_at: 1667781968,
kind: 1, kind: 1,
tags: vec![], tags: vec![],
content: "yello\nthere\nbeep\nboop\nyoink".to_string(), content: LOREM_IPSUM.into(),
sig: "af02c971015995f79e07fa98aaf98adeeb6a56d0005e451ee4e78844cff712a6bc0f2109f72a878975f162dcefde4173b65ebd4c3d3ab3b520a9dcac6acf092d".to_string(), sig: "af02c971015995f79e07fa98aaf98adeeb6a56d0005e451ee4e78844cff712a6bc0f2109f72a878975f162dcefde4173b65ebd4c3d3ab3b520a9dcac6acf092d".to_string(),
}; };
@ -214,7 +234,7 @@ impl eframe::App for Damus {
created_at: 1667781968, created_at: 1667781968,
kind: 1, kind: 1,
tags: vec![], tags: vec![],
content: "yo yo\nwhats up\nnotmuch".to_string(), content: LOREM_IPSUM_LONG.into(),
sig: "af02c971015995f79e07fa98aaf98adeeb6a56d0005e451ee4e78844cff712a6bc0f2109f72a878975f162dcefde4173b65ebd4c3d3ab3b520a9dcac6acf092d".to_string(), sig: "af02c971015995f79e07fa98aaf98adeeb6a56d0005e451ee4e78844cff712a6bc0f2109f72a878975f162dcefde4173b65ebd4c3d3ab3b520a9dcac6acf092d".to_string(),
}; };
@ -233,3 +253,9 @@ impl eframe::App for Damus {
render_damus(ctx, _frame, self); render_damus(ctx, _frame, self);
} }
} }
pub const LOREM_IPSUM: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
pub const LOREM_IPSUM_LONG: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Curabitur pretium tincidunt lacus. Nulla gravida orci a odio. Nullam varius, turpis et commodo pharetra, est eros bibendum elit, nec luctus magna felis sollicitudin mauris. Integer in mauris eu nibh euismod gravida. Duis ac tellus et risus vulputate vehicula. Donec lobortis risus a elit. Etiam tempor. Ut ullamcorper, ligula eu tempor congue, eros est euismod turpis, id tincidunt sapien risus a quam. Maecenas fermentum consequat mi. Donec fermentum. Pellentesque malesuada nulla a mi. Duis sapien sem, aliquet nec, commodo eget, consequat quis, neque. Aliquam faucibus, elit ut dictum aliquet, felis nisl adipiscing sapien, sed malesuada diam lacus eget erat. Cras mollis scelerisque nunc. Nullam arcu. Aliquam consequat. Curabitur augue lorem, dapibus quis, laoreet et, pretium ac, nisi. Aenean magna nisl, mollis quis, molestie eu, feugiat in, orci. In hac habitasse platea dictumst.";

View File

@ -1,5 +1,4 @@
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use serde_json::json;
/// Event is the struct used to represent a Nostr event /// Event is the struct used to represent a Nostr event
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]