@@ -39,6 +39,7 @@ pub struct NoteResponse {
|
||||
pub response: egui::Response,
|
||||
pub action: Option<BarAction>,
|
||||
pub context_selection: Option<NoteContextSelection>,
|
||||
pub clicked_profile: bool,
|
||||
}
|
||||
|
||||
impl NoteResponse {
|
||||
@@ -47,6 +48,7 @@ impl NoteResponse {
|
||||
response,
|
||||
action: None,
|
||||
context_selection: None,
|
||||
clicked_profile: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +62,13 @@ impl NoteResponse {
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn click_profile(self, clicked_profile: bool) -> Self {
|
||||
Self {
|
||||
clicked_profile,
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> View for NoteView<'a> {
|
||||
@@ -305,7 +314,7 @@ impl<'a> NoteView<'a> {
|
||||
note_key: NoteKey,
|
||||
profile: &Result<nostrdb::ProfileRecord<'_>, nostrdb::Error>,
|
||||
ui: &mut egui::Ui,
|
||||
) {
|
||||
) -> egui::Response {
|
||||
if !self.options().has_wide() {
|
||||
ui.spacing_mut().item_spacing.x = 16.0;
|
||||
} else {
|
||||
@@ -314,6 +323,7 @@ impl<'a> NoteView<'a> {
|
||||
|
||||
let pfp_size = self.options().pfp_size();
|
||||
|
||||
let sense = Sense::click();
|
||||
match profile
|
||||
.as_ref()
|
||||
.ok()
|
||||
@@ -326,7 +336,7 @@ impl<'a> NoteView<'a> {
|
||||
let profile_key = profile.as_ref().unwrap().record().note_key();
|
||||
let note_key = note_key.as_u64();
|
||||
|
||||
let (rect, size, _resp) = ui::anim::hover_expand(
|
||||
let (rect, size, resp) = ui::anim::hover_expand(
|
||||
ui,
|
||||
egui::Id::new((profile_key, note_key)),
|
||||
pfp_size,
|
||||
@@ -342,13 +352,14 @@ impl<'a> NoteView<'a> {
|
||||
self.img_cache,
|
||||
));
|
||||
});
|
||||
resp
|
||||
}
|
||||
None => {
|
||||
ui.add(
|
||||
None => ui
|
||||
.add(
|
||||
ui::ProfilePic::new(self.img_cache, ui::ProfilePic::no_pfp_url())
|
||||
.size(pfp_size),
|
||||
);
|
||||
}
|
||||
)
|
||||
.interact(sense),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -441,10 +452,12 @@ impl<'a> NoteView<'a> {
|
||||
Pos2::new(x, y)
|
||||
};
|
||||
|
||||
let mut clicked_profile = false;
|
||||
|
||||
// wide design
|
||||
let response = if self.options().has_wide() {
|
||||
ui.horizontal(|ui| {
|
||||
self.pfp(note_key, &profile, ui);
|
||||
clicked_profile = self.pfp(note_key, &profile, ui).clicked();
|
||||
|
||||
let size = ui.available_size();
|
||||
ui.vertical(|ui| {
|
||||
@@ -498,7 +511,7 @@ impl<'a> NoteView<'a> {
|
||||
} else {
|
||||
// main design
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| {
|
||||
self.pfp(note_key, &profile, ui);
|
||||
clicked_profile = self.pfp(note_key, &profile, ui).clicked();
|
||||
|
||||
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
||||
selected_option = NoteView::note_header(
|
||||
@@ -557,6 +570,7 @@ impl<'a> NoteView<'a> {
|
||||
NoteResponse::new(response)
|
||||
.with_action(note_action)
|
||||
.select_option(selected_option)
|
||||
.click_profile(clicked_profile)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,57 @@
|
||||
pub mod picture;
|
||||
pub mod preview;
|
||||
|
||||
use egui::{Label, RichText};
|
||||
use nostrdb::Ndb;
|
||||
pub use picture::ProfilePic;
|
||||
pub use preview::ProfilePreview;
|
||||
use tracing::info;
|
||||
|
||||
use crate::{
|
||||
actionbar::TimelineResponse, column::Columns, imgcache::ImageCache, notecache::NoteCache,
|
||||
timeline::TimelineId,
|
||||
};
|
||||
|
||||
use super::TimelineView;
|
||||
|
||||
pub struct ProfileView<'a> {
|
||||
timeline_id: TimelineId,
|
||||
columns: &'a mut Columns,
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut ImageCache,
|
||||
}
|
||||
|
||||
impl<'a> ProfileView<'a> {
|
||||
pub fn new(
|
||||
timeline_id: TimelineId,
|
||||
columns: &'a mut Columns,
|
||||
ndb: &'a Ndb,
|
||||
note_cache: &'a mut NoteCache,
|
||||
img_cache: &'a mut ImageCache,
|
||||
) -> Self {
|
||||
ProfileView {
|
||||
timeline_id,
|
||||
columns,
|
||||
ndb,
|
||||
note_cache,
|
||||
img_cache,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) -> TimelineResponse {
|
||||
ui.add(Label::new(
|
||||
RichText::new("PROFILE VIEW").text_style(egui::TextStyle::Heading),
|
||||
));
|
||||
|
||||
TimelineView::new(
|
||||
self.timeline_id,
|
||||
self.columns,
|
||||
self.ndb,
|
||||
self.note_cache,
|
||||
self.img_cache,
|
||||
false,
|
||||
)
|
||||
.ui(ui)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::actionbar::TimelineResponse;
|
||||
use crate::{
|
||||
actionbar::BarAction, column::Columns, imgcache::ImageCache, notecache::NoteCache,
|
||||
timeline::TimelineId, ui,
|
||||
@@ -5,8 +6,9 @@ use crate::{
|
||||
use egui::containers::scroll_area::ScrollBarVisibility;
|
||||
use egui::{Direction, Layout};
|
||||
use egui_tabs::TabColor;
|
||||
use enostr::Pubkey;
|
||||
use nostrdb::{Ndb, Transaction};
|
||||
use tracing::{debug, error, warn};
|
||||
use tracing::{debug, error, info, warn};
|
||||
|
||||
pub struct TimelineView<'a> {
|
||||
timeline_id: TimelineId,
|
||||
@@ -39,7 +41,7 @@ impl<'a> TimelineView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) -> Option<BarAction> {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) -> TimelineResponse {
|
||||
timeline_ui(
|
||||
ui,
|
||||
self.ndb,
|
||||
@@ -68,7 +70,7 @@ fn timeline_ui(
|
||||
img_cache: &mut ImageCache,
|
||||
reversed: bool,
|
||||
textmode: bool,
|
||||
) -> Option<BarAction> {
|
||||
) -> TimelineResponse {
|
||||
//padding(4.0, ui, |ui| ui.heading("Notifications"));
|
||||
/*
|
||||
let font_id = egui::TextStyle::Body.resolve(ui.style());
|
||||
@@ -83,7 +85,7 @@ fn timeline_ui(
|
||||
error!("tried to render timeline in column, but timeline was missing");
|
||||
// TODO (jb55): render error when timeline is missing?
|
||||
// this shouldn't happen...
|
||||
return None;
|
||||
return TimelineResponse::default();
|
||||
};
|
||||
|
||||
timeline.selected_view = tabs_ui(ui);
|
||||
@@ -94,6 +96,7 @@ fn timeline_ui(
|
||||
egui::Id::new(("tlscroll", timeline.view_id()))
|
||||
};
|
||||
|
||||
let mut open_profile: Option<Pubkey> = None;
|
||||
let mut bar_action: Option<BarAction> = None;
|
||||
egui::ScrollArea::vertical()
|
||||
.id_source(scroll_id)
|
||||
@@ -157,6 +160,11 @@ fn timeline_ui(
|
||||
if let Some(context) = resp.context_selection {
|
||||
context.process(ui, ¬e);
|
||||
}
|
||||
|
||||
if resp.clicked_profile {
|
||||
info!("clicked profile");
|
||||
open_profile = Some(Pubkey::new(*note.pubkey()))
|
||||
}
|
||||
});
|
||||
|
||||
ui::hline(ui);
|
||||
@@ -168,7 +176,10 @@ fn timeline_ui(
|
||||
1
|
||||
});
|
||||
|
||||
bar_action
|
||||
TimelineResponse {
|
||||
open_profile,
|
||||
bar_action,
|
||||
}
|
||||
}
|
||||
|
||||
fn tabs_ui(ui: &mut egui::Ui) -> i32 {
|
||||
|
||||
Reference in New Issue
Block a user