diff --git a/crates/ui-egui/src/dialogs/char_style_options.rs b/crates/ui-egui/src/dialogs/char_style_options.rs
index 9fcb532c33..25c7891020 100644
--- a/crates/ui-egui/src/dialogs/char_style_options.rs
+++ b/crates/ui-egui/src/dialogs/char_style_options.rs
@@ -8,8 +8,9 @@ use std::sync::Arc;
use craft::behavior::Mixed;
use craft::ui::choice::Checkbox;
-use craft::ui::contract::{Bind, Entry, Outcome as _, Props as _, Show as _};
+use craft::ui::contract::{Bind, Entry, Outcome as _, Props as _, Show as _, ShowContainer as _};
use craft::ui::dialog::{DialogResult, FieldRefusal};
+use craft::ui::layout_components::Row;
use craft::ui::patterns::form_dialogs::{
DialogFields, FieldValue, HostedPropertiesDialog, Param, ParamKind, PropertiesDialog, PropertiesTab, PropertyRow, TabLayout,
};
@@ -843,7 +844,9 @@ fn sets_row() -> Param {
.and_then(|v| v.as_array().map(|tags| tags.iter().filter_map(Value::as_str).map(str::to_string).collect()))
.unwrap_or_default();
let mut clicked = None;
- let line = ui.horizontal_wrapped(|ui| {
+ let line = Row::new().wrap(true).show(ui, |ui, _| {
+ // The row's body may run more than once in a pass: the last run's click applies.
+ clicked = None;
for set in &vectorcraft_text::EXTRA_FEATURES[..20] {
let current = listed.iter().find(|t| bare(t) == *set).map(|t| !t.starts_with('-'));
if let (_, Some(next)) = tri_box(ui, current, Some(Label::from(set.to_string())), set) {
@@ -864,7 +867,7 @@ fn sets_row() -> Param {
fields.set("ot_sets", FieldValue::Json(json!(listed)));
}
}
- line.response
+ line.output
})
}
diff --git a/crates/ui-egui/src/dialogs/color_balance.rs b/crates/ui-egui/src/dialogs/color_balance.rs
index 5dfeb4e018..c82918426b 100644
--- a/crates/ui-egui/src/dialogs/color_balance.rs
+++ b/crates/ui-egui/src/dialogs/color_balance.rs
@@ -199,12 +199,11 @@ fn track(key: &str, x: f32) -> Srgba {
/// The channel rows of the current mode.
fn channels(ui: &mut egui::Ui, fields: &mut DialogFields, _cx: &mut CustomContext) -> egui::Response {
- ui.vertical(|ui| {
+ super::form::stacked(ui, fields, |ui, fields| {
for (key, label) in mode(fields).channels {
percent_row(ui, fields, key, label, |x| track(key, x));
}
})
- .response
}
fn rows() -> Vec {
diff --git a/crates/ui-egui/src/dialogs/color_guide_options.rs b/crates/ui-egui/src/dialogs/color_guide_options.rs
index 37836565e4..721064005b 100644
--- a/crates/ui-egui/src/dialogs/color_guide_options.rs
+++ b/crates/ui-egui/src/dialogs/color_guide_options.rs
@@ -32,12 +32,11 @@ pub fn open(app: &mut VectorcraftApp) {
fields.set("steps", f64::from(current.steps));
fields.set("amount", f64::from(current.amount));
let steps = Param::custom("steps", field_label(tl!("Steps:")), |ui, fields, _| {
- ui.vertical(|ui| {
+ super::form::stacked(ui, fields, |ui, fields| {
slider(ui, fields, "steps", tl!("Steps:"), 1.0..=f64::from(GuideOptions::MAX_STEPS), None);
let ends = [(0.0, tl!("Less").to_owned()), (100.0, tl!("More").to_owned())];
slider(ui, fields, "amount", tl!("Variation:"), 0.0..=100.0, Some(ends));
})
- .response
})
.companions(["amount"]);
let variations = Param::custom("variations", field_label(tl!("Variations:")), move |ui, fields, _| {
diff --git a/crates/ui-egui/src/dialogs/form.rs b/crates/ui-egui/src/dialogs/form.rs
index 538141fc11..6d81d18214 100644
--- a/crates/ui-egui/src/dialogs/form.rs
+++ b/crates/ui-egui/src/dialogs/form.rs
@@ -4,9 +4,11 @@
use std::collections::HashMap;
-use craft::ui::contract::{Bind, Show as _};
+use craft::ui::contract::{Bind, Show as _, ShowContainer as _};
+use craft::ui::layout_components::Stack;
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, Param, ParamKind, encode};
use craft::ui::runtime::env::{Label, LengthUnits, UnitKind};
+use craft::ui::runtime::measure;
use craft::ui::text::TextField;
use craft::ui::value_drag::SliderScale;
use serde_json::{Map, Value, json};
@@ -200,6 +202,25 @@ pub(crate) fn fields_of(params: &[Param], json: &Map) -> DialogFi
fields
}
+/// Shows `body` in a `Stack` as rows of a custom dialog row that edit `fields`. The stack may run its body more than
+/// once in a pass: every run edits a copy of the values as they stand here, and the copy of the run that is not a
+/// measuring run replaces them after the stack.
+pub(super) fn stacked(ui: &mut egui::Ui, fields: &mut DialogFields, mut body: impl FnMut(&mut egui::Ui, &mut DialogFields)) -> egui::Response {
+ let before = fields.clone();
+ let mut edited = None;
+ let shown = Stack::new().show(ui, |ui, _| {
+ let mut run = before.clone();
+ body(ui, &mut run);
+ if measure::effect(ui.ctx(), "dialog rows edit their values") {
+ edited = Some(run);
+ }
+ });
+ if let Some(edited) = edited {
+ *fields = edited;
+ }
+ shown.output
+}
+
/// The command or effect parameters of the dialog values `fields`: the UI-only keys (`__*`, `preview`) are dropped.
pub(crate) fn json_of(params: &[Param], fields: &DialogFields) -> Map {
fields
diff --git a/crates/ui-egui/src/dialogs/hpgl_options.rs b/crates/ui-egui/src/dialogs/hpgl_options.rs
index 3cfe0ecdfc..50eab143f5 100644
--- a/crates/ui-egui/src/dialogs/hpgl_options.rs
+++ b/crates/ui-egui/src/dialogs/hpgl_options.rs
@@ -18,7 +18,7 @@ use craft::ui::choice::{Radio, RadioGroup, Swatch};
use craft::ui::contract::{Bind, Props as _, Scroll, Show as _, ShowContainer as _};
use craft::ui::dialog::DialogId;
use craft::ui::layout_components::{Row, Stack};
-use craft::ui::patterns::form_dialogs::{CustomContext, DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog};
+use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog};
use craft::ui::runtime::env::Env;
use craft::ui::style::rgba_color;
use craft::ui::text::TextField;
@@ -143,18 +143,13 @@ fn pen_key(i: usize) -> String {
fn pens_param() -> Param {
Param::custom("pens", tl!("Pens:"), |ui, fields, cx| {
take_picked_pens(fields);
- // The rows draw from the values as they stand here and the edits apply after them: the stack's body may run
- // twice in a pass.
- let mut drawn = fields.clone();
+ // The stack's body may run more than once in a pass: every run draws from the values as they stand here, and
+ // what the last run asked for applies after the stack.
let mut asked = PensAsked::default();
- let shown = Stack::new().show(ui, |ui, _| {
- asked = pens_ui(ui, &drawn, cx);
- if let Some(p) = &asked.pens {
- drawn.set("pens", FieldValue::Json(Value::Array(p.clone())));
- }
- });
- // An edit of the rows in any run of the body is in `drawn`; a switch of Pen Table drops it.
- let edited = table(&drawn).filter(|p| asked.table.is_none() && table(fields).as_ref() != Some(p));
+ let shown = Stack::new().show(ui, |ui, _| asked = pens_ui(ui, fields));
+ if let Some((i, color)) = asked.pick {
+ cx.pick_color(&pen_key(i), color);
+ }
match asked.table {
Some(true) => cx.request_action("penTable"),
Some(false) => {
@@ -163,7 +158,7 @@ fn pens_param() -> Param {
}
None => {}
}
- if let Some(pens) = edited {
+ if let Some(pens) = asked.pens {
fields.set("pens", FieldValue::Json(Value::Array(pens)));
}
shown.output
@@ -179,11 +174,13 @@ struct PensAsked {
table: Option,
/// The pen table after an edit of its rows.
pens: Option>,
+ /// The pen whose swatch was pressed, with its color: the picker opens on it.
+ pick: Option<(usize, Srgba)>,
}
/// Writes the colors the picker answered into the pen table.
fn take_picked_pens(fields: &mut DialogFields) {
- let Some(mut pens) = table(fields).filter(|a| a.len() <= MAX_PENS) else { return };
+ let Some(mut pens) = table(fields) else { return };
let mut changed = false;
for (i, pen) in pens.iter_mut().enumerate() {
if let Some([r, g, b]) = fields.color(&pen_key(i)) {
@@ -200,7 +197,7 @@ fn take_picked_pens(fields: &mut DialogFields) {
/// The pens row. Switching to Pen Table asks the host (`penTable`): the table starts from the document's pens, which
/// this draw cannot reach.
-fn pens_ui(ui: &mut egui::Ui, fields: &DialogFields, cx: &mut CustomContext) -> PensAsked {
+fn pens_ui(ui: &mut egui::Ui, fields: &DialogFields) -> PensAsked {
let mut asked = PensAsked::default();
let list = table(fields);
let mut on = list.is_some();
@@ -219,29 +216,35 @@ fn pens_ui(ui: &mut egui::Ui, fields: &DialogFields, cx: &mut CustomContext) ->
let Some(mut pens) = list.filter(|a| asked.table.is_none() && a.len() <= MAX_PENS) else { return asked };
let mut changed = false;
let n = pens.len();
+ // What the rows asked for: a typed color per pen, the pen whose swatch or Remove was pressed. Each run of the
+ // stack's body starts them afresh from the same pens.
+ let mut typed: Vec