mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 13:27:56 +00:00
Image Trace: tracing preset settings scroll past the preset list's height
The manager and the preset editor showed every settings row, so a Color preset with Document Library and Ignore Color made both dialogs taller than a short screen. The settings now scroll once they are taller than the manager's preset list.
This commit is contained in:
@@ -36,6 +36,10 @@ pub const REPLACE_KIND: &str = "tracingPresetsReplace";
|
||||
/// The editor's field naming the saved preset it edits.
|
||||
const EDITING: &str = "editing";
|
||||
|
||||
/// The tallest the tracing settings draw, in the manager and the editor, before they scroll (the
|
||||
/// height of the manager's preset list), so the dialog's buttons stay on short screens.
|
||||
const SETTINGS_HEIGHT: f32 = 300.0;
|
||||
|
||||
pub(super) const SPEC: DialogSpec = DialogSpec {
|
||||
heading: |_| tl!("Tracing Presets").into(),
|
||||
body,
|
||||
@@ -148,9 +152,12 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool {
|
||||
ui.set_width(320.0);
|
||||
ui.label(egui::RichText::new(list_label(&preset)).color(t.text_strong).strong());
|
||||
ui.add_space(8.0);
|
||||
// The selected preset's settings, as the editor shows them, to read only.
|
||||
// The selected preset's settings, as the editor shows them, to read only. They scroll
|
||||
// past the height of the preset list.
|
||||
let mut params = preset.1.clone();
|
||||
ui.add_enabled_ui(false, |ui| settings_editor(app, ui, "tracing-presets", &mut params));
|
||||
egui::ScrollArea::vertical().id_salt("tracing-preset-details").max_height(SETTINGS_HEIGHT).show(ui, |ui| {
|
||||
ui.add_enabled_ui(false, |ui| settings_editor(app, ui, "tracing-presets", &mut params));
|
||||
});
|
||||
if builtin {
|
||||
ui.add_space(6.0);
|
||||
ui.label(egui::RichText::new(tl!("Built-in presets don't change: New makes a copy you can edit.")).color(t.text_dim).size(11.5));
|
||||
@@ -332,7 +339,12 @@ fn preset_body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> b
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
let mut params = d.fields.get("params").cloned().filter(Value::is_object).unwrap_or_else(|| json!({}));
|
||||
if settings_editor(app, ui, "tracing-preset", &mut params) {
|
||||
let changed = egui::ScrollArea::vertical()
|
||||
.id_salt("tracing-preset-settings")
|
||||
.max_height(SETTINGS_HEIGHT)
|
||||
.show(ui, |ui| settings_editor(app, ui, "tracing-preset", &mut params))
|
||||
.inner;
|
||||
if changed {
|
||||
d.fields.insert("params".into(), params);
|
||||
}
|
||||
false
|
||||
|
||||
@@ -385,3 +385,57 @@ fn a_long_list_of_names_keeps_replace_on_screen() {
|
||||
assert!(rect.is_some_and(|r| screen.contains_rect(r)), "{button} is drawn on screen: {rect:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The tracing settings scroll past the height of the preset list, in the manager and in the
|
||||
/// editor: a preset with every row shown (Color, Document Library, Ignore Color) makes neither
|
||||
/// dialog taller than a Black and White one does.
|
||||
#[test]
|
||||
fn tall_settings_scroll_instead_of_growing_the_dialog() {
|
||||
fn walk(s: &egui::Shape, out: &mut Vec<(String, egui::Rect)>) {
|
||||
match s {
|
||||
egui::Shape::Text(t) => out.push((t.galley.text().to_string(), t.visual_bounding_rect())),
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// The height from the dialog's heading to the bottom of its button `button`.
|
||||
fn height(app: &mut VectorcraftApp, heading: &str, button: &str) -> f32 {
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 2000.0));
|
||||
let mut texts = vec![];
|
||||
for k in 0..6 {
|
||||
let raw = egui::RawInput { screen_rect: Some(screen), time: Some(f64::from(k) * 0.25), ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw, |ui| super::super::show(app, ui.ctx()));
|
||||
out.textures_delta.clear();
|
||||
texts.clear();
|
||||
out.shapes.iter().for_each(|c| walk(&c.shape, &mut texts));
|
||||
}
|
||||
let at = |t: &str| texts.iter().find(|(s, _)| s == t).map(|(_, r)| *r).unwrap_or_else(|| panic!("{t}: {texts:?}"));
|
||||
at(button).max.y - at(heading).min.y
|
||||
}
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let short = listed(&mut app, "Default");
|
||||
let mut tall = short.clone();
|
||||
tall["mode"] = json!("color");
|
||||
tall["palette"] = json!("documentLibrary");
|
||||
tall["colorGroup"] = json!("Brand Colors");
|
||||
tall["ignoreWhite"] = json!(true);
|
||||
for (name, params) in [("Short", &short), ("Tall", &tall)] {
|
||||
app.run("imageTrace.presets.save", json!({ "name": name, "preset": "Default", "params": params })).unwrap();
|
||||
}
|
||||
app.run("ui.tracingPresetsDialog", json!({})).unwrap();
|
||||
let mut heights = vec![];
|
||||
for name in ["Short", "Tall"] {
|
||||
set(&mut app, "selected", json!(name));
|
||||
let manager = height(&mut app, "Tracing Presets", "Close");
|
||||
press(&mut app, Action::Edit, name).unwrap();
|
||||
assert_eq!(kind(&app), Some(PRESET_KIND));
|
||||
let editor = height(&mut app, "Save Preset", "OK");
|
||||
app.ui.dialog = super::super::parent(app.ui.dialog.as_ref().unwrap());
|
||||
heights.push((manager, editor));
|
||||
}
|
||||
let [(manager, editor), (tall_manager, tall_editor)] = heights[..] else { panic!("{heights:?}") };
|
||||
assert!(tall_manager <= manager + 0.5, "the manager grows from {manager} to {tall_manager}");
|
||||
assert!(tall_editor <= editor + 0.5, "the editor grows from {editor} to {tall_editor}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user