Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Expressions: Down arrow in an empty field lists the parameters (#9246) (#9385)

phanoob306b78ce16f7
diff --git a/assets/locales/pending/parameter-list-rows.json b/assets/locales/pending/parameter-list-rows.json
new file mode 100644
index 0000000000..ec66aa10f4
--- /dev/null
+++ b/assets/locales/pending/parameter-list-rows.json
@@ -0,0 +1,30 @@
+{
+ "en": {
+ "prefs.parameter_list_rows": "Parameter list rows",
+ "prefs.parameter_list_rows_tip": "Down arrow in an empty value field lists the parameters, favourites first, up to this many. Fewer keeps the list light in a large design."
+ },
+ "ar": {
+ "prefs.parameter_list_rows": "صفوف قائمة المعاملات",
+ "prefs.parameter_list_rows_tip": "يعرض السهم لأسفل في حقل قيمة فارغ المعاملات، المفضلة أولًا، حتى هذا العدد. العدد الأقل يبقي القائمة خفيفة في التصميم الكبير."
+ },
+ "fr": {
+ "prefs.parameter_list_rows": "Paramètres listés",
+ "prefs.parameter_list_rows_tip": "La flèche bas dans un champ de valeur vide liste les paramètres, favoris en premier, jusqu'à ce nombre. Moins allège la liste dans un gros design."
+ },
+ "he": {
+ "prefs.parameter_list_rows": "שורות ברשימת הפרמטרים",
+ "prefs.parameter_list_rows_tip": "חץ למטה בשדה ערך ריק מציג את הפרמטרים, המועדפים תחילה, עד מספר זה. מספר קטן יותר שומר על רשימה קלה בתכנון גדול."
+ },
+ "ja": {
+ "prefs.parameter_list_rows": "パラメーター一覧の行数",
+ "prefs.parameter_list_rows_tip": "空の値フィールドで下矢印を押すと、お気に入りを先頭にパラメーターをこの数まで一覧表示します。少なくすると大きな設計でも一覧が軽くなります。"
+ },
+ "vi": {
+ "prefs.parameter_list_rows": "Số dòng danh sách tham số",
+ "prefs.parameter_list_rows_tip": "Phím mũi tên xuống trong ô giá trị trống liệt kê các tham số, mục yêu thích trước, tối đa số này. Ít hơn giúp danh sách nhẹ trong thiết kế lớn."
+ },
+ "zh": {
+ "prefs.parameter_list_rows": "参数列表行数",
+ "prefs.parameter_list_rows_tip": "在空的数值框中按下箭头会列出参数(收藏的在前),最多列出此数量。数量越少,大型设计中的列表越轻。"
+ }
+}
diff --git a/crates/ui-egui/src/expression_complete.rs b/crates/ui-egui/src/expression_complete.rs
index c8f7f7725b..71c8f66ff9 100644
--- a/crates/ui-egui/src/expression_complete.rs
+++ b/crates/ui-egui/src/expression_complete.rs
@@ -3,7 +3,7 @@
use crate::ui_kit;
use egui::Key;
-use crate::params_dialog::{exact_token, suggestions_for, unit_token, word_before};
+use crate::params_dialog::{every_parameter, exact_token, suggestions_for, unit_token, word_before};
use crate::theme::Tokens;
#[derive(Clone)]
@@ -31,6 +31,10 @@ struct Popup {
/// every frame: the names it depends on are gathered only once a box has the focus, and
/// the text before the word can change under it (`20 mm` replaced by `pi mm`).
keyed: bool,
+ /// The box was empty when last drawn: Down arrow there opens the list.
+ empty: bool,
+ /// Down arrow in the empty box opened it: every named parameter, however many (#9246).
+ every: bool,
}
fn popup_id() -> egui::Id {
@@ -53,6 +57,22 @@ pub(crate) fn begin_frame(ctx: &egui::Context) {
(popup.armed, popup.keyed) = (true, true);
ctx.data_mut(|d| d.insert_temp(popup_id(), popup.clone()));
}
+ // Down arrow in an empty box opens every named parameter (#9246): one need not remember
+ // a letter of the name. Once the list is open, Down moves through it as below.
+ if popup.empty
+ && (popup.count == 0 || popup.dismissed)
+ && ctx.memory(|m| m.has_focus(popup.editor))
+ && popup.frame.saturating_add(1) >= ctx.cumulative_frame_nr()
+ && ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, Key::ArrowDown))
+ {
+ ctx.input_mut(|i| {
+ i.raw.events.retain(|e| !matches!(e, egui::Event::Key { key: Key::ArrowDown, modifiers, .. } if modifiers.is_none()));
+ });
+ (popup.explicit, popup.every, popup.dismissed) = (true, true, false);
+ (popup.armed, popup.keyed, popup.selected) = (true, true, 0);
+ ctx.data_mut(|d| d.insert_temp(popup_id(), popup.clone()));
+ return;
+ }
let escape_blurred = ctx.input(|i| i.key_pressed(Key::Escape)) && ctx.memory(|m| m.focused().is_none() && m.had_focus_last_frame(popup.editor));
let focused = ctx.memory(|m| m.has_focus(popup.editor)) || escape_blurred;
if popup.frame.saturating_add(1) < ctx.cumulative_frame_nr() || !focused || popup.dismissed || popup.count == 0 {
@@ -169,7 +189,10 @@ pub(crate) fn complete(ui: &mut egui::Ui, resp: &egui::Response, text: &mut Stri
rows: Vec::new(),
armed,
keyed: false,
+ empty: false,
+ every: false,
});
+ popup.empty = text.is_empty();
popup.armed = popup.keyed || armed;
// Never over a control being dragged: the drag dismisses them.
if ctx.dragged_id().is_some_and(|id| id != resp.id) {
@@ -178,7 +201,9 @@ pub(crate) fn complete(ui: &mut egui::Ui, resp: &egui::Response, text: &mut Stri
// A unit right after a number (`2 in`, `10 mm`, the form every dialog starts its sizes in)
// is a unit, not the start of a name: no popup there, so nothing sits over the OK button.
let number_before = before.is_some_and(|c| c.is_ascii_digit() || c == '.' || c == ')');
- let list = if !popup.explicit && number_before && unit_token(&ctx, &popup.word) {
+ let list = if popup.every {
+ every_parameter(&ctx)
+ } else if !popup.explicit && number_before && unit_token(&ctx, &popup.word) {
Vec::new()
} else {
suggestions_for(&ctx, &popup.word, popup.explicit)
@@ -326,6 +351,12 @@ mod tests {
output.textures_delta.clear();
}
+ fn frames(&mut self, n: usize) {
+ for _ in 0..n {
+ self.frame(Vec::new());
+ }
+ }
+
fn key(&mut self, key: Key) {
self.frame(vec![egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }]);
}
@@ -649,6 +680,54 @@ mod tests {
}
}
+ /// #9246: Down arrow in an empty box lists every named parameter, past the eight rows a
+ /// typed word shows; the list scrolls to the chosen row and Enter inserts it. In a box that
+ /// already holds text, Down stays the editor's.
+ #[test]
+ fn down_arrow_in_an_empty_box_lists_every_parameter_and_scrolls() {
+ let mut e = Editor::new("");
+ for i in 1..=15 {
+ e.app.run("parameters.add", json!({"name":format!("p{i:02}"),"expression":"1 mm"})).unwrap();
+ }
+ e.frame(Vec::new());
+ assert_eq!(e.popup(), None, "an empty box shows nothing until asked");
+ e.key(Key::ArrowDown);
+ e.frame(Vec::new());
+ assert!(!e.leaked.contains(&Key::ArrowDown));
+ assert_eq!(e.popup(), Some((20, true)), "every parameter, armed on the first");
+ assert_eq!(e.selected(), 0);
+ assert!(e.text.is_empty());
+
+ e.key(Key::ArrowUp);
+ e.frames(2);
+ assert_eq!(e.selected(), 19);
+ let rows = e.ctx.data(|d| d.get_temp::<Popup>(popup_id())).unwrap().rows;
+ assert!(rows.last().is_some_and(|r| r.area() > 0.0), "the chosen last row is scrolled into view");
+ assert!(rows.first().is_some_and(|r| r.area() <= 0.0), "the first row has scrolled out: {:?}", rows.first());
+ let last = params_dialog::every_parameter(&e.ctx).last().map(|s| s.text.clone()).unwrap();
+ e.key(Key::Enter);
+ assert!(e.accepted);
+ assert_eq!(e.text, last);
+
+ let mut typed = Editor::new("width + ");
+ typed.key(Key::ArrowDown);
+ assert!(typed.leaked.contains(&Key::ArrowDown), "a box with text keeps Down for itself");
+ assert_eq!(typed.popup(), None);
+
+ // Preferences caps the list, so a large design does not list thousands; a hand-edited
+ // cap below the accepted range still lists a few.
+ for (cap, listed) in [(12, 12), (0, 5)] {
+ let mut capped = Editor::new("");
+ for i in 1..=15 {
+ capped.app.run("parameters.add", json!({"name":format!("p{i:02}"),"expression":"1 mm"})).unwrap();
+ }
+ capped.app.preferences.parameter_list_rows = cap;
+ capped.key(Key::ArrowDown);
+ capped.frame(Vec::new());
+ assert_eq!(capped.popup(), Some((listed, true)), "cap {cap}");
+ }
+ }
+
#[test]
fn modified_navigation_remains_available_to_the_editor() {
let mut e = Editor::new("wi");
diff --git a/crates/ui-egui/src/params_dialog.rs b/crates/ui-egui/src/params_dialog.rs
index 9f90b1d4c2..0cf0121477 100644
--- a/crates/ui-egui/src/params_dialog.rs
+++ b/crates/ui-egui/src/params_dialog.rs
@@ -734,6 +734,8 @@ pub struct Suggestion {
struct Cache {
revision: u64,
all: Arc<Vec<Suggestion>>,
+ /// How many parameters Down arrow lists (`Prefs::parameter_list_rows`).
+ every: usize,
}
fn cache_id() -> egui::Id {
@@ -744,7 +746,9 @@ fn cache_id() -> egui::Id {
/// design where expression boxes can reach it. Called once per frame.
pub fn publish(app: &mut SolveApp, ctx: &egui::Context) {
let rev = app.session.revision;
- if ctx.data(|d| d.get_temp::<Cache>(cache_id())).is_some_and(|c| c.revision == rev) {
+ let every =
+ usize::from(app.preferences.parameter_list_rows.clamp(*crate::prefs::PARAMETER_LIST_ROWS.start(), *crate::prefs::PARAMETER_LIST_ROWS.end()));
+ if ctx.data(|d| d.get_temp::<Cache>(cache_id())).is_some_and(|c| c.revision == rev && c.every == every) {
return;
}
let mut all: Vec<Suggestion> = Vec::new();
@@ -763,7 +767,7 @@ pub fn publish(app: &mut SolveApp, ctx: &egui::Context) {
}
}
}
- ctx.data_mut(|d| d.insert_temp(cache_id(), Cache { revision: rev, all: Arc::new(all) }));
+ ctx.data_mut(|d| d.insert_temp(cache_id(), Cache { revision: rev, all: Arc::new(all), every }));
}
/// The identifier being typed before `cursor` (chars) and where it starts.
@@ -802,6 +806,14 @@ pub(crate) fn suggestions_for(ctx: &egui::Context, word: &str, explicit: bool) -
all.iter().filter(|s| starts(s) && offered(s)).chain(all.iter().filter(|s| within(s) && offered(s))).take(8).cloned().collect()
}
+/// The named parameters, in the order the list offers them (favourites and the design's own
+/// first), up to the Preferences' cap rather than a typed word's eight: what Down arrow in an
+/// empty expression box shows (#9246).
+pub(crate) fn every_parameter(ctx: &egui::Context) -> Vec<Suggestion> {
+ let Some(cache) = ctx.data(|d| d.get_temp::<Cache>(cache_id())) else { return Vec::new() };
+ cache.all.iter().filter(|s| s.kind == "parameter").take(cache.every).cloned().collect()
+}
+
/// Is `word` itself one of the known tokens (a parameter or dimension name, a constant or a
/// unit)? Such a word is ready to submit as typed; the popup then only offers longer names.
pub(crate) fn exact_token(ctx: &egui::Context, word: &str) -> bool {
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index 6f348a6e19..503e8afea5 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -281,6 +281,8 @@ pub const PAGE_SKETCH: usize = 5;
pub const PAGE_GRAPHICS: usize = 6;
pub const PAGE_AI: usize = 7;
pub const PAGE_PLUGINS: usize = 8;
+/// What Preferences accepts for `parameter_list_rows`: `parameters.complete` answers at most 200.
+pub const PARAMETER_LIST_ROWS: std::ops::RangeInclusive<u16> = 5..=200;
const WINDOW_PAGES: &[ui_kit::WindowPage<SolveApp>] = &[
ui_kit::WindowPage { icon: "settings", label: "ui.general", group: None, handle: "prefs:page:General", scroll: true, draw: window_page::<0> },
ui_kit::WindowPage {
@@ -1006,6 +1008,9 @@ preference_settings! {
/// Decimals shown for lengths and angles.
length_decimals: u8 = 2, PAGE_DESIGN;
angle_decimals: u8 = 1, PAGE_DESIGN;
+ /// The most parameters Down arrow lists in an empty expression box (#9246): fewer keeps the
+ /// list light in a large design.
+ parameter_list_rows: u16 = 50, PAGE_DESIGN;
/// Up/Down and the wheel over a focused value field step its plain number (`value_step`,
/// #2320). Off by default: the keys move the text cursor and the wheel scrolls, as before.
step_values: bool = false, PAGE_DESIGN => check_id("ui.step_values");
diff --git a/crates/ui-egui/src/prefs/design.rs b/crates/ui-egui/src/prefs/design.rs
index f33bb8ec39..19b0a0d7f1 100644
--- a/crates/ui-egui/src/prefs/design.rs
+++ b/crates/ui-egui/src/prefs/design.rs
@@ -31,6 +31,10 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
ui.add_space(t.space_6);
ui_kit::settings_precision_sample(ui, &format!("{:.*}°", usize::from(app.preferences.angle_decimals.min(6)), 45.0));
});
+ ui_kit::row(ui, app.tr("prefs.parameter_list_rows"), |ui| {
+ let tip = app.tr("prefs.parameter_list_rows_tip").to_string();
+ ui_kit::settings_number(ui, &mut app.preferences.parameter_list_rows, PARAMETER_LIST_ROWS, 1.0).on_hover_text(tip);
+ });
});
let tip = app.tr("ui.step_values_tip").to_string();
let step = setting::step_values(app, ui).on_hover_text(tip);
diff --git a/crates/ui-egui/src/ui_kit/choice.rs b/crates/ui-egui/src/ui_kit/choice.rs
index e8cea12076..e5325c8368 100644
--- a/crates/ui-egui/src/ui_kit/choice.rs
+++ b/crates/ui-egui/src/ui_kit/choice.rs
@@ -609,6 +609,9 @@ pub(crate) struct PopupOption<'a> {
pub color: egui::Color32,
}
+/// Rows a completion list shows before it scrolls.
+const POPUP_LIST_ROWS: usize = 8;
+
/// Focus-neutral suggestion popup. The owner handles navigation and completion semantics;
/// `selected` is the highlighted row, or `None` when no row is picked yet (#3663). Its rows
/// take no focus, and where they were drawn is kept under `id.with("rows")`, so an owner can
@@ -648,31 +651,56 @@ pub(crate) fn popup_list(
.show(ui, |ui| {
super::scope(ui, |ui| {
ui.set_width(width);
- for (index, option) in options.iter().enumerate() {
- let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), t.control_height), egui::Sense::CLICK);
- rows.push(rect);
- let picked = selected == Some(index);
- if picked || response.hovered() {
- ui.painter().rect_filled(rect, t.control_radius, if picked { t.selected_bg } else { t.hover });
- }
- let inner = rect.shrink2(vec2(t.space_8, 0.0));
- let kind = crate::i18n::tr_label(option.kind);
- let kind_width = super::metrics::label_width(ui, kind);
- let text_rect = egui::Rect::from_min_max(
- inner.min,
- egui::pos2((inner.right() - kind_width - t.space_8).max(inner.left()), inner.bottom()),
- );
- super::text::paint_text(ui, text_rect, option.text, mono.clone(), if picked { t.form_primary } else { option.color }, false);
- ui.painter().text(inner.right_center(), egui::Align2::RIGHT_CENTER, kind, kind_font.clone(), t.form_dim);
- response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, ui.is_enabled(), picked, option.text));
- // Tip the full name first: long identifiers still clip inside a capped popup.
- let tip = if option.detail.is_empty() { option.text.to_owned() } else { format!("{}\n{}", option.text, option.detail) };
- let response = response.on_hover_text(tip);
- crate::scenario::publish_handle(&format!("dialog:suggestion:{index}"), response.rect.center());
- if response.clicked() {
- chosen = Some(index);
+ // A long list (every parameter, #9246) scrolls past its first rows and keeps
+ // the chosen row in view.
+ let scrolls = options.len() > POPUP_LIST_ROWS;
+ let followed = id.with("followed");
+ let follow = scrolls && selected.is_some() && ctx.data(|d| d.get_temp::<Option<usize>>(followed)) != Some(selected);
+ ctx.data_mut(|d| d.insert_temp(followed, selected));
+ let scroll = egui::ScrollArea::vertical()
+ .id_salt(id.with("scroll"))
+ .max_height(t.control_height * POPUP_LIST_ROWS as f32)
+ .auto_shrink([false, true])
+ .vscroll(scrolls);
+ scroll.show(ui, |ui| {
+ for (index, option) in options.iter().enumerate() {
+ let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), t.control_height), egui::Sense::CLICK);
+ if follow && selected == Some(index) {
+ ui.scroll_to_rect_animation(rect, None, egui::style::ScrollAnimation::none());
+ }
+ // A row scrolled out of view is not under the pointer.
+ rows.push(if ui.is_rect_visible(rect) { rect.intersect(ui.clip_rect()) } else { egui::Rect::NOTHING });
+ let picked = selected == Some(index);
+ if picked || response.hovered() {
+ ui.painter().rect_filled(rect, t.control_radius, if picked { t.selected_bg } else { t.hover });
+ }
+ let inner = rect.shrink2(vec2(t.space_8, 0.0));
+ let kind = crate::i18n::tr_label(option.kind);
+ let kind_width = super::metrics::label_width(ui, kind);
+ let text_rect = egui::Rect::from_min_max(
+ inner.min,
+ egui::pos2((inner.right() - kind_width - t.space_8).max(inner.left()), inner.bottom()),
+ );
+ super::text::paint_text(
+ ui,
+ text_rect,
+ option.text,
+ mono.clone(),
+ if picked { t.form_primary } else { option.color },
+ false,
+ );
+ ui.painter().text(inner.right_center(), egui::Align2::RIGHT_CENTER, kind, kind_font.clone(), t.form_dim);
+ response
+ .widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, ui.is_enabled(), picked, option.text));
+ // Tip the full name first: long identifiers still clip inside a capped popup.
+ let tip = if option.detail.is_empty() { option.text.to_owned() } else { format!("{}\n{}", option.text, option.detail) };
+ let response = response.on_hover_text(tip);
+ crate::scenario::publish_handle(&format!("dialog:suggestion:{index}"), response.rect.center());
+ if response.clicked() {
+ chosen = Some(index);
+ }
}
- }
+ });
super::divider(ui, "completion_detail");
if let Some(option) = selected.and_then(|index| options.get(index)) {
super::text(ui, option.detail, super::Text::Note("completion_detail"));