mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 13:15:12 +00:00
Dialogs: Split Into Grid keeps one pass's edits, and the Picked files test uses the shared frame
Split Into Grid's fields edit a copy of the dialog values inside the grid and keep it only when the pass takes effect, as form::stacked does, so a measuring pass no longer changes the values the real pass reads. tests::script_dialogs::frame returns the last pass's output, and the Picked files group test reads the accessibility tree from it instead of running its own frame.
This commit is contained in:
@@ -13,6 +13,7 @@ use craft::ui::layout::GridFit;
|
||||
use craft::ui::layout_components::Grid;
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind};
|
||||
use craft::ui::runtime::env::{LengthUnits, UnitKind};
|
||||
use craft::ui::runtime::measure;
|
||||
use craft::ui::runtime::memory::{SaveKey, saved_value, set_saved_value};
|
||||
use craft::ui::text::{NumberField, NumberOutput};
|
||||
use craft::ui::value_drag::SliderScale;
|
||||
@@ -200,38 +201,45 @@ fn split_grid(ui: &mut egui::Ui, f: &mut DialogFields, lengths: LengthUnits) ->
|
||||
("rows", tl!("Rows:"), tl!("Height:"), "rowGutter", "totalHeight", 2.0),
|
||||
("columns", tl!("Columns:"), tl!("Width:"), "columnGutter", "totalWidth", 2.0),
|
||||
];
|
||||
Grid::new(&AXES)
|
||||
.fit(GridFit::Fixed)
|
||||
.id_salt("split-grid")
|
||||
.show(ui, |ui, _| {
|
||||
for (number, label, _, _, _, default) in axes {
|
||||
let n = f.number(number).unwrap_or(default);
|
||||
if let Some(v) = cell(ui, label, label.to_string(), false, n, None) {
|
||||
f.set(number, v);
|
||||
}
|
||||
// The grid can run its body twice in a pass, so the body edits a copy, kept only from the run that takes effect.
|
||||
let before = f.clone();
|
||||
let mut edited = None;
|
||||
let shown = Grid::new(&AXES).fit(GridFit::Fixed).id_salt("split-grid").show(ui, |ui, _| {
|
||||
let mut f = before.clone();
|
||||
for (number, label, _, _, _, default) in axes {
|
||||
let n = f.number(number).unwrap_or(default);
|
||||
if let Some(v) = cell(ui, label, label.to_string(), false, n, None) {
|
||||
f.set(number, v);
|
||||
}
|
||||
for (number, _, label, gutter, total, default) in axes {
|
||||
let n = f.number(number).unwrap_or(default).max(1.0);
|
||||
let gaps = f.number(gutter).unwrap_or(0.0) * (n - 1.0);
|
||||
let size = (f.number(total).unwrap_or(0.0) - gaps) / n;
|
||||
if let Some(v) = cell(ui, label, label.to_string(), false, size, Some(lengths)) {
|
||||
f.set(total, n * v + gaps);
|
||||
}
|
||||
}
|
||||
for (number, _, label, gutter, total, default) in axes {
|
||||
let n = f.number(number).unwrap_or(default).max(1.0);
|
||||
let gaps = f.number(gutter).unwrap_or(0.0) * (n - 1.0);
|
||||
let size = (f.number(total).unwrap_or(0.0) - gaps) / n;
|
||||
if let Some(v) = cell(ui, label, label.to_string(), false, size, Some(lengths)) {
|
||||
f.set(total, n * v + gaps);
|
||||
}
|
||||
for (_, axis, _, gutter, _, _) in axes {
|
||||
let label = tl!("Gutter:");
|
||||
if let Some(v) = cell(ui, label, format!("{axis} {label}"), true, f.number(gutter).unwrap_or(0.0), Some(lengths)) {
|
||||
f.set(gutter, v);
|
||||
}
|
||||
}
|
||||
for (_, axis, _, gutter, _, _) in axes {
|
||||
let label = tl!("Gutter:");
|
||||
if let Some(v) = cell(ui, label, format!("{axis} {label}"), true, f.number(gutter).unwrap_or(0.0), Some(lengths)) {
|
||||
f.set(gutter, v);
|
||||
}
|
||||
for (_, axis, _, _, total, _) in axes {
|
||||
let label = tl!("Total:");
|
||||
if let Some(v) = cell(ui, label, format!("{axis} {label}"), true, f.number(total).unwrap_or(0.0), Some(lengths)) {
|
||||
f.set(total, v);
|
||||
}
|
||||
}
|
||||
for (_, axis, _, _, total, _) in axes {
|
||||
let label = tl!("Total:");
|
||||
if let Some(v) = cell(ui, label, format!("{axis} {label}"), true, f.number(total).unwrap_or(0.0), Some(lengths)) {
|
||||
f.set(total, v);
|
||||
}
|
||||
})
|
||||
.output
|
||||
}
|
||||
if measure::effect(ui.ctx(), "Split Into Grid's fields edit their values") {
|
||||
edited = Some(f);
|
||||
}
|
||||
});
|
||||
if let Some(edited) = edited {
|
||||
*f = edited;
|
||||
}
|
||||
shown.output
|
||||
}
|
||||
|
||||
/// Split Into Grid's rows: the grid and Add Guides.
|
||||
|
||||
@@ -77,8 +77,8 @@ pub(super) fn open_blocker(app: &VectorcraftApp) {
|
||||
}
|
||||
|
||||
/// One pass of the dialog host with `events`; a key pressed in it is let go in a second pass, as a
|
||||
/// person lets go of it.
|
||||
pub(super) fn frame(app: &VectorcraftApp, events: Vec<egui::Event>) {
|
||||
/// person lets go of it. Returns the last pass's output.
|
||||
pub(super) fn frame(app: &VectorcraftApp, events: Vec<egui::Event>) -> egui::FullOutput {
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
let dialogs = app.dialogs().unwrap();
|
||||
let released: Vec<egui::Event> = events
|
||||
@@ -92,10 +92,12 @@ pub(super) fn frame(app: &VectorcraftApp, events: Vec<egui::Event>) {
|
||||
.collect();
|
||||
let screen_rect = Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 800.0)));
|
||||
let pressed = !released.is_empty();
|
||||
let mut last = egui::FullOutput::default();
|
||||
for events in std::iter::once(events).chain(pressed.then_some(released)) {
|
||||
let mut out = ctx.run_ui(egui::RawInput { events, screen_rect, ..Default::default() }, |ui| dialogs.with(|host| host.run(ui)));
|
||||
out.textures_delta.clear();
|
||||
last = ctx.run_ui(egui::RawInput { events, screen_rect, ..Default::default() }, |ui| dialogs.with(|host| host.run(ui)));
|
||||
last.textures_delta.clear();
|
||||
}
|
||||
last
|
||||
}
|
||||
|
||||
pub(super) fn key(k: egui::Key) -> egui::Event {
|
||||
|
||||
@@ -476,10 +476,7 @@ fn a_scripts_file_dialog_lists_several_picked_files_in_a_named_group() {
|
||||
let given = vec!["/picked/a.txt".to_string(), "/picked/b.txt".to_string()];
|
||||
script_run::with_host(&app, |host, _| host.get_mut::<ScriptFiles>().map(|d| d.add(given, true, false))).unwrap();
|
||||
frame(&app, vec![]);
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
let dialogs = app.dialogs().unwrap();
|
||||
let screen_rect = Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 800.0)));
|
||||
let out = ctx.run_ui(egui::RawInput { screen_rect, ..Default::default() }, |ui| dialogs.with(|host| host.run(ui)));
|
||||
let out = frame(&app, vec![]);
|
||||
let update = out.platform_output.accesskit_update.expect("an accessibility tree");
|
||||
let groups: Vec<_> =
|
||||
update.nodes.iter().filter(|(_, node)| node.role() == egui::accesskit::Role::Group).filter_map(|(_, node)| node.label()).collect();
|
||||
|
||||
Reference in New Issue
Block a user