Merge pull request #9263 from dotCooCoo/fix/tracing-presets-two-columns

Tracing Presets: the selected preset's settings sit beside the list, under its name in strong type
This commit is contained in:
BFlat
2026-11-25 11:34:13 +07:00
committed by GitHub
2 changed files with 76 additions and 42 deletions
+50 -40
View File
@@ -20,14 +20,15 @@ use craft::host::{PickRequest, Picked};
use craft::ui::buttons::Button;
use craft::ui::contract::SelectMode;
use craft::ui::contract::{Bind, CollectionEvent, Props as _, Show as _, ShowCollection as _, ShowContainer as _, clicked};
use craft::ui::display::Text;
use craft::ui::layout_components::Row;
use craft::ui::display::{Shade, Text};
use craft::ui::layout_components::{Row, Stack};
use craft::ui::list::{List, ListRow};
// PLAN: assumed `craft::ui::patterns::form_dialogs::FieldValue` and `craft::ui::runtime::env::Label` paths.
use craft::ui::dialog::{Dialog, DialogId, DialogResult, DialogStack, FieldRefusal, PromptChoice, StackDialog, StandardPrompt, dialog_id};
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind, ParamResult};
use craft::ui::runtime::env::Label;
use craft::ui::sections::{DialogRole, FooterButton};
use craft::ui::style::TypeRole;
use serde_json::{Value, json};
use vectorcraft_engine::cmd::{TRACE_PRESET_EXTS, TRACE_PRESET_FORMAT, TRACE_PRESET_MAX_BYTES};
@@ -123,46 +124,55 @@ impl StackDialog for Manager {
let (data, action) = (&self.data, &mut self.action);
let dialog = Dialog::new(tl!("Tracing Presets")).buttons([FooterButton::new(tl!("Close"), DialogRole::Cancel)]);
let shown = dialog.show(ui, |ui, _| {
Text::new(tl!("Presets:")).show(ui);
let out = List::new(tl!("Presets"))
.select(SelectMode::Single)
.max_rows(LIST_ROWS)
.selection(Bind::given(Selection::single(at)))
.show_items(ui, &Labels(&labels), &mut |&k, _| ListRow::new(labels[k].clone()));
for event in out.events {
if let CollectionEvent::Selection { change: SelectionChange::Set(keys), .. } = event
&& let Some(p) = keys.last().and_then(|&k| list.presets.get(k))
{
*action = Some(Action::Select(p.0.clone()));
}
}
Row::new().show(ui, |ui, _| {
let buttons = [
(Button::new(tl!("New…")).tooltip(tl!("A new preset starting from the selected one")), Action::New, true),
(Button::new(tl!("Edit…")), Action::Edit, !builtin),
(Button::new(tl!("Delete")), Action::Delete, !builtin),
(Button::new(tl!("Import…")), Action::Import, true),
(Button::new(tl!("Export…")), Action::Export, any_saved),
];
for (button, act, enabled) in buttons {
if clicked(&button.enabled(enabled).show(ui)) {
*action = Some(act);
// The list and its buttons on the left, the selected preset's name and settings on the right.
Row::new().id_salt("presets-body").show(ui, |ui, _| {
Stack::new().id_salt("presets-list").show(ui, |ui, _| {
Text::new(tl!("Presets:")).role(TypeRole::Caption).shade(Shade::Muted).show(ui);
let out = List::new(tl!("Presets"))
.select(SelectMode::Single)
.max_rows(LIST_ROWS)
.selection(Bind::given(Selection::single(at)))
.show_items(ui, &Labels(&labels), &mut |&k, _| ListRow::new(labels[k].clone()));
for event in out.events {
if let CollectionEvent::Selection { change: SelectionChange::Set(keys), .. } = event
&& let Some(p) = keys.last().and_then(|&k| list.presets.get(k))
{
*action = Some(Action::Select(p.0.clone()));
}
}
}
Row::new().show(ui, |ui, _| {
let buttons = [
(Button::new(tl!("New…")).tooltip(tl!("A new preset starting from the selected one")), Action::New, true),
(Button::new(tl!("Edit…")), Action::Edit, !builtin),
(Button::new(tl!("Delete")), Action::Delete, !builtin),
(Button::new(tl!("Import…")), Action::Import, true),
(Button::new(tl!("Export…")), Action::Export, any_saved),
];
for (button, act, enabled) in buttons {
if clicked(&button.enabled(enabled).show(ui)) {
*action = Some(act);
}
}
});
});
Stack::new().id_salt("presets-details").show(ui, |ui, _| {
Text::new(list_label(preset)).role(TypeRole::BodyStrong).show(ui);
// The selected preset's settings, as the editor shows them, to read only: edits land in a copy.
let mut params = preset.1.clone();
// 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);
});
if builtin {
Text::new(tl!("Built-in presets don't change: New makes a copy you can edit."))
.role(TypeRole::Caption)
.shade(Shade::Muted)
.show(ui);
}
});
});
// PLAN: the sheet's two columns and a strong name need layout and text variants that are not in the bundle; stacked and plain here.
Text::new(list_label(preset)).show(ui);
// The selected preset's settings, as the editor shows them, to read only: edits land in a copy.
let mut params = preset.1.clone();
// 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);
});
if builtin {
Text::new(tl!("Built-in presets don't change: New makes a copy you can edit.")).show(ui);
}
});
shown.output.result(|| ())
}
@@ -66,9 +66,17 @@ fn finish(app: &mut VectorcraftApp, ctx: &egui::Context, ok: bool) {
/// The texts the dialogs paint, once they have faded in (each frame is a quarter second on).
fn frame_texts(app: &VectorcraftApp, ctx: &egui::Context) -> Vec<String> {
fn walk(s: &egui::Shape, out: &mut Vec<String>) {
frame_runs(app, ctx).into_iter().map(|(text, _, _)| text).collect()
}
/// The texts the dialogs paint with where each is drawn and its font, once they have faded in.
fn frame_runs(app: &VectorcraftApp, ctx: &egui::Context) -> Vec<(String, egui::Rect, Option<egui::FontId>)> {
fn walk(s: &egui::Shape, out: &mut Vec<(String, egui::Rect, Option<egui::FontId>)>) {
match s {
egui::Shape::Text(t) => out.push(t.galley.text().to_string()),
egui::Shape::Text(t) => {
let font = t.galley.job.sections.first().map(|section| section.format.font_id.clone());
out.push((t.galley.text().to_string(), t.galley.rect.translate(t.pos.to_vec2()), font));
}
egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),
_ => {}
}
@@ -145,6 +153,22 @@ fn new_and_edit_save_through_the_editor_and_cancel_saves_nothing() {
assert_eq!((field(&app, "name"), field(&app, "params")), (json!("Tracing Preset 1"), edited));
}
#[test]
fn the_selected_preset_shows_beside_the_list_under_a_strong_name() {
let (mut app, ctx) = windowed(Default::default());
app.run("ui.tracingPresetsDialog", json!({})).unwrap();
pass(&mut app, &ctx);
let runs = frame_runs(&app, &ctx);
let rect = |names: &[&str]| runs.iter().find(|r| names.contains(&r.0.as_str())).map(|r| r.1);
let (Some(export), Some(mode)) = (rect(&["Export…"]), rect(&["Mode", "Mode:"])) else { panic!("Export… and Mode: {runs:?}") };
// The settings column starts right of the list's buttons and level with the list, not under it.
assert!(mode.left() >= export.right() && mode.top() < export.top(), "Mode {mode:?}, Export… {export:?}");
// The selected preset's name over its settings is set apart from its row in the list.
let names: Vec<_> = runs.iter().filter(|r| r.0 == "[Default]").collect();
assert_eq!(names.len(), 2, "{runs:?}");
assert_ne!(names[0].2, names[1].2, "the list row and the name: {names:?}");
}
#[test]
fn the_editor_shows_document_library_s_library_and_colors() {
let (mut app, ctx) = windowed(Default::default());