dominus

One damus client to rule them all
git clone git://jb55.com/dominus
Log | Files | Refs | README

commit 8d0bfdfb24bfc538346b5fa2c8f8a1db51da6614
parent 28c5ddbc80500e61af004b5cf9af2e3a8eecd13c
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  7 Nov 2022 00:11:21 -0800

dominus demo

Diffstat:
MTrunk.toml | 3++-
Mindex.html | 2+-
Msrc/app.rs | 118++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Msrc/event.rs | 1-
4 files changed, 75 insertions(+), 49 deletions(-)

diff --git a/Trunk.toml b/Trunk.toml @@ -1,2 +1,3 @@ [build] -filehash = false +filehash = true +public_url = "/webv3/" diff --git a/index.html b/index.html @@ -7,7 +7,7 @@ <head> <!-- 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 --> <link data-trunk rel="rust" data-wasm-opt="2" /> diff --git a/src/app.rs b/src/app.rs @@ -1,8 +1,8 @@ -use egui::{Align, Layout, RichText, WidgetText}; +//use egui::{Align, Layout, RichText, WidgetText}; use egui_extras::RetainedImage; //use nostr_rust::events::Event; use poll_promise::Promise; -use std::borrow::{Borrow, Cow}; +//use std::borrow::{Borrow, Cow}; use std::collections::HashMap; use crate::Event; @@ -16,6 +16,8 @@ pub struct Damus { // Example stuff: label: String, + n_panels: u32, + #[serde(skip)] events: Vec<Event>, @@ -35,6 +37,7 @@ impl Default for Damus { events: vec![], img_cache: HashMap::new(), value: 2.7, + n_panels: 1, } } } @@ -82,10 +85,10 @@ fn fetch_img(ctx: &egui::Context, url: &str) -> Promise<ehttp::Result<RetainedIm 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); 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() { @@ -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| { 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 = if ev.pub_key == "32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245" { jb55_pic @@ -121,7 +124,7 @@ fn render_event(ctx: &egui::Context, img_cache: &mut ImageCache, ui: &mut egui:: 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| { 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) { - //let row_height = 100_f32; - //let total_rows = app.events.len(); +fn timeline_view(ui: &mut egui::Ui, app: &mut Damus) { ui.heading("Timeline"); - egui::ScrollArea::both().show(ui, |ui| { - for ev in &app.events { - ui.separator(); - render_event(ctx, &mut app.img_cache, ui, 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("."); + egui::ScrollArea::vertical() + .auto_shrink([false; 2]) + .show(ui, |ui| { + for ev in &app.events { + ui.separator(); + render_event(ui, &mut app.img_cache, ev); + } }); - }); - */ } 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| { - // The top panel is often a good place for a menu bar: - egui::menu::bar(ui, |ui| { - ui.menu_button("File", |ui| { - if ui.button("Quit").clicked() { - _frame.close(); + ui.horizontal_wrapped(|ui| { + ui.visuals_mut().button_frame = false; + egui::widgets::global_dark_light_mode_switch(ui); + + 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| { - // The central panel the region left after adding TopPanel's and SidePanel's - - ui.heading("Damus Desktop"); - ui.hyperlink("https://damus.io"); - egui::warn_if_debug_build(ui); + egui::ScrollArea::horizontal() + .auto_shrink([false; 2]) + .show(ui, |ui| { + for ind in 0..app.n_panels { + 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 { /// Called by the frame work to save state before shutdown. fn save(&mut self, storage: &mut dyn eframe::Storage) { @@ -204,7 +224,7 @@ impl eframe::App for Damus { created_at: 1667781968, kind: 1, tags: vec![], - content: "yello\nthere\nbeep\nboop\nyoink".to_string(), + content: LOREM_IPSUM.into(), sig: "af02c971015995f79e07fa98aaf98adeeb6a56d0005e451ee4e78844cff712a6bc0f2109f72a878975f162dcefde4173b65ebd4c3d3ab3b520a9dcac6acf092d".to_string(), }; @@ -214,7 +234,7 @@ impl eframe::App for Damus { created_at: 1667781968, kind: 1, tags: vec![], - content: "yo yo\nwhats up\nnotmuch".to_string(), + content: LOREM_IPSUM_LONG.into(), sig: "af02c971015995f79e07fa98aaf98adeeb6a56d0005e451ee4e78844cff712a6bc0f2109f72a878975f162dcefde4173b65ebd4c3d3ab3b520a9dcac6acf092d".to_string(), }; @@ -233,3 +253,9 @@ impl eframe::App for Damus { 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."; diff --git a/src/event.rs b/src/event.rs @@ -1,5 +1,4 @@ use serde_derive::{Deserialize, Serialize}; -use serde_json::json; /// Event is the struct used to represent a Nostr event #[derive(Serialize, Deserialize, Debug, Clone)]