hitbox: cache note size instead of rect
This commit is contained in:
committed by
William Casarin
parent
c25fde4a06
commit
21298b43f5
@@ -20,6 +20,7 @@ use crate::{
|
|||||||
notecache::{CachedNote, NoteCache},
|
notecache::{CachedNote, NoteCache},
|
||||||
ui::{self, View},
|
ui::{self, View},
|
||||||
};
|
};
|
||||||
|
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::NoteId;
|
use enostr::NoteId;
|
||||||
use nostrdb::{Ndb, Note, NoteKey, NoteReply, Transaction};
|
use nostrdb::{Ndb, Note, NoteKey, NoteReply, Transaction};
|
||||||
@@ -584,19 +585,22 @@ fn get_reposted_note<'a>(ndb: &Ndb, txn: &'a Transaction, note: &Note) -> Option
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn note_hitbox_id(note_key: NoteKey) -> egui::Id {
|
fn note_hitbox_id(note_key: NoteKey) -> egui::Id {
|
||||||
Id::new(("note_rect", note_key))
|
Id::new(("note_size", note_key))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_note_hitbox(ui: &mut egui::Ui, note_key: NoteKey) -> Option<Response> {
|
fn maybe_note_hitbox(ui: &mut egui::Ui, note_key: NoteKey) -> Option<Response> {
|
||||||
ui.ctx()
|
ui.ctx()
|
||||||
.data_mut(|d| d.get_persisted(note_hitbox_id(note_key)))
|
.data_mut(|d| d.get_persisted(note_hitbox_id(note_key)))
|
||||||
.map(|mut rect: Rect| {
|
.map(|note_size: Vec2| {
|
||||||
let id = ui.make_persistent_id(("hitbox_interact", note_key));
|
let id = ui.make_persistent_id(("hitbox_interact", note_key));
|
||||||
|
|
||||||
// Extend the hitbox to the full width of the container
|
// The hitbox should extend the entire width of the
|
||||||
|
// container. The hitbox height was cached last layout.
|
||||||
let container_rect = ui.max_rect();
|
let container_rect = ui.max_rect();
|
||||||
rect.min.x = container_rect.min.x;
|
let rect = Rect {
|
||||||
rect.max.x = container_rect.max.x;
|
min: pos2(container_rect.min.x, container_rect.min.y),
|
||||||
|
max: pos2(container_rect.max.x, container_rect.min.y + note_size.y),
|
||||||
|
};
|
||||||
|
|
||||||
ui.interact(rect, id, egui::Sense::click())
|
ui.interact(rect, id, egui::Sense::click())
|
||||||
})
|
})
|
||||||
@@ -613,7 +617,7 @@ fn check_note_hitbox(
|
|||||||
// Stash the dimensions of the note content so we can render the
|
// Stash the dimensions of the note content so we can render the
|
||||||
// hitbox in the next frame
|
// hitbox in the next frame
|
||||||
ui.ctx().data_mut(|d| {
|
ui.ctx().data_mut(|d| {
|
||||||
d.insert_persisted(note_hitbox_id(note_key), note_response.rect);
|
d.insert_persisted(note_hitbox_id(note_key), note_response.rect.size());
|
||||||
});
|
});
|
||||||
|
|
||||||
// If there was an hitbox and it was clicked open the thread
|
// If there was an hitbox and it was clicked open the thread
|
||||||
|
|||||||
Reference in New Issue
Block a user