mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-17 16:54:18 +01:00
note: cleanup wide/standard implementation
Since this function was getting too big
This commit is contained in:
@@ -20,7 +20,7 @@ pub use reply_description::reply_desc;
|
|||||||
use egui::emath::{pos2, Vec2};
|
use egui::emath::{pos2, Vec2};
|
||||||
use egui::{Id, Label, Pos2, Rect, Response, RichText, Sense};
|
use egui::{Id, Label, Pos2, Rect, Response, RichText, Sense};
|
||||||
use enostr::{KeypairUnowned, NoteId, Pubkey};
|
use enostr::{KeypairUnowned, NoteId, Pubkey};
|
||||||
use nostrdb::{Ndb, Note, NoteKey, Transaction};
|
use nostrdb::{Ndb, Note, NoteKey, ProfileRecord, Transaction};
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
name::get_display_name,
|
name::get_display_name,
|
||||||
note::{NoteAction, NoteContext, ZapAction},
|
note::{NoteAction, NoteContext, ZapAction},
|
||||||
@@ -387,29 +387,21 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[profiling::function]
|
fn wide_ui(
|
||||||
fn show_standard(&mut self, ui: &mut egui::Ui) -> NoteResponse {
|
&mut self,
|
||||||
let note_key = self.note.key().expect("todo: support non-db notes");
|
ui: &mut egui::Ui,
|
||||||
let txn = self.note.txn().expect("todo: support non-db notes");
|
txn: &Transaction,
|
||||||
|
note_key: NoteKey,
|
||||||
let mut note_action: Option<NoteAction> = None;
|
profile: &Result<ProfileRecord, nostrdb::Error>,
|
||||||
|
note_action: &mut Option<NoteAction>,
|
||||||
let hitbox_id = note_hitbox_id(note_key, self.options(), self.parent);
|
) -> Response {
|
||||||
let profile = self
|
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
||||||
.note_context
|
|
||||||
.ndb
|
|
||||||
.get_profile_by_pubkey(txn, self.note.pubkey());
|
|
||||||
let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
|
|
||||||
|
|
||||||
// wide design
|
|
||||||
let response = if self.options().has_wide() {
|
|
||||||
ui.vertical(|ui| {
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let (pfp_resp, action) = self.pfp(note_key, &profile, ui);
|
let (pfp_resp, action) = self.pfp(note_key, profile, ui);
|
||||||
if pfp_resp.clicked() {
|
if pfp_resp.clicked() {
|
||||||
note_action = Some(NoteAction::Profile(Pubkey::new(*self.note.pubkey())));
|
*note_action = Some(NoteAction::Profile(Pubkey::new(*self.note.pubkey())));
|
||||||
} else if let Some(action) = action {
|
} else if let Some(action) = action {
|
||||||
note_action = Some(NoteAction::Media(action));
|
*note_action = Some(NoteAction::Media(action));
|
||||||
};
|
};
|
||||||
|
|
||||||
let size = ui.available_size();
|
let size = ui.available_size();
|
||||||
@@ -422,7 +414,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
ui,
|
ui,
|
||||||
self.note_context.note_cache,
|
self.note_context.note_cache,
|
||||||
self.note,
|
self.note,
|
||||||
&profile,
|
profile,
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.response
|
.response
|
||||||
@@ -452,7 +444,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
.inner;
|
.inner;
|
||||||
|
|
||||||
if action.is_some() {
|
if action.is_some() {
|
||||||
note_action = action;
|
*note_action = action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -470,7 +462,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
ui.add(&mut contents);
|
ui.add(&mut contents);
|
||||||
|
|
||||||
if let Some(action) = contents.action {
|
if let Some(action) = contents.action {
|
||||||
note_action = Some(action);
|
*note_action = Some(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.options().has_actionbar() {
|
if self.options().has_actionbar() {
|
||||||
@@ -486,23 +478,32 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
)
|
)
|
||||||
.inner
|
.inner
|
||||||
{
|
{
|
||||||
note_action = Some(action);
|
*note_action = Some(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.response
|
.response
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
fn standard_ui(
|
||||||
|
&mut self,
|
||||||
|
ui: &mut egui::Ui,
|
||||||
|
txn: &Transaction,
|
||||||
|
note_key: NoteKey,
|
||||||
|
profile: &Result<ProfileRecord, nostrdb::Error>,
|
||||||
|
note_action: &mut Option<NoteAction>,
|
||||||
|
) -> Response {
|
||||||
// main design
|
// main design
|
||||||
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 (pfp_resp, action) = self.pfp(note_key, &profile, ui);
|
let (pfp_resp, action) = self.pfp(note_key, profile, ui);
|
||||||
if pfp_resp.clicked() {
|
if pfp_resp.clicked() {
|
||||||
note_action = Some(NoteAction::Profile(Pubkey::new(*self.note.pubkey())));
|
*note_action = Some(NoteAction::Profile(Pubkey::new(*self.note.pubkey())));
|
||||||
} else if let Some(action) = action {
|
} else if let Some(action) = action {
|
||||||
note_action = Some(NoteAction::Media(action));
|
*note_action = Some(NoteAction::Media(action));
|
||||||
};
|
};
|
||||||
|
|
||||||
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
|
||||||
NoteView::note_header(ui, self.note_context.note_cache, self.note, &profile);
|
NoteView::note_header(ui, self.note_context.note_cache, self.note, profile);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.spacing_mut().item_spacing.x = 2.0;
|
ui.spacing_mut().item_spacing.x = 2.0;
|
||||||
|
|
||||||
@@ -525,7 +526,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if action.is_some() {
|
if action.is_some() {
|
||||||
note_action = action;
|
*note_action = action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -541,7 +542,7 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
ui.add(&mut contents);
|
ui.add(&mut contents);
|
||||||
|
|
||||||
if let Some(action) = contents.action {
|
if let Some(action) = contents.action {
|
||||||
note_action = Some(action);
|
*note_action = Some(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.options().has_actionbar() {
|
if self.options().has_actionbar() {
|
||||||
@@ -557,12 +558,31 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
)
|
)
|
||||||
.inner
|
.inner
|
||||||
{
|
{
|
||||||
note_action = Some(action);
|
*note_action = Some(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.response
|
.response
|
||||||
|
}
|
||||||
|
|
||||||
|
#[profiling::function]
|
||||||
|
fn show_standard(&mut self, ui: &mut egui::Ui) -> NoteResponse {
|
||||||
|
let note_key = self.note.key().expect("todo: support non-db notes");
|
||||||
|
let txn = self.note.txn().expect("todo: support non-db notes");
|
||||||
|
|
||||||
|
let mut note_action: Option<NoteAction> = None;
|
||||||
|
|
||||||
|
let profile = self
|
||||||
|
.note_context
|
||||||
|
.ndb
|
||||||
|
.get_profile_by_pubkey(txn, self.note.pubkey());
|
||||||
|
|
||||||
|
// wide design
|
||||||
|
let response = if self.options().has_wide() {
|
||||||
|
self.wide_ui(ui, txn, note_key, &profile, &mut note_action)
|
||||||
|
} else {
|
||||||
|
self.standard_ui(ui, txn, note_key, &profile, &mut note_action)
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.options().has_options_button() {
|
if self.options().has_options_button() {
|
||||||
@@ -579,6 +599,8 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let hitbox_id = note_hitbox_id(note_key, self.options(), self.parent);
|
||||||
|
let maybe_hitbox = maybe_note_hitbox(ui, hitbox_id);
|
||||||
let note_action = if note_hitbox_clicked(ui, hitbox_id, &response.rect, maybe_hitbox) {
|
let note_action = if note_hitbox_clicked(ui, hitbox_id, &response.rect, maybe_hitbox) {
|
||||||
Some(NoteAction::Note(NoteId::new(*self.note.id())))
|
Some(NoteAction::Note(NoteId::new(*self.note.id())))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user