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.
This commit is contained in:
dotCooCoo committed 2026-11-28 18:04:53 -08:00
1 parent ac031311a2
commit 56de7f0f5b
4 files changed
+44 -12

No files matched your search

@@ -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<RowsData>) -> 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));
+9 -6
View File
@@ -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] {
@@ -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<String>], 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<R: Default>(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,
@@ -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());