Remember heights of rendered posts, use for more accurate scrolling

This commit is contained in:
Mike Dilger 2023-02-17 12:28:01 +13:00
parent a19f94e5f0
commit e62633f7e8
2 changed files with 14 additions and 3 deletions

View File

@ -172,13 +172,16 @@ fn render_post_maybe_fake(
// If too far off of the screen, don't actually render the post, just make some space // If too far off of the screen, don't actually render the post, just make some space
// so the scrollbar isn't messed up // so the scrollbar isn't messed up
let estimated_height = estimate_height(&event, maybe_person); let height = match app.height.get(&id) {
Some(h) => *h,
None => estimate_height(&event, maybe_person),
};
let after_the_bottom = pos2.y > screen_rect.max.y; let after_the_bottom = pos2.y > screen_rect.max.y;
let before_the_top = pos2.y + estimated_height < 0.0; let before_the_top = pos2.y + height < 0.0;
if after_the_bottom || before_the_top { if after_the_bottom || before_the_top {
// Don't actually render, just make space for scrolling purposes // Don't actually render, just make space for scrolling purposes
ui.add_space(estimated_height); ui.add_space(height);
// Yes, and we need to fake render threads to get their approx height too. // Yes, and we need to fake render threads to get their approx height too.
if threaded && !as_reply_to { if threaded && !as_reply_to {
@ -234,6 +237,8 @@ fn render_post_actual(
} }
let event = maybe_event.unwrap(); let event = maybe_event.unwrap();
let top = ui.next_widget_position();
// Only render TextNote events // Only render TextNote events
let enable_reposts = GLOBALS.settings.blocking_read().reposts; let enable_reposts = GLOBALS.settings.blocking_read().reposts;
if event.kind != EventKind::TextNote && !(enable_reposts && (event.kind == EventKind::Repost)) { if event.kind != EventKind::TextNote && !(enable_reposts && (event.kind == EventKind::Repost)) {
@ -301,6 +306,10 @@ fn render_post_actual(
app.viewed.insert(id); app.viewed.insert(id);
} }
// Store actual rendered height for future reference
let bottom = ui.next_widget_position();
app.height.insert(id, bottom.y - top.y);
ui.separator(); ui.separator();
if threaded && !as_reply_to { if threaded && !as_reply_to {

View File

@ -89,6 +89,7 @@ struct GossipUi {
render_raw: Option<Id>, render_raw: Option<Id>,
render_qr: Option<Id>, render_qr: Option<Id>,
viewed: HashSet<Id>, viewed: HashSet<Id>,
height: HashMap<Id, f32>,
// Person page rendering ('npub', 'nprofile', or 'lud06') // Person page rendering ('npub', 'nprofile', or 'lud06')
person_qr: Option<&'static str>, person_qr: Option<&'static str>,
@ -231,6 +232,7 @@ impl GossipUi {
render_raw: None, render_raw: None,
render_qr: None, render_qr: None,
viewed: HashSet::new(), viewed: HashSet::new(),
height: HashMap::new(),
person_qr: None, person_qr: None,
setting_active_person: false, setting_active_person: false,
page: start_page, page: start_page,