From 56de7f0f5bb210d8559c869effc8d8b0914389c7 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 18:04:53 -0800 Subject: [PATCH] Image Trace: line up the settings rows in one label column The Image Trace panel, the Tracing Presets details and the preset editor gave each settings row its own label column, so the Threshold, Paths, Corners, Noise and Stroke sliders started at different x positions and had different lengths. The rows now share one FieldGroup, so every select and slider starts at the width of the widest label, including across the Advanced section. --- crates/ui-egui/src/dialogs/tracing_presets.rs | 14 +++++++++----- crates/ui-egui/src/panels/image_trace.rs | 15 +++++++++------ crates/ui-egui/src/panels/image_trace/rows.rs | 8 +++++++- .../ui-egui/src/panels/image_trace/tests.rs | 19 +++++++++++++++++++ 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/dialogs/tracing_presets.rs b/crates/ui-egui/src/dialogs/tracing_presets.rs index 2db0261f2b..86772bd201 100644 --- a/crates/ui-egui/src/dialogs/tracing_presets.rs +++ b/crates/ui-egui/src/dialogs/tracing_presets.rs @@ -164,8 +164,10 @@ impl StackDialog for Manager { // PLAN: the rows components take no `enabled` prop; the scope's `Ui` is disabled for them. ui.scope(|ui| { ui.disable(); - rows::main_rows(ui, &mut params, data, RowsHost::Dialog); - rows::advanced_rows(ui, &mut params, data, RowsHost::Dialog, None); + rows::settings_group(ui, |ui| { + rows::main_rows(ui, &mut params, data, RowsHost::Dialog); + rows::advanced_rows(ui, &mut params, data, RowsHost::Dialog, None); + }); }); if builtin { Text::new(tl!("Built-in presets don't change: New makes a copy you can edit.")) @@ -472,9 +474,11 @@ fn build(data: Arc) -> impl for<'b> Fn(&'b mut DialogFields) -> ParamD _ => json!({}), }; let shown = ui.scope(|ui| { - let main = rows::main_rows(ui, &mut params, &data, RowsHost::Dialog); - let advanced = rows::advanced_rows(ui, &mut params, &data, RowsHost::Dialog, None); - main.changed || advanced.changed + rows::settings_group(ui, |ui| { + let main = rows::main_rows(ui, &mut params, &data, RowsHost::Dialog); + let advanced = rows::advanced_rows(ui, &mut params, &data, RowsHost::Dialog, None); + main.changed || advanced.changed + }) }); if shown.inner { fields.set("params", FieldValue::Json(params)); diff --git a/crates/ui-egui/src/panels/image_trace.rs b/crates/ui-egui/src/panels/image_trace.rs index 77afb2c39b..08dcd9f42e 100644 --- a/crates/ui-egui/src/panels/image_trace.rs +++ b/crates/ui-egui/src/panels/image_trace.rs @@ -1032,13 +1032,16 @@ fn show_settings(app: &mut VectorcraftApp, ui: &mut Ui, st: &mut TraceUi, list: split_row(app, ui); let data = RowsData::of(app); - let main = rows::main_rows(ui, &mut st.params, &data, RowsHost::Panel); let sampler = Sampler { enabled: t.is_trace || t.is_image, armed: app.ui.trace_ignore_sampler.is_some() }; - let advanced = Section::new(tl!("Advanced")) - .open(Bind::bound(&mut app.ui.image_trace_advanced)) - .show(ui, |ui, _| rows::advanced_rows(ui, &mut st.params, &data, RowsHost::Panel, Some(sampler))) - .inner - .unwrap_or_default(); + let (main, advanced) = rows::settings_group(ui, |ui| { + let main = rows::main_rows(ui, &mut st.params, &data, RowsHost::Panel); + let advanced = Section::new(tl!("Advanced")) + .open(Bind::bound(&mut app.ui.image_trace_advanced)) + .show(ui, |ui, _| rows::advanced_rows(ui, &mut st.params, &data, RowsHost::Panel, Some(sampler))) + .inner + .unwrap_or_default(); + (main, advanced) + }); // A setting is settled when its pick, check or drag ends. Switching to Custom while a slider // still drags would remove the preset's Enhanced row from under it. for RowsOutput { committed, .. } in [main, advanced] { diff --git a/crates/ui-egui/src/panels/image_trace/rows.rs b/crates/ui-egui/src/panels/image_trace/rows.rs index 73f3034177..98551787eb 100644 --- a/crates/ui-egui/src/panels/image_trace/rows.rs +++ b/crates/ui-egui/src/panels/image_trace/rows.rs @@ -11,7 +11,7 @@ use craft::theme::Srgba; use craft::ui::buttons::ToggleButton; use craft::ui::choice::{Checkbox, Segmented}; use craft::ui::contract::{Bind, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _}; -use craft::ui::form::{Field, SliderField, SliderFieldLayout}; +use craft::ui::form::{Field, FieldGroup, SliderField, SliderFieldLayout}; use craft::ui::layout_components::Row; use craft::ui::pickers::Select; // PLAN: assumed `IconId` is re-exported from `craft::ui::primitives`. @@ -132,6 +132,12 @@ fn select_row(ui: &mut Ui, label: &'static str, entries: &[Entry], curre .flatten() } +/// Shows `rows` (one host's [`main_rows`] and [`advanced_rows`]) in one field group, so every row's label takes the +/// width of the widest and the selects and sliders start at the same x. +pub(crate) fn settings_group(ui: &mut Ui, mut rows: impl FnMut(&mut Ui) -> R) -> R { + FieldGroup::new(tl!("Tracing Settings")).show(ui, |ui, _| rows(ui)).inner.unwrap_or_default() +} + /// One number setting: its key, name, range, unit and the value shown when the setting is absent. struct Slider { key: &'static str, diff --git a/crates/ui-egui/src/panels/image_trace/tests.rs b/crates/ui-egui/src/panels/image_trace/tests.rs index 28973d5897..29ed937ca9 100644 --- a/crates/ui-egui/src/panels/image_trace/tests.rs +++ b/crates/ui-egui/src/panels/image_trace/tests.rs @@ -706,6 +706,25 @@ fn advanced_is_a_section_that_stays_as_it_was_left() { assert!(panel.app().ui.image_trace_advanced && panel.shows("Corners")); } +#[test] +fn the_sliders_and_selects_start_in_one_column() { + use craft::ui::contract::Role; + let mut panel = panel_over(traced_app()); + panel.room(egui::vec2(320.0, 1400.0)); + panel.frame(); + panel.frame(); + assert!(panel.app().ui.image_trace_advanced); + // Threshold sits with the main rows and the others in Advanced; the Stroke slider shows dimmed. + let sliders: Vec<(&str, egui::Rect)> = + ["Threshold", "Paths", "Corners", "Noise", "Stroke"].into_iter().map(|n| (n, panel.rect_role(n, Role::SLIDER))).collect(); + let (_, first) = sliders[0]; + for (name, rect) in &sliders { + assert_eq!(rect.left(), first.left(), "the {name} slider starts where Threshold's does"); + assert_eq!(rect.width(), first.width(), "the {name} slider is as long as Threshold's"); + } + assert_eq!(panel.rect_role("Mode:", Role::COMBO_BOX).left(), first.left(), "the Mode select starts in the sliders' column"); +} + #[test] fn the_palette_shows_in_color_mode_and_traces_again() { let mut panel = panel_over(traced_app());