From b925a1af3d9f9a5d24d64efe878051b0a63a7fc1 Mon Sep 17 00:00:00 2001 From: NOWN-DEV <257771410+NOWN-DEV@users.noreply.github.com> Date: Sun, 25 Oct 2026 01:24:33 +0000 Subject: [PATCH] Configurations: a long table builds only the rows on screen (#6366) * Test: a long configuration table builds the cells of the rows on screen Co-Authored-By: Claude Opus 5.5 * Configurations: the table builds the rows on screen and its cells once per change A table of hundreds of configurations was slow to open and to use: every frame cloned the whole config.table answer, rebuilt every cell's text, looked each parameter's unit up once per cell and built an editor for every cell of every row, on screen or not. The answer and its cells (with units, looked up once per column) are now kept per design revision, and rows off screen keep their space without building their cells, as the parameters table already does. A row with an edit in progress stays live, so leaving its cell still commits the edit. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- crates/ui-egui/src/configuration_rules_ui.rs | 3 +- crates/ui-egui/src/configurations_ui.rs | 68 +++++++++++++------- crates/ui-egui/src/dialogs_motion.rs | 1 + crates/ui-egui/src/manage_dialogs_tests.rs | 14 ++++ 4 files changed, 61 insertions(+), 25 deletions(-) diff --git a/crates/ui-egui/src/configuration_rules_ui.rs b/crates/ui-egui/src/configuration_rules_ui.rs index 4f5089108..804f322f2 100644 --- a/crates/ui-egui/src/configuration_rules_ui.rs +++ b/crates/ui-egui/src/configuration_rules_ui.rs @@ -16,7 +16,8 @@ pub struct Editor { pub(super) adding_row: bool, pub(super) focus_new_row: bool, pub(super) drafts: std::collections::BTreeMap<(String, String), String>, - pub(super) table: Option<(u64, Value)>, + /// The configuration table at a design revision: the command's answer and its shown cells. + pub(super) table: Option>, } impl Default for Editor { fn default() -> Self { diff --git a/crates/ui-egui/src/configurations_ui.rs b/crates/ui-egui/src/configurations_ui.rs index c5a5f0e3e..43e33ce67 100644 --- a/crates/ui-egui/src/configurations_ui.rs +++ b/crates/ui-egui/src/configurations_ui.rs @@ -13,32 +13,16 @@ pub(super) fn configurations_rows( ) { // Physical materials for the configuration table's Library: the library's, then the design's own. let material_names = app.session.doc.material_names(); + // The table and its cells are made once per design revision: a table of hundreds of rows + // costs too much to rebuild every frame. let revision = app.session.revision; - let v = rule_editor.table.as_ref().filter(|(r, _)| *r == revision).map(|(_, v)| v.clone()).unwrap_or_else(|| { + if rule_editor.table.as_ref().is_none_or(|shown| shown.0 != revision) { let value = app.session.execute("config.table", &json!({})).unwrap_or(Value::Null); - rule_editor.table = Some((revision, value.clone())); - value - }); - let mut tb = table(&v); - // Bare numbers show with their parameter's unit ("40" is 40 mm), as Fusion shows them. - let kinds = app.session.doc.all_param_exprs(); - for (_, vals) in &mut tb.rows { - for (c, val) in tb.columns.iter().zip(vals.iter_mut()) { - let (kind, n) = column_parts(c); - if kind == "param" - && val.trim().parse::().is_ok() - && let Some(unit) = app.session.doc.param(n).map(|parameter| parameter.unit.clone()).or_else(|| { - kinds.iter().find(|x| x.0 == n).and_then(|x| { - unit_of(x.2).map(|unit| { - if x.2 == solidcraft_engine::doc::expr::Kind::Length { app.session.doc.units.clone() } else { unit.to_string() } - }) - }) - }) - { - *val = format!("{} {unit}", val.trim()); - } - } + let tb = with_units(app, table(&value)); + rule_editor.table = Some(std::sync::Arc::new((revision, value, tb))); } + let Some(shown) = rule_editor.table.clone() else { return }; + let (_, v, tb) = &*shown; let run = |app: &mut SolveApp, error: &mut Option, id: &str, p: Value| { *error = app.run(id, p).err(); }; @@ -112,7 +96,10 @@ pub(super) fn configurations_rows( }); for (name, values) in &tb.rows { let active = tb.active.as_deref() == Some(name.as_str()); - table.row(ui, name, active, |row| { + // Rows off screen keep their space without building their cells; one with an edit + // in progress stays live, so leaving its cell still commits the edit. + let editing = rule_editor.drafts.keys().any(|(row, _)| row == name); + table.row_visible(ui, name, active, editing, |row| { row.cell(|ui| { // A measured name slot keeps status/actions inside the Configuration column. ui.allocate_ui_with_layout( @@ -281,6 +268,39 @@ pub(super) fn configurations_rows( ui.input_mut(|input| input.consume_key(egui::Modifiers::NONE, egui::Key::Enter)); } +/// Bare numbers show with their parameter's unit ("40" is 40 mm), as Fusion shows them. The +/// unit is looked up once per column, not once per cell. +fn with_units(app: &SolveApp, mut tb: super::Table) -> super::Table { + let kinds = app.session.doc.all_param_exprs(); + let units: Vec> = + tb.columns + .iter() + .map(|c| { + let (kind, n) = column_parts(c); + if kind != "param" { + return None; + } + app.session.doc.param(n).map(|parameter| parameter.unit.clone()).or_else(|| { + kinds.iter().find(|x| x.0 == n).and_then(|x| { + unit_of(x.2).map(|unit| { + if x.2 == solidcraft_engine::doc::expr::Kind::Length { app.session.doc.units.clone() } else { unit.to_string() } + }) + }) + }) + }) + .collect(); + for (_, vals) in &mut tb.rows { + for (unit, val) in units.iter().zip(vals.iter_mut()) { + if let Some(unit) = unit + && val.trim().parse::().is_ok() + { + *val = format!("{} {unit}", val.trim()); + } + } + } + tb +} + fn column_menu(app: &mut SolveApp, ui: &mut egui::Ui, error: &mut Option, columns: &[String]) { let run = |app: &mut SolveApp, error: &mut Option, id: &str, params: Value| { *error = app.run(id, params).err(); diff --git a/crates/ui-egui/src/dialogs_motion.rs b/crates/ui-egui/src/dialogs_motion.rs index ef724c3f2..54ad8ecbf 100644 --- a/crates/ui-egui/src/dialogs_motion.rs +++ b/crates/ui-egui/src/dialogs_motion.rs @@ -282,6 +282,7 @@ pub fn study_params(s: &Session, name: &str, study: Option<&str>, steps: &str, t } /// The configurations table: columns and rows (name, value per column). +#[derive(Debug)] pub struct Table { pub columns: Vec, pub rows: Vec<(String, Vec)>, diff --git a/crates/ui-egui/src/manage_dialogs_tests.rs b/crates/ui-egui/src/manage_dialogs_tests.rs index 410a80ac2..8c4e63185 100644 --- a/crates/ui-egui/src/manage_dialogs_tests.rs +++ b/crates/ui-egui/src/manage_dialogs_tests.rs @@ -246,6 +246,20 @@ fn configure_alias_is_dense_and_adds_rows() { configurations("config.configure"); } +#[test] +fn a_long_configuration_table_builds_the_cells_of_the_rows_on_screen() { + let mut h = fixture(); + h.app.run("config.configure", json!({"params":["width"]})).unwrap(); + for k in 1..=200 { + h.app.session.execute("config.row", &json!({ "name": format!("Row{k}") })).unwrap(); + } + h.app.start("config.table"); + h.frames(4); + assert!(scenario::rect_of("dialog:table:configuration_table:Default:cell:width").is_some()); + // The last of 201 rows is far below the card's bottom: it keeps its place but builds nothing. + assert!(scenario::rect_of("dialog:table:configuration_table:Row200:cell:width").is_none(), "an off-screen row built its cells"); +} + #[test] fn parameters_are_dense_and_keep_inline_edits_order_and_undo() { let mut h = fixture();