notedeck

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

commit f12ccc69a44bdcab0dd698271676dec4e97f058e
parent 7ec31d0eaee2aa816d4a40f5ec8a6ad4646b6570
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 24 Apr 2024 11:00:47 -0700

add hover to profile map demo

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
MCargo.lock | 2+-
MCargo.toml | 2+-
Msrc/ui/profile/picture.rs | 53+++++++++++++++++++++++++++++++++++++++++++----------
Msrc/ui_preview/main.rs | 11+++++++++--
4 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -2557,7 +2557,7 @@ dependencies = [ [[package]] name = "nostrdb" version = "0.3.2" -source = "git+https://github.com/damus-io/nostrdb-rs?rev=01d8bee4fea6e2e8f6bc3e4e6e3c989e43defe4b#01d8bee4fea6e2e8f6bc3e4e6e3c989e43defe4b" +source = "git+https://github.com/damus-io/nostrdb-rs?rev=1489a5aee49996d8a6a54b4c3c9c8397e3e8d40f#1489a5aee49996d8a6a54b4c3c9c8397e3e8d40f" dependencies = [ "bindgen", "cc", diff --git a/Cargo.toml b/Cargo.toml @@ -31,7 +31,7 @@ serde_json = "1.0.89" env_logger = "0.10.0" puffin_egui = { version = "0.27.0", optional = true } puffin = { version = "0.19.0", optional = true } -nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "01d8bee4fea6e2e8f6bc3e4e6e3c989e43defe4b" } +nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "1489a5aee49996d8a6a54b4c3c9c8397e3e8d40f" } #nostrdb = "0.3.2" hex = "0.4.3" base32 = "0.4.0" diff --git a/src/ui/profile/picture.rs b/src/ui/profile/picture.rs @@ -100,12 +100,14 @@ fn paint_circle(ui: &mut egui::Ui, size: f32) -> egui::Response { mod preview { use super::*; + use crate::ui; use nostrdb::*; use std::collections::HashSet; pub struct ProfilePicPreview { cache: ImageCache, - urls: Vec<String>, + ndb: Ndb, + keys: Vec<ProfileKey>, } impl ProfilePicPreview { @@ -116,9 +118,9 @@ mod preview { let filters = vec![Filter::new().kinds(vec![0]).build()]; let cache = ImageCache::new("cache/img".into()); let mut pks = HashSet::new(); - let mut urls = HashSet::new(); + let mut keys = HashSet::new(); - for query_result in ndb.query(&txn, filters, 1000).unwrap() { + for query_result in ndb.query(&txn, filters, 2000).unwrap() { pks.insert(query_result.note.pubkey()); } @@ -128,22 +130,53 @@ mod preview { } else { continue; }; - if let Some(url) = profile.record().profile().and_then(|p| p.picture()) { - urls.insert(url.to_string()); + + if profile + .record() + .profile() + .and_then(|p| p.picture()) + .is_none() + { + continue; } - } - let urls = urls.into_iter().collect(); + keys.insert(profile.key().expect("should not be owned")); + } - ProfilePicPreview { cache, urls } + let keys = keys.into_iter().collect(); + ProfilePicPreview { cache, ndb, keys } } } impl View for ProfilePicPreview { fn ui(&mut self, ui: &mut egui::Ui) { ui.horizontal_wrapped(|ui| { - for url in &self.urls { - ui.add(ProfilePic::new(&mut self.cache, &url)); + let txn = Transaction::new(&self.ndb).unwrap(); + for key in &self.keys { + let profile = self.ndb.get_profile_by_key(&txn, *key).unwrap(); + let url = profile + .record() + .profile() + .expect("should have profile") + .picture() + .expect("should have picture"); + + let expand_size = 10.0; + let anim_speed = 0.05; + + let (rect, size) = ui::anim::hover_expand( + ui, + egui::Id::new(profile.key().unwrap()), + ui::ProfilePic::default_size(), + expand_size, + anim_speed, + ); + + ui.put(rect, ui::ProfilePic::new(&mut self.cache, url).size(size)) + .on_hover_ui_at_pointer(|ui| { + ui.set_max_width(300.0); + ui.add(ui::ProfilePreview::new(&profile, &mut self.cache)); + }); } }); } diff --git a/src/ui_preview/main.rs b/src/ui_preview/main.rs @@ -2,7 +2,7 @@ use notedeck::account_login_view::AccountLoginView; use notedeck::app_creation::{ generate_mobile_emulator_native_options, generate_native_options, setup_cc, }; -use notedeck::ui::{Preview, PreviewApp, ProfilePreview, RelayView, ProfilePic}; +use notedeck::ui::{Preview, PreviewApp, ProfilePic, ProfilePreview, RelayView}; use std::env; struct PreviewRunner { @@ -73,5 +73,12 @@ async fn main() { let runner = PreviewRunner::new(is_mobile); - previews!(runner, name, RelayView, AccountLoginView, ProfilePreview, ProfilePic); + previews!( + runner, + name, + RelayView, + AccountLoginView, + ProfilePreview, + ProfilePic + ); }