From 98639d1471759f8d315bde469a9f7f5d33c0fc47 Mon Sep 17 00:00:00 2001 From: RobertTGreat Date: Sat, 24 Oct 2026 18:49:37 +0100 Subject: [PATCH 1/2] fix(launcher): virtualize long mod lists from the first frame Render nearby rows in the existing page scrollbar, defer hidden icons and cached verdict reads, and preserve bottom anchoring as row heights are measured. Co-Authored-By: OpenAI Codex (GPT-6.1 Sol) --- launcher/README.md | 6 + launcher/src/cull.rs | 397 +++++++++++++++++++++++++++------- launcher/src/main.rs | 7 +- launcher/src/modpacks_page.rs | 22 +- launcher/src/mods_page.rs | 70 ++++-- launcher/src/mods_project.rs | 96 ++++++-- 6 files changed, 479 insertions(+), 119 deletions(-) diff --git a/launcher/README.md b/launcher/README.md index cf968f93c..5923491e0 100644 --- a/launcher/README.md +++ b/launcher/README.md @@ -258,6 +258,12 @@ measure idle CPU, fetches the release list 3 times, and writes one report there your machine; a `benchmark` report is uploaded, dated to the day, only if you allowed benchmark uploads ([data collection](../docs/telemetry.md)). +Long lists on Mods (results, installed entries, coverage reports and project versions), Versions +and Patch notes build only nearby rows, including on their first frame. Variable row heights +are measured as they enter view; hidden ranges share spacers in the existing page scrollbar. +On Windows, `cargo test --bin horizon-launcher desktop_list_renders_the_viewport_after_scrollbar_jumps +-- --ignored` checks 10,000 rows of different heights in a real GPUI window (requires an awake desktop/GPU). + ## Building cargo build --release diff --git a/launcher/src/cull.rs b/launcher/src/cull.rs index 41df05610..38bd3dd6d 100644 --- a/launcher/src/cull.rs +++ b/launcher/src/cull.rs @@ -1,25 +1,39 @@ -//! Long lists in the page's scroll area (the hundred releases on Versions and Patch notes) draw -//! only the rows near what is on screen. A row far off screen becomes an empty block as tall as -//! it was the last time it was drawn, so the page keeps its length and the scrollbar its place. -use gpui::{div, px, Bounds, Div, IntoElement, ParentElement, Pixels, ScrollHandle, Styled}; -use std::{cell::RefCell, rc::Rc}; +//! Variable-height lists in the page's scroll area. Only nearby rows build elements; +//! unseen rows use estimated heights and consecutive hidden rows share one spacer. +use gpui::{ + div, point, px, size, Bounds, Div, IntoElement, ParentElement, Pixels, ScrollHandle, Styled, +}; +use std::{cell::RefCell, ops::Range, rc::Rc}; + +const ESTIMATED_HEIGHT: f32 = 96.; +/// Until the enclosing scroll area completes its first layout. +const INITIAL_VIEW_HEIGHT: f32 = 800.; #[derive(Clone, Default)] pub struct Cull(Rc>); -/// Where each row was in the last frame, and the scroll offset and the viewport's width then -/// (a narrower window wraps text, and the heights no longer hold). #[derive(Default)] struct Drawn { - rows: Vec>, + heights: Vec, + top: Pixels, offset: Pixels, width: Pixels, } +#[derive(Debug)] +enum Span { + Row(usize), + Space { rows: Range, height: Pixels }, +} + impl Cull { - /// A column for `rows` rows that remembers where they were drawn. Rows come from `row(i)`, or - /// an empty block when row `i` was more than a screen away from the viewport last frame and - /// `keep(i)` is false (a row being installed or showing an error is always drawn). + /// Invalidate measurements when filtering, ordering or collection identity changes. + pub fn reset(&self) { + *self.0.borrow_mut() = Drawn::default(); + } + + /// Render nearby rows plus those retained by `keep` (such as active confirmations). + /// `gap` is the bottom margin already supplied by each row. pub fn column( &self, handle: &ScrollHandle, @@ -28,92 +42,329 @@ impl Cull { keep: impl Fn(usize) -> bool, mut row: impl FnMut(usize) -> E, ) -> Div { - let far = self.far(handle, rows); - let skipped: Vec> = (0..rows).map(|i| far(i).filter(|_| !keep(i))).collect(); - let gaps = skipped.iter().any(Option::is_some); + let max = handle.max_offset().height; + if max > px(0.) + && handle.offset().y <= -max + px(0.5) + && self.0.borrow().heights.len() == rows + { + // Measuring taller rows at the end must keep the final row in view. Appending + // results deliberately leaves the current viewport in place instead. + handle.scroll_to_bottom(); + } + let spans = self + .0 + .borrow_mut() + .plan(handle.bounds(), handle.offset().y, rows, gap, keep); + let children = spans + .iter() + .map(|span| match span { + // The wrapper includes the row's margin in its measured height. + Span::Row(index) => div().flex().flex_col().flex_none().child(row(*index)), + Span::Space { height, .. } => div().flex_none().h(*height), + }) + .collect::>(); let state = self.0.clone(); let scroll = handle.clone(); div() .flex() .flex_col() - .children(skipped.iter().enumerate().map(|(i, skip)| match skip { - Some(height) => div().flex_none().h(*height).mb(px(gap)).into_any_element(), - None => row(i).into_any_element(), - })) + .children(children) .on_children_prepainted(move |bounds, window, _| { - let view = scroll.bounds(); - // A jump of more than a screen (the scrollbar dragged) can bring an empty block - // into view: draw again, with the rows where they are now. - if gaps - && bounds - .iter() - .zip(&skipped) - .any(|(b, skip)| skip.is_some() && !away(*b, px(0.), view)) + if state + .borrow_mut() + .record(&spans, &bounds, scroll.bounds(), scroll.offset().y) { window.refresh(); } - let mut drawn = state.borrow_mut(); - drawn.rows = bounds; - drawn.offset = scroll.offset().y; - drawn.width = view.size.width; }) } - - /// For row `i`: its height when it was more than a screen away from the viewport. - fn far(&self, handle: &ScrollHandle, rows: usize) -> impl Fn(usize) -> Option { - let drawn = self.0.borrow(); - let view = handle.bounds(); - // The rows moved by however far the page scrolled since they were drawn. - let moved = handle.offset().y - drawn.offset; - let known = - drawn.rows.len() == rows && view.size.height > px(0.) && drawn.width == view.size.width; - let rows = if known { - drawn.rows.clone() - } else { - Vec::new() - }; - move |i| { - let b = *rows.get(i)?; - away(b, moved, view).then_some(b.size.height) - } - } } -/// Whether a row drawn at `row`, since moved down by `moved`, is more than a screen above or -/// below `view`. -fn away(row: Bounds, moved: Pixels, view: Bounds) -> bool { - row.bottom() + moved < view.top() - view.size.height - || row.top() + moved > view.bottom() + view.size.height +impl Drawn { + fn plan( + &mut self, + mut view: Bounds, + offset: Pixels, + rows: usize, + gap: f32, + keep: impl Fn(usize) -> bool, + ) -> Vec { + let estimate = px(ESTIMATED_HEIGHT + gap); + if self.width != view.size.width { + // A resize changes wrapping, including in rows currently off screen. + self.heights.fill(estimate); + } + self.heights.resize(rows, estimate); + if view.size.height <= px(0.) { + view.size.height = px(INITIAL_VIEW_HEIGHT); + } + let mut top = self.top + offset - self.offset; + let mut spans = Vec::new(); + for (index, height) in self.heights.iter().copied().enumerate() { + let bounds = Bounds::new(point(view.left(), top), size(view.size.width, height)); + if !away(bounds, view) || keep(index) { + spans.push(Span::Row(index)); + } else if let Some(Span::Space { + rows, + height: total, + }) = spans.last_mut() + { + rows.end = index + 1; + *total += height; + } else { + spans.push(Span::Space { + rows: index..index + 1, + height, + }); + } + top += height; + } + spans + } + + /// A moved header or scrollbar jump can expose a spacer: request another frame when + /// measurements or the estimated visible range need correcting. + fn record( + &mut self, + spans: &[Span], + bounds: &[Bounds], + view: Bounds, + offset: Pixels, + ) -> bool { + let mut changed = false; + for (span, bounds) in spans.iter().zip(bounds) { + match span { + Span::Row(index) => { + let height = &mut self.heights[*index]; + changed |= (*height - bounds.size.height).abs() > px(0.5); + *height = bounds.size.height; + } + Span::Space { .. } => changed |= !away(*bounds, view), + } + } + self.top = bounds.first().map_or(view.top(), Bounds::top); + self.offset = offset; + self.width = view.size.width; + changed + } +} + +/// One viewport of overdraw above and below the visible area. +fn away(row: Bounds, view: Bounds) -> bool { + row.bottom() < view.top() - view.size.height || row.top() > view.bottom() + view.size.height } #[cfg(test)] mod tests { use super::*; - use gpui::{point, size}; - fn at(y: f32, h: f32) -> Bounds { - Bounds::new(point(px(0.), px(y)), size(px(10.), px(h))) + fn at(top: f32, height: f32, width: f32) -> Bounds { + Bounds::new(point(px(0.), px(top)), size(px(width), px(height))) + } + + fn rendered(spans: &[Span]) -> Vec { + spans + .iter() + .filter_map(|span| match span { + Span::Row(index) => Some(*index), + Span::Space { .. } => None, + }) + .collect() } #[test] - fn only_rows_more_than_a_screen_away_are_skipped() { - let view = at(100., 500.); - assert!(!away(at(100., 100.), px(0.), view)); - assert!(!away(at(1000., 100.), px(0.), view)); - assert!(away(at(1200., 100.), px(0.), view)); - assert!(away(at(-600., 100.), px(0.), view)); - // Scrolled 700 px down since: the row that was far below is now on screen. - assert!(!away(at(1200., 100.), px(-700.), view)); + fn ten_thousand_rows_build_only_nearby_elements_on_the_first_frame() { + let list = Cull::default(); + let mut count = 0; + list.column( + &ScrollHandle::new(), + 10_000, + 8., + |_| false, + |_| { + count += 1; + div().h(px(96.)).mb(px(8.)) + }, + ); + assert!(count <= 17, "built {count} rows before the first layout"); + let spans = list + .0 + .borrow_mut() + .plan(at(0., 800., 600.), px(0.), 10_000, 8., |_| false); + assert!(spans.len() <= count + 1, "hidden rows share one spacer"); } #[test] - fn nothing_is_skipped_before_the_rows_are_known() { - let cull = Cull::default(); - cull.0.borrow_mut().rows = (0..10).map(|i| at(i as f32 * 2000., 100.)).collect(); - // No viewport yet (the first frame), or another number of rows: every row is drawn. - let far = cull.far(&ScrollHandle::new(), 10); - assert!((0..10).all(|i| far(i).is_none())); - let far = cull.far(&ScrollHandle::new(), 11); - assert!((0..11).all(|i| far(i).is_none())); + fn large_scroll_jumps_reach_the_last_rows_and_return_to_the_first() { + let mut state = Drawn::default(); + let view = at(0., 500., 600.); + state.plan(view, px(0.), 10_000, 8., |_| false); + state.width = view.size.width; + let end = state.plan(view, px(-1_039_500.), 10_000, 8., |_| false); + assert!(rendered(&end).contains(&9_999)); + assert!(rendered(&end).len() < 20); + assert_eq!( + rendered(&state.plan(view, px(0.), 10_000, 8., |_| false))[0], + 0 + ); + } + + #[test] + fn resizing_and_appending_keep_render_work_bounded_and_retained_rows_available() { + let mut state = Drawn::default(); + let view = at(0., 500., 600.); + state.plan(view, px(0.), 5_000, 8., |_| false); + state.width = view.size.width; + state.heights[100] = px(900.); + let spans = state.plan(at(0., 500., 300.), px(0.), 10_000, 8., |index| { + index == 9_000 + }); + assert_eq!(state.heights[100], px(104.)); + assert!(rendered(&spans).contains(&9_000)); + assert!(spans.len() < 20); + assert_eq!(state.heights.len(), 10_000); + } + + #[test] + fn measurements_include_wrapping_and_reveal_spacers_after_headers_move() { + let mut state = Drawn::default(); + let view = at(0., 500., 600.); + state.plan(view, px(0.), 100, 8., |_| false); + let spans = vec![ + Span::Row(0), + Span::Space { + rows: 1..100, + height: px(10_296.), + }, + ]; + assert!(state.record( + &spans, + &[at(0., 240., 600.), at(240., 10_296., 600.)], + view, + px(0.) + )); + assert_eq!(state.heights[0], px(240.)); + assert!(rendered(&state.plan(view, px(0.), 100, 8., |_| false)).contains(&1)); + let list = Cull::default(); + list.0.borrow_mut().heights = vec![px(400.); 100]; + list.reset(); + assert!(list.0.borrow().heights.is_empty()); + } +} + +#[cfg(all(test, target_os = "windows"))] +mod desktop_tests { + use super::*; + use gpui::{ + prelude::*, AppContext, Application, Context, Render, Window, WindowBounds, WindowOptions, + }; + use std::time::Duration; + + struct ListWindow { + list: Cull, + scroll: ScrollHandle, + rendered: Vec, + } + + impl Render for ListWindow { + fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { + self.rendered.clear(); + let rows = self.list.column( + &self.scroll, + 10_000, + 8., + |_| false, + |index| { + self.rendered.push(index); + div() + .h(px(if index % 2 == 0 { 72. } else { 180. })) + .mb(px(8.)) + .child(format!("Row {index}")) + }, + ); + div() + .id("viewport") + .size_full() + .overflow_y_scroll() + .track_scroll(&self.scroll) + .child(div().pt(px(320.)).child(rows)) + } + } + + #[test] + #[ignore = "requires an interactive desktop and graphics adapter"] + fn desktop_list_renders_the_viewport_after_scrollbar_jumps() { + Application::new().run(|cx| { + let window = cx + .open_window( + WindowOptions { + window_bounds: Some(WindowBounds::Windowed(Bounds::new( + point(px(0.), px(0.)), + size(px(600.), px(500.)), + ))), + ..WindowOptions::default() + }, + |_, cx| { + cx.new(|_| ListWindow { + list: Cull::default(), + scroll: ScrollHandle::new(), + rendered: Vec::new(), + }) + }, + ) + .unwrap(); + cx.spawn(async move |cx| { + for step in 0..3 { + cx.background_executor() + .timer(Duration::from_millis(300)) + .await; + window + .update(cx, |view, _, cx| { + assert!( + view.rendered.len() < 40, + "rendered {} rows", + view.rendered.len() + ); + let wanted = if step == 1 { 9_999 } else { 0 }; + assert!( + view.rendered.contains(&wanted), + "row {wanted} missing: {:?}", + view.rendered + ); + let measured = view.list.0.borrow(); + let mut top = measured.top; + for (index, height) in measured.heights.iter().enumerate() { + if top < view.scroll.bounds().bottom() + && top + *height > view.scroll.bounds().top() + { + assert!( + view.rendered.contains(&index), + "visible row {index} was a spacer" + ); + } + top += *height; + } + if step == 1 { + assert!( + top <= view.scroll.bounds().bottom() + px(1.), + "the last row stayed below the viewport by {:?}", + top - view.scroll.bounds().bottom() + ); + } + drop(measured); + let offset = if step == 0 { + -view.scroll.max_offset().height + } else { + px(0.) + }; + view.scroll.set_offset(point(px(0.), offset)); + cx.notify(); + }) + .unwrap(); + } + cx.update(|cx| cx.quit()).unwrap(); + }) + .detach(); + }); } } diff --git a/launcher/src/main.rs b/launcher/src/main.rs index db2309dd6..0c824bb44 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -366,6 +366,9 @@ impl Launcher { self.switches += 1; self.content_scroll = Scrollbar::default(); self.long_list = cull::Cull::default(); + if page == Page::Mods { + self.mods.reset_lists(); + } } self.picker_open = false; } @@ -2901,7 +2904,7 @@ impl Launcher { )) } Load::Ready(r) if r.is_empty() => return page.child(centered("No releases yet.", &t)), - Load::Ready(r) => r.clone(), + Load::Ready(r) => r, }; // A hundred releases: only the rows near the screen are drawn. let keep = |i: usize| { @@ -3138,7 +3141,7 @@ impl Launcher { ), ) } - Load::Ready(r) => r.clone(), + Load::Ready(r) => r, }; let list = self.long_list.clone().column( &self.content_scroll.handle, diff --git a/launcher/src/modpacks_page.rs b/launcher/src/modpacks_page.rs index ccd0b3a4e..6346f8a0b 100644 --- a/launcher/src/modpacks_page.rs +++ b/launcher/src/modpacks_page.rs @@ -50,6 +50,7 @@ impl Launcher { self.pack_busy = false; match result { Ok(pack) => { + self.mods.report_list.reset(); self.pack_open = Some(pack.slug.clone()); self.packs.retain(|p| p.slug != pack.slug); self.packs.push(*pack); @@ -127,6 +128,7 @@ impl Launcher { /// Reads the imported packs, once (the sidebar and the Modpacks tab both show them). pub(super) fn load_packs(&mut self) { if self.packs_loaded.is_none() { + self.mods.report_list.reset(); self.packs = modpacks::list(); if self.pack_open.is_none() { self.pack_open = self.packs.first().map(|p| p.slug.clone()); @@ -193,6 +195,7 @@ impl Launcher { button(format!("open-{slug}"), "Open", Kind::Ghost, &t) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.pack_open = Some(slug.clone()); + this.mods.report_list.reset(); cx.notify(); })) .into_any_element() @@ -317,6 +320,7 @@ impl Launcher { Ok(()) => { this.packs.retain(|p| p.slug != slug); this.pack_open = this.packs.first().map(|p| p.slug.clone()); + this.mods.report_list.reset(); } Err(e) => this.pack_error = Some(e), } @@ -354,12 +358,13 @@ impl Launcher { move |value, _, cx| { let _ = this.update(cx, |this, cx| { this.pack_filter = value; + this.mods.report_list.reset(); cx.notify(); }); } }); - let mut list = div().flex().flex_col(); - for (i, r) in rows.iter().enumerate() { + let row = |i: usize| { + let r = rows[i]; let color = match r.status { Status::Ported => t.success, Status::Partial => t.accent, @@ -372,7 +377,7 @@ impl Launcher { format!("{} ({})", r.name, r.key) }; let detail = format!("{} · {} · {}: {}", r.class, r.tier, r.license, r.reason); - list = list.child(index_row( + index_row( i + 1, name, Some(detail.into_any_element()), @@ -383,8 +388,15 @@ impl Launcher { .into_any_element(), ), &t, - )); - } + ) + }; + let list = self.mods.report_list.column( + &self.content_scroll.handle, + rows.len(), + 8., + |_| false, + row, + ); Some( div() .flex() diff --git a/launcher/src/mods_page.rs b/launcher/src/mods_page.rs index 00162f930..5c3e1b0c6 100644 --- a/launcher/src/mods_page.rs +++ b/launcher/src/mods_page.rs @@ -54,6 +54,9 @@ pub(super) struct Mods { searching: bool, searched: bool, results: Vec, + results_list: cull::Cull, + installed_list: cull::Cull, + pub(super) report_list: cull::Cull, more: bool, error: Option, installed: Vec, @@ -72,6 +75,12 @@ pub(super) struct Mods { } impl Mods { + pub(super) fn reset_lists(&self) { + self.results_list.reset(); + self.installed_list.reset(); + self.report_list.reset(); + } + /// Whether the Modpacks tab is open (the sidebar marks the pack shown there). pub(super) fn on_modpacks(&self) -> bool { self.kind == PackKind::Modpack @@ -94,6 +103,9 @@ impl Mods { searching: false, searched: false, results: Vec::new(), + results_list: cull::Cull::default(), + installed_list: cull::Cull::default(), + report_list: cull::Cull::default(), more: false, error: None, installed: Vec::new(), @@ -158,6 +170,7 @@ impl Launcher { self.go(Page::Mods); if slug.is_some() { self.pack_open = slug; + self.mods.report_list.reset(); } if self.mods.kind != PackKind::Modpack { self.mods.kind = PackKind::Modpack; @@ -203,6 +216,7 @@ impl Launcher { m.busy = None; m.message = Some(result); m.installed = installed::Installed::load(&backend::game_home()).entries; + m.installed_list.reset(); if modpack { // The Modpacks page reads its list again. self.packs_loaded = None; @@ -249,6 +263,8 @@ impl Launcher { if offset == 0 { m.results.clear(); m.more = false; + m.results_list.reset(); + m.installed_list.reset(); } let query = Query { everything: m.everything, @@ -296,7 +312,16 @@ impl Launcher { .and_then(|source| { java::check_project(&home, &*source, &p, everything, &|_| {}) }) - .map(|(_, c)| Box::new(c)); + .map(|(version, check)| { + let _ = tx.send(Event::Loaded( + super::mods_project::Loaded::Checked( + (p.source, p.id.clone()), + version.id, + check.verdict, + ), + )); + Box::new(check) + }); let _ = tx.send(Event::Checked((p.source, p.id), result)); } }); @@ -608,8 +633,8 @@ impl Launcher { return None; } let busy = self.mods.busy.is_some(); - let mut list = div().flex().flex_col(); - for (i, e) in entries.into_iter().enumerate() { + let row = |i: usize| { + let e = entries[i]; let key = (e.source, e.project.clone()); let mut right = div().flex().items_center().gap(px(8.)); if let Some(number) = self.mods.updates.get(&key) { @@ -654,6 +679,7 @@ impl Launcher { installed::remove(&home, &id).map(|e| format!("Removed {}.", e.title)), ); this.mods.installed = installed::Installed::load(&home).entries; + this.mods.installed_list.reset(); this.mods.confirm_remove = None; } else { this.mods.confirm_remove = Some(id.clone()); @@ -689,14 +715,21 @@ impl Launcher { .font_family(theme::MONO) .child(format!("checked: {}", short_sum(&e.checksum))), ); - list = list.child(index_row( + index_row( i + 1, e.title.clone(), Some(detail.into_any_element()), Some(right.into_any_element()), &t, - )); - } + ) + }; + let list = self.mods.installed_list.column( + &self.content_scroll.handle, + entries.len(), + 8., + |index| self.mods.confirm_remove.as_ref() == Some(&entries[index].project), + row, + ); Some( div() .flex() @@ -709,8 +742,6 @@ impl Launcher { fn mods_results(&mut self, cx: &mut Context) -> Div { let t = self.theme; - let found = self.mods.results.clone(); - let icons: Vec = found.iter().map(|p| self.mods_icon(p, 56.)).collect(); let m = &self.mods; if let Some(e) = &m.error { return div().child(notice(e.clone(), &t)); @@ -725,10 +756,15 @@ impl Launcher { }; return centered(line, &t); } - let busy = m.busy.as_ref().map(|b| b.0.as_str()); - let mut icons = icons.into_iter(); - let mut list = div().flex().flex_col(); - for (i, p) in m.results.iter().enumerate() { + let result_count = m.results.len(); + let rows = m.results_list.clone(); + let scroll = self.content_scroll.handle.clone(); + let row = |i: usize| { + let project = self.mods.results[i].clone(); + let icon = self.mods_icon(&project, 56.); + let p = &project; + let m = &self.mods; + let busy = m.busy.as_ref().map(|b| b.0.as_str()); let support = m.support(p); let checking = p.kind == PackKind::Mod && matches!( @@ -813,21 +849,23 @@ impl Launcher { .items_center() .gap(px(12.)) .cursor_pointer() - .child(icons.next().expect("one icon per result")) + .child(icon) .child(div().hover(|s| s.underline()).child(p.title.clone())) .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { this.mods_open(open.clone()); cx.notify(); })); - list = list.child(index_row( + index_row( i + 1, name, Some(detail.into_any_element()), Some(right.into_any_element()), &t, - )); - } + ) + }; + let list = rows.column(&scroll, result_count, 8., |_| false, row); let mut out = div().flex().flex_col().child(list); + let m = &self.mods; if m.more { let mut more = button("mods-more", "More", Kind::Ghost, &t); if m.searching { diff --git a/launcher/src/mods_project.rs b/launcher/src/mods_project.rs index c66cf174a..ad75f58cd 100644 --- a/launcher/src/mods_project.rs +++ b/launcher/src/mods_project.rs @@ -19,6 +19,7 @@ use horizon_launcher::browser::{ }; use std::collections::{HashMap, HashSet}; use std::path::PathBuf; +use std::sync::Arc; /// A project page's tabs. #[derive(Clone, Copy, PartialEq, Eq)] @@ -38,8 +39,17 @@ const TABS: [(Tab, &str); 3] = [ pub(super) struct Opened { pub(super) project: Project, tab: Tab, - details: Option>, - versions: Option, String>>, + details: Option, String>>, + versions: Option, String>>, + version_list: cull::Cull, + checked_versions: HashMap, +} + +/// Cached verdicts are read with the version request, never while drawing a frame. +#[derive(Clone)] +pub(super) struct ProjectVersion { + version: Version, + verdict: Option, } /// The project page, filters and images' share of the Mods page's state. @@ -58,7 +68,12 @@ pub(super) struct Browse { /// What the background sends this module. pub(super) enum Loaded { Details((SourceId, String), Result), - Versions((SourceId, String), Result, String>), + Versions((SourceId, String), Result, String>), + Checked( + (SourceId, String), + String, + horizon_port_pack::check::Verdict, + ), Image((String, u32), Option), Tags((SourceId, PackKind), Result), } @@ -77,12 +92,20 @@ impl Launcher { match loaded { Loaded::Details(key, d) => { if let Some(o) = open(b, &key) { - o.details = Some(d); + o.details = Some(d.map(Arc::new)); } } Loaded::Versions(key, v) => { if let Some(o) = open(b, &key) { - o.versions = Some(v); + o.versions = Some(v.map(Arc::from)); + o.apply_checks(); + o.version_list.reset(); + } + } + Loaded::Checked(key, version, verdict) => { + if let Some(o) = open(b, &key) { + o.checked_versions.insert(version, verdict); + o.apply_checks(); } } Loaded::Image(key, path) => { @@ -106,7 +129,21 @@ impl Launcher { }; let d = source.details(&p); let _ = tx.send(Event::Loaded(Loaded::Details(key.clone(), d))); - let v = source.versions(&p); + let v = source.versions(&p).map(|versions| { + let home = backend::game_home(); + versions + .into_iter() + .map(|version| { + let verdict = version.file().and_then(|file| { + (p.kind == PackKind::Mod) + .then(|| java::cached(&home, file)) + .flatten() + .map(|check| check.verdict) + }); + ProjectVersion { version, verdict } + }) + .collect() + }); let _ = tx.send(Event::Loaded(Loaded::Versions(key, v))); }); self.mods.browse.open = Some(Opened { @@ -114,6 +151,8 @@ impl Launcher { tab: Tab::Description, details: None, versions: None, + version_list: cull::Cull::default(), + checked_versions: HashMap::new(), }); } @@ -361,6 +400,7 @@ impl Launcher { )); let details = o.details.clone(); let versions = o.versions.clone(); + let version_list = o.version_list.clone(); let mut meta = vec![format!("{} downloads", thousands(p.downloads))]; if let Some(Ok(d)) = &details { meta.push(format!("{} followers", thousands(d.followers))); @@ -551,9 +591,13 @@ impl Launcher { Tab::Versions => match &versions { None => centered("Loading…", &t), Some(Err(e)) => notice(e.clone(), &t), - Some(Ok(list)) => { - let mut rows = div().flex().flex_col(); - for (i, v) in list.iter().take(50).enumerate() { + Some(Ok(list)) => version_list.column( + &self.content_scroll.handle, + list.len().min(50), + 8., + |_| false, + |i| { + let v = &list[i].version; let file = v.file(); let mut detail = vec![ v.published.get(..10).unwrap_or_default().to_string(), @@ -570,27 +614,33 @@ impl Launcher { if let Some(f) = file { detail.push(format!("{} · {:.1} MB", f.name, f.size as f64 / 1e6)); } - let checked = file.and_then(|f| { - (p.kind == PackKind::Mod) - .then(|| java::cached(&backend::game_home(), f)) - .flatten() - }); - rows = rows.child(index_row( + index_row( i + 1, v.number.clone(), Some(detail.join(" · ").into_any_element()), - checked.map(|c| { - caps(c.verdict.label()) - .text_color(t.muted) - .into_any_element() + list[i].verdict.as_ref().map(|verdict| { + caps(verdict.label()).text_color(t.muted).into_any_element() }), &t, - )); - } - rows - } + ) + }, + ), }, }; Some(page.child(body)) } } + +impl Opened { + /// A check can finish before or after the version request; retain either event order. + fn apply_checks(&mut self) { + let Some(Ok(versions)) = &mut self.versions else { + return; + }; + for row in Arc::make_mut(versions) { + if let Some(verdict) = self.checked_versions.get(&row.version.id) { + row.verdict = Some(*verdict); + } + } + } +} From f1ff81e874950a213c543ae51ab9efadef874e00 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 24 Oct 2026 20:38:34 +0200 Subject: [PATCH 2/2] launcher: spacers carry only their height; the version verdict leaves the check thread plainly - `Span::Space` kept the range of rows it hid, written and never read: it is just a height. - The check thread sent the project page's verdict from inside a `map` closure; it is now an explicit step before the result goes to the results list. Co-Authored-By: Claude Opus 5.5 --- launcher/src/cull.rs | 31 +++++++++---------------------- launcher/src/mods_page.rs | 21 +++++++++++---------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/launcher/src/cull.rs b/launcher/src/cull.rs index 38bd3dd6d..e6516019d 100644 --- a/launcher/src/cull.rs +++ b/launcher/src/cull.rs @@ -3,7 +3,7 @@ use gpui::{ div, point, px, size, Bounds, Div, IntoElement, ParentElement, Pixels, ScrollHandle, Styled, }; -use std::{cell::RefCell, ops::Range, rc::Rc}; +use std::{cell::RefCell, rc::Rc}; const ESTIMATED_HEIGHT: f32 = 96.; /// Until the enclosing scroll area completes its first layout. @@ -23,7 +23,8 @@ struct Drawn { #[derive(Debug)] enum Span { Row(usize), - Space { rows: Range, height: Pixels }, + /// Hidden rows, this tall together. + Space(Pixels), } impl Cull { @@ -60,7 +61,7 @@ impl Cull { .map(|span| match span { // The wrapper includes the row's margin in its measured height. Span::Row(index) => div().flex().flex_col().flex_none().child(row(*index)), - Span::Space { height, .. } => div().flex_none().h(*height), + Span::Space(height) => div().flex_none().h(*height), }) .collect::>(); let state = self.0.clone(); @@ -104,18 +105,10 @@ impl Drawn { let bounds = Bounds::new(point(view.left(), top), size(view.size.width, height)); if !away(bounds, view) || keep(index) { spans.push(Span::Row(index)); - } else if let Some(Span::Space { - rows, - height: total, - }) = spans.last_mut() - { - rows.end = index + 1; + } else if let Some(Span::Space(total)) = spans.last_mut() { *total += height; } else { - spans.push(Span::Space { - rows: index..index + 1, - height, - }); + spans.push(Span::Space(height)); } top += height; } @@ -139,7 +132,7 @@ impl Drawn { changed |= (*height - bounds.size.height).abs() > px(0.5); *height = bounds.size.height; } - Span::Space { .. } => changed |= !away(*bounds, view), + Span::Space(_) => changed |= !away(*bounds, view), } } self.top = bounds.first().map_or(view.top(), Bounds::top); @@ -167,7 +160,7 @@ mod tests { .iter() .filter_map(|span| match span { Span::Row(index) => Some(*index), - Span::Space { .. } => None, + Span::Space(_) => None, }) .collect() } @@ -230,13 +223,7 @@ mod tests { let mut state = Drawn::default(); let view = at(0., 500., 600.); state.plan(view, px(0.), 100, 8., |_| false); - let spans = vec![ - Span::Row(0), - Span::Space { - rows: 1..100, - height: px(10_296.), - }, - ]; + let spans = vec![Span::Row(0), Span::Space(px(10_296.))]; assert!(state.record( &spans, &[at(0., 240., 600.), at(240., 10_296., 600.)], diff --git a/launcher/src/mods_page.rs b/launcher/src/mods_page.rs index 5c3e1b0c6..86e5e2e48 100644 --- a/launcher/src/mods_page.rs +++ b/launcher/src/mods_page.rs @@ -311,17 +311,18 @@ impl Launcher { .ok_or_else(|| format!("{} isn't set up.", p.source.label())) .and_then(|source| { java::check_project(&home, &*source, &p, everything, &|_| {}) - }) - .map(|(version, check)| { - let _ = tx.send(Event::Loaded( - super::mods_project::Loaded::Checked( - (p.source, p.id.clone()), - version.id, - check.verdict, - ), - )); - Box::new(check) }); + // The project's page, if open, shows the verdict beside its version. + if let Ok((version, check)) = &result { + let key = (p.source, p.id.clone()); + let _ = + tx.send(Event::Loaded(super::mods_project::Loaded::Checked( + key, + version.id.clone(), + check.verdict, + ))); + } + let result = result.map(|(_, check)| Box::new(check)); let _ = tx.send(Event::Checked((p.source, p.id), result)); } });