This splits notedeck into: - notedeck - notedeck_chrome - notedeck_columns The `notedeck` crate is the library that `notedeck_chrome` and `notedeck_columns`, use. It contains common functionality related to notedeck apps such as the NoteCache, ImageCache, etc. The `notedeck_chrome` crate is the binary and ui chrome. It is responsible for managing themes, user accounts, signing, data paths, nostrdb, image caches etc. It will eventually have its own ui which has yet to be determined. For now it just manages the browser data, which is passed to apps via a new struct called `AppContext`. `notedeck_columns` is our columns app, with less responsibility now that more things are handled by `notedeck_chrome` There is still much work left to do before this is a proper browser: - process isolation - sandboxing - etc This is the beginning of a new era! We're just getting started. Signed-off-by: William Casarin <jb55@jb55.com>
96 lines
2.1 KiB
Rust
96 lines
2.1 KiB
Rust
use crate::ui;
|
|
use nostrdb::{Ndb, Transaction};
|
|
use notedeck::ImageCache;
|
|
|
|
pub struct Mention<'a> {
|
|
ndb: &'a Ndb,
|
|
img_cache: &'a mut ImageCache,
|
|
txn: &'a Transaction,
|
|
pk: &'a [u8; 32],
|
|
selectable: bool,
|
|
size: f32,
|
|
}
|
|
|
|
impl<'a> Mention<'a> {
|
|
pub fn new(
|
|
ndb: &'a Ndb,
|
|
img_cache: &'a mut ImageCache,
|
|
txn: &'a Transaction,
|
|
pk: &'a [u8; 32],
|
|
) -> Self {
|
|
let size = 16.0;
|
|
let selectable = true;
|
|
Mention {
|
|
ndb,
|
|
img_cache,
|
|
txn,
|
|
pk,
|
|
selectable,
|
|
size,
|
|
}
|
|
}
|
|
|
|
pub fn selectable(mut self, selectable: bool) -> Self {
|
|
self.selectable = selectable;
|
|
self
|
|
}
|
|
|
|
pub fn size(mut self, size: f32) -> Self {
|
|
self.size = size;
|
|
self
|
|
}
|
|
}
|
|
|
|
impl egui::Widget for Mention<'_> {
|
|
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
|
|
mention_ui(
|
|
self.ndb,
|
|
self.img_cache,
|
|
self.txn,
|
|
self.pk,
|
|
ui,
|
|
self.size,
|
|
self.selectable,
|
|
)
|
|
}
|
|
}
|
|
|
|
fn mention_ui(
|
|
ndb: &Ndb,
|
|
img_cache: &mut ImageCache,
|
|
txn: &Transaction,
|
|
pk: &[u8; 32],
|
|
ui: &mut egui::Ui,
|
|
size: f32,
|
|
selectable: bool,
|
|
) -> egui::Response {
|
|
#[cfg(feature = "profiling")]
|
|
puffin::profile_function!();
|
|
|
|
let link_color = ui.visuals().hyperlink_color;
|
|
|
|
ui.horizontal(|ui| {
|
|
let profile = ndb.get_profile_by_pubkey(txn, pk).ok();
|
|
|
|
let name: String =
|
|
if let Some(name) = profile.as_ref().and_then(crate::profile::get_profile_name) {
|
|
format!("@{}", name.username())
|
|
} else {
|
|
"??".to_string()
|
|
};
|
|
|
|
let resp = ui.add(
|
|
egui::Label::new(egui::RichText::new(name).color(link_color).size(size))
|
|
.selectable(selectable),
|
|
);
|
|
|
|
if let Some(rec) = profile.as_ref() {
|
|
resp.on_hover_ui_at_pointer(|ui| {
|
|
ui.set_max_width(300.0);
|
|
ui.add(ui::ProfilePreview::new(rec, img_cache));
|
|
});
|
|
}
|
|
})
|
|
.response
|
|
}
|