hitbox: handle hits on quoted notes correctly

This commit is contained in:
Ken Sedgwick 2024-09-24 14:54:12 -07:00 committed by William Casarin
parent 5b7c9c9234
commit c25fde4a06
2 changed files with 41 additions and 29 deletions

View File

@ -1,7 +1,8 @@
use crate::actionbar::BarAction;
use crate::images::ImageType;
use crate::imgcache::ImageCache;
use crate::notecache::NoteCache;
use crate::ui::note::NoteOptions;
use crate::ui::note::{NoteOptions, NoteResponse};
use crate::ui::ProfilePic;
use crate::{colors, ui};
use egui::{Color32, Hyperlink, Image, RichText};
@ -16,6 +17,7 @@ pub struct NoteContents<'a> {
note: &'a Note<'a>,
note_key: NoteKey,
options: NoteOptions,
action: Option<BarAction>,
}
impl<'a> NoteContents<'a> {
@ -36,13 +38,18 @@ impl<'a> NoteContents<'a> {
note,
note_key,
options,
action: None,
}
}
pub fn action(&self) -> Option<BarAction> {
self.action
}
}
impl egui::Widget for NoteContents<'_> {
impl egui::Widget for &mut NoteContents<'_> {
fn ui(self, ui: &mut egui::Ui) -> egui::Response {
render_note_contents(
let result = render_note_contents(
ui,
self.ndb,
self.img_cache,
@ -51,8 +58,9 @@ impl egui::Widget for NoteContents<'_> {
self.note,
self.note_key,
self.options,
)
.response
);
self.action = result.action;
result.response
}
}
@ -66,7 +74,7 @@ pub fn render_note_preview(
txn: &Transaction,
id: &[u8; 32],
_id_str: &str,
) -> egui::Response {
) -> NoteResponse {
#[cfg(feature = "profiling")]
puffin::profile_function!();
@ -75,13 +83,13 @@ pub fn render_note_preview(
if note.kind() == 1 {
note
} else {
return ui.colored_label(
return NoteResponse::new(ui.colored_label(
Color32::RED,
format!("TODO: can't preview kind {}", note.kind()),
);
));
}
} else {
return ui.colored_label(Color32::RED, "TODO: COULD NOT LOAD");
return NoteResponse::new(ui.colored_label(Color32::RED, "TODO: COULD NOT LOAD"));
/*
return ui
.horizontal(|ui| {
@ -103,19 +111,15 @@ pub fn render_note_preview(
ui.visuals().noninteractive().bg_stroke.color,
))
.show(ui, |ui| {
let resp = ui::NoteView::new(ndb, note_cache, img_cache, &note)
ui::NoteView::new(ndb, note_cache, img_cache, &note)
.actionbar(false)
.small_pfp(true)
.wide(true)
.note_previews(false)
.options_button(true)
.show(ui);
if let Some(context) = resp.context_selection {
context.process(ui, &note);
}
.show(ui)
})
.response
.inner
}
#[allow(clippy::too_many_arguments)]
@ -128,7 +132,7 @@ fn render_note_contents(
note: &Note,
note_key: NoteKey,
options: NoteOptions,
) -> egui::InnerResponse<()> {
) -> NoteResponse {
#[cfg(feature = "profiling")]
puffin::profile_function!();
@ -136,7 +140,7 @@ fn render_note_contents(
let mut images: Vec<String> = vec![];
let mut inline_note: Option<(&[u8; 32], &str)> = None;
let resp = ui.horizontal_wrapped(|ui| {
let response = ui.horizontal_wrapped(|ui| {
let blocks = if let Ok(blocks) = ndb.get_blocks_by_key(txn, note_key) {
blocks
} else {
@ -204,9 +208,11 @@ fn render_note_contents(
}
});
if let Some((id, block_str)) = inline_note {
render_note_preview(ui, ndb, note_cache, img_cache, txn, id, block_str);
}
let note_action = if let Some((id, block_str)) = inline_note {
render_note_preview(ui, ndb, note_cache, img_cache, txn, id, block_str).action
} else {
None
};
if !images.is_empty() && !options.has_textmode() {
ui.add_space(2.0);
@ -215,7 +221,7 @@ fn render_note_contents(
ui.add_space(2.0);
}
resp
NoteResponse::new(response.response).with_action(note_action)
}
fn image_carousel(

View File

@ -281,7 +281,7 @@ impl<'a> NoteView<'a> {
)
});
ui.add(NoteContents::new(
ui.add(&mut NoteContents::new(
self.ndb,
self.img_cache,
self.note_cache,
@ -476,7 +476,7 @@ impl<'a> NoteView<'a> {
});
});
let resp = ui.add(NoteContents::new(
let mut contents = NoteContents::new(
self.ndb,
self.img_cache,
self.note_cache,
@ -484,10 +484,13 @@ impl<'a> NoteView<'a> {
self.note,
note_key,
self.options(),
));
);
let resp = ui.add(&mut contents);
note_action = note_action.or(contents.action());
if self.options().has_actionbar() {
note_action = render_note_actionbar(ui, self.note.id(), note_key).inner;
let ab = render_note_actionbar(ui, self.note.id(), note_key);
note_action = note_action.or(ab.inner);
}
resp
@ -520,7 +523,7 @@ impl<'a> NoteView<'a> {
}
});
ui.add(NoteContents::new(
let mut contents = NoteContents::new(
self.ndb,
self.img_cache,
self.note_cache,
@ -528,10 +531,13 @@ impl<'a> NoteView<'a> {
self.note,
note_key,
self.options(),
));
);
ui.add(&mut contents);
note_action = note_action.or(contents.action());
if self.options().has_actionbar() {
note_action = render_note_actionbar(ui, self.note.id(), note_key).inner;
let ab = render_note_actionbar(ui, self.note.id(), note_key);
note_action = note_action.or(ab.inner);
}
});
})