notes: rename "underbutt" to "hitbox"

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-09-17 15:12:20 -07:00
parent fea315cb99
commit e16eeb4d1b

View File

@@ -384,8 +384,7 @@ impl<'a> NoteView<'a> {
let txn = self.note.txn().expect("todo: support non-db notes"); let txn = self.note.txn().expect("todo: support non-db notes");
let mut note_action: Option<BarAction> = None; let mut note_action: Option<BarAction> = None;
let profile = self.ndb.get_profile_by_pubkey(txn, self.note.pubkey()); let profile = self.ndb.get_profile_by_pubkey(txn, self.note.pubkey());
let maybe_hitbox = maybe_note_hitbox(ui, note_key);
let maybe_underbutt = maybe_note_underbutton(ui, note_key);
// wide design // wide design
let response = if self.options().has_wide() { let response = if self.options().has_wide() {
@@ -470,12 +469,12 @@ impl<'a> NoteView<'a> {
.response .response
}; };
note_action = check_note_underbutton( note_action = check_note_hitbox(
ui, ui,
self.note.id(), self.note.id(),
note_key, note_key,
&response, &response,
maybe_underbutt, maybe_hitbox,
note_action, note_action,
); );
@@ -510,35 +509,35 @@ fn get_reposted_note<'a>(ndb: &Ndb, txn: &'a Transaction, note: &Note) -> Option
note.filter(|note| note.kind() == 1) note.filter(|note| note.kind() == 1)
} }
fn maybe_note_underbutton(ui: &mut egui::Ui, note_key: NoteKey) -> Option<Response> { fn note_hitbox_id(note_key: NoteKey) -> egui::Id {
let underbuttid = Id::new(("note_rect", note_key)); Id::new(("note_rect", note_key))
let maybe_underbutt = ui }
.ctx()
.data_mut(|d| d.get_persisted(underbuttid)) fn maybe_note_hitbox(ui: &mut egui::Ui, note_key: NoteKey) -> Option<Response> {
ui.ctx()
.data_mut(|d| d.get_persisted(note_hitbox_id(note_key)))
.map(|rect| { .map(|rect| {
let id = ui.make_persistent_id(("under_button_interact", note_key)); let id = ui.make_persistent_id(("under_button_interact", note_key));
ui.interact(rect, id, egui::Sense::click()) ui.interact(rect, id, egui::Sense::click())
}); })
maybe_underbutt
} }
fn check_note_underbutton( fn check_note_hitbox(
ui: &mut egui::Ui, ui: &mut egui::Ui,
note_id: &[u8; 32], note_id: &[u8; 32],
note_key: NoteKey, note_key: NoteKey,
note_response: &Response, note_response: &Response,
maybe_underbutt: Option<Response>, maybe_hitbox: Option<Response>,
prior_action: Option<BarAction>, prior_action: Option<BarAction>,
) -> Option<BarAction> { ) -> Option<BarAction> {
// Stash the dimensions of the note content so we can render the // Stash the dimensions of the note content so we can render the
// underbutton in the next frame // underbutton in the next frame
let underbuttid = Id::new(("note_rect", note_key));
ui.ctx().data_mut(|d| { ui.ctx().data_mut(|d| {
d.insert_persisted(underbuttid, note_response.rect); d.insert_persisted(note_hitbox_id(note_key), note_response.rect);
}); });
// If there was an underbutton and it was clicked open the thread // If there was an underbutton and it was clicked open the thread
match maybe_underbutt { match maybe_hitbox {
Some(underbutt) if underbutt.clicked() => { Some(underbutt) if underbutt.clicked() => {
Some(BarAction::OpenThread(NoteId::new(*note_id))) Some(BarAction::OpenThread(NoteId::new(*note_id)))
} }