mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 22:08:42 +00:00
Fix the dialogs a-m tests: style dialogs' Reset and number fields, held dialogs' frames, hidden JSON fields, scroll ownership
- Style dialogs: the wrapper passes Reset through, a number set on a text row is taken as its JSON text, fields hold numbers as production showed them (12.0), a refused value keeps the last accepted preview, and a paint set from outside updates its tint flags. - Brush Options keeps its hidden JSON values whole and holds an automation-set Colorization as its select does. - Graph Data's sheet and JavaScript Files' list own their scroll. - Kinsoku Shori Settings' New no longer writes the old fields into the new set. - Flatten Transparency opens with Preview off; a gradient stop's colour takes hex only; Envelope Warp's Horizontal/Vertical radio holds its ids. - Tests: held dialogs' OK is driven through app frames; lookups use visible labels; a length row is set in points (wg.W21); Check Spelling sits in Edit > Spelling.
This commit is contained in:
@@ -60,9 +60,10 @@ mod tests {
|
||||
let count = |panel: &Panel| panel.app().ui.attributes_panel.recent_urls;
|
||||
let is_open = |panel: &Panel| panel.app().dialogs().is_some_and(|d| d.with(|host| host.get_mut_by_id::<HostedParamDialog>(id).is_some()));
|
||||
let set = |panel: &Panel, value: Value| panel.app().dialogs().unwrap().with(|host| host.set_json_field(&ctx, id, "count", value));
|
||||
// OK files a held answer, which the next frames apply and close on; Cancel closes at once.
|
||||
let press = |panel: &mut Panel, ok: bool| {
|
||||
let done = panel.app().dialogs().unwrap().with(|host| if ok { host.confirm_by_id(&ctx, id) } else { host.cancel_by_id(&ctx, id) });
|
||||
assert!(done);
|
||||
let closed = panel.app().dialogs().unwrap().with(|host| if ok { host.confirm_by_id(&ctx, id) } else { host.cancel_by_id(&ctx, id) });
|
||||
assert!(ok || closed);
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
};
|
||||
|
||||
@@ -168,12 +168,10 @@ mod tests {
|
||||
app
|
||||
}
|
||||
|
||||
/// One app frame and one dialog pump.
|
||||
/// One app frame: the dialog pump runs and the dialogs draw, so an accepted OK closes its dialog.
|
||||
fn frame(app: &mut VectorcraftApp) {
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |_| {});
|
||||
out.textures_delta.clear();
|
||||
crate::dialogs::host::pump(app, &ctx);
|
||||
crate::testing::app_frame(app, &ctx, egui::RawInput::default());
|
||||
}
|
||||
|
||||
fn with<R>(app: &VectorcraftApp, f: impl FnOnce(&mut DialogHost) -> R) -> R {
|
||||
|
||||
@@ -29,7 +29,7 @@ use craft::theme::Srgba;
|
||||
use craft::ui::buttons::Button;
|
||||
use craft::ui::choice::{CellMarks, Segmented, Swatch};
|
||||
use craft::ui::contract::{Bind, Entry, Outcome as _, Props as _, Show as _, ShowContainer as _, clicked};
|
||||
use craft::ui::dialog::StackDialog;
|
||||
use craft::ui::dialog::{FieldRefusal, StackDialog};
|
||||
use craft::ui::display::{Picture, PictureSize, Text};
|
||||
use craft::ui::layout_components::{Row, Stack};
|
||||
use craft::ui::list::{ThumbAspect, ThumbSize};
|
||||
@@ -683,7 +683,16 @@ fn colorization_rows() -> Vec<Param> {
|
||||
}
|
||||
shown
|
||||
})
|
||||
.companions(["tips"]);
|
||||
.companions(["tips"])
|
||||
// A method set from outside is held as the select holds it, so Key Color's `enabled_when` reads it.
|
||||
.on_set(|f: &mut DialogFields, key: &str, value: Value| {
|
||||
let read = match key {
|
||||
"colorization" => value.as_str().filter(|id| Colorization::IDS.contains(id)).map(|id| FieldValue::Text(id.to_string())),
|
||||
_ => value.as_bool().map(FieldValue::Bool),
|
||||
};
|
||||
f.set(key, read.ok_or_else(|| FieldRefusal::Rejects(&value).message(key))?);
|
||||
Ok(())
|
||||
});
|
||||
// Hue Shift's key colour: the art colour that becomes the stroke colour.
|
||||
let key_color_row = Param::custom("keyColors", tl!("Key Color"), |ui, f, cx| {
|
||||
let colors: Vec<Color> = json_field(f, "__colors").and_then(|v| serde_json::from_value(v.clone()).ok()).unwrap_or_default();
|
||||
|
||||
@@ -172,6 +172,12 @@ fn open_dialog(app: &mut VectorcraftApp, f: &Map<String, Value>, object_keys: Op
|
||||
let rows = rows(ty, object, doc, crate::canvas::rulers::unit_kind(app.session.general_unit()));
|
||||
let title = Label::from(title(ty, object));
|
||||
let mut initial = form::fields_of(&rows, f);
|
||||
// The hidden values the rows read whole stay JSON: an untagged read makes an array a list of values.
|
||||
for key in ["__def", "__patterns", "__colors"] {
|
||||
if let Some(value) = f.get(key) {
|
||||
initial.set(key, FieldValue::Json(value.clone()));
|
||||
}
|
||||
}
|
||||
if let Some(keys) = object_keys {
|
||||
let opened = object_params(&initial, keys);
|
||||
initial.set(OPENED, FieldValue::Json(Value::Object(opened)));
|
||||
|
||||
@@ -9,7 +9,7 @@ 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::dialog::DialogResult;
|
||||
use craft::ui::dialog::{DialogResult, FieldRefusal};
|
||||
use craft::ui::patterns::form_dialogs::{
|
||||
DialogFields, FieldValue, HostedPropertiesDialog, Param, ParamKind, PropertiesDialog, PropertiesTab, PropertyRow, TabLayout,
|
||||
};
|
||||
@@ -197,13 +197,13 @@ pub(crate) fn value_of(value: &FieldValue) -> Value {
|
||||
serde_json::to_value(value).unwrap_or(Value::Null)
|
||||
}
|
||||
|
||||
/// The field value of a JSON `value` (`None` for `null`): a number is its text, which the text rows hold.
|
||||
/// The field value of a JSON `value` (`None` for `null`): a number is its JSON text (`12.0`), which the text rows hold.
|
||||
fn field_of(value: &Value) -> Option<FieldValue> {
|
||||
Some(match value {
|
||||
Value::Null => return None,
|
||||
Value::Bool(b) => FieldValue::Bool(*b),
|
||||
Value::String(s) => FieldValue::Text(s.clone()),
|
||||
Value::Number(n) => FieldValue::Text(n.as_f64().map_or_else(|| n.to_string(), |n| n.to_string())),
|
||||
Value::Number(n) => FieldValue::Text(n.to_string()),
|
||||
other => FieldValue::Json(other.clone()),
|
||||
})
|
||||
}
|
||||
@@ -273,6 +273,17 @@ pub(crate) fn tri_state(key: impl Into<String>, label: impl Into<Label>) -> Para
|
||||
}
|
||||
response
|
||||
})
|
||||
// Set from outside: on, off, or `null` for neither.
|
||||
.on_set(|fields, key, value| {
|
||||
match value {
|
||||
Value::Bool(on) => fields.set(key, FieldValue::Bool(on)),
|
||||
Value::Null => {
|
||||
fields.remove(key);
|
||||
}
|
||||
other => return Err(FieldRefusal::Rejects(&other).message(key)),
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
/// The General tab's rows: the style's name and what it sets, or nothing of that while `attrs` is refused.
|
||||
@@ -811,6 +822,16 @@ fn paint_row(key: &'static str, label: &'static str, swatches: Vec<(String, Valu
|
||||
out.response().clone()
|
||||
})
|
||||
.companions(companions.iter().copied())
|
||||
.on_set(|fields, key, value| {
|
||||
match field_of(&value) {
|
||||
Some(value) => fields.set(key, value),
|
||||
None => {
|
||||
fields.remove(key);
|
||||
}
|
||||
}
|
||||
paint_flags(fields);
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
/// The Stylistic Sets grid: each set is on (`ssNN`), off (`-ssNN`) or unset (not listed), as the other checkboxes are.
|
||||
@@ -970,8 +991,9 @@ pub(crate) struct Frame {
|
||||
pub(crate) ok: bool,
|
||||
}
|
||||
|
||||
/// Runs one frame of an options dialog's live preview of `cmd`: previews the values while they are accepted, and
|
||||
/// at OK keeps the preview as one undo step. Returns the preview state to keep and the commit's answer at OK.
|
||||
/// Runs one frame of an options dialog's live preview of `cmd`: previews the values while they are accepted, keeps
|
||||
/// the last accepted preview while they are refused, and at OK keeps the preview as one undo step. Returns the
|
||||
/// preview state to keep and the commit's answer at OK.
|
||||
pub(crate) fn drive(
|
||||
app: &mut VectorcraftApp,
|
||||
mut live: LivePreview,
|
||||
@@ -986,13 +1008,28 @@ pub(crate) fn drive(
|
||||
live.run(app, frame.previewing, label, cmd, params);
|
||||
(live, None)
|
||||
}
|
||||
// Refused values keep the last accepted preview; turning Preview off still rolls it back.
|
||||
(Err(_), false) => {
|
||||
live.run(app, false, label, cmd, &Value::Null);
|
||||
if !frame.previewing {
|
||||
live.run(app, false, label, cmd, &Value::Null);
|
||||
}
|
||||
(live, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets `field` of the style dialog `inner` from automation: a number a text row refuses is taken as its text, as
|
||||
/// typing it would give.
|
||||
pub(crate) fn set_field(inner: &mut HostedPropertiesDialog, ctx: &egui::Context, field: &str, value: Value) -> Result<(), String> {
|
||||
use craft::ui::dialog::StackDialog as _;
|
||||
let refused = match inner.set_json_field(ctx, field, value.clone()) {
|
||||
Err(why) if value.is_number() => why,
|
||||
done => return done,
|
||||
};
|
||||
let text = field_of(&value).map(|typed| value_of(&typed)).unwrap_or(Value::Null);
|
||||
inner.set_json_field(ctx, field, text).map_err(|_| refused)
|
||||
}
|
||||
|
||||
/// Makes a wrapper over a [`HostedPropertiesDialog`] (`inner`) a dialog of its own type: it answers with the values
|
||||
/// and delegates everything else to `inner`. The wrapper has `edited()` and `command(attrs)` of its own; `frame` is
|
||||
/// what its pump reads each frame, which also keeps OK off while `edited()` refuses.
|
||||
@@ -1044,12 +1081,20 @@ macro_rules! style_dialog {
|
||||
}
|
||||
|
||||
fn set_json_field(&mut self, ctx: &egui::Context, field: &str, value: serde_json::Value) -> Result<(), String> {
|
||||
craft::ui::dialog::StackDialog::set_json_field(&mut self.inner, ctx, field, value)
|
||||
$crate::dialogs::char_style_options::set_field(&mut self.inner, ctx, field, value)
|
||||
}
|
||||
|
||||
fn cancelled(&mut self, ctx: &egui::Context) {
|
||||
craft::ui::dialog::StackDialog::cancelled(&mut self.inner, ctx);
|
||||
}
|
||||
|
||||
fn can_reset(&self) -> bool {
|
||||
self.inner.can_reset_tab()
|
||||
}
|
||||
|
||||
fn reset(&mut self, _ctx: &egui::Context) -> bool {
|
||||
self.inner.reset_tab()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ fn advanced_fields_show_set_values_and_keep_untouched_ones() {
|
||||
assert_eq!(edited_attrs(&d, &o).unwrap(), attrs(original.clone()), "{original}");
|
||||
}
|
||||
let (d, _) = dialog_for(json!({"h_scale": 100.0, "rotation": 0.0, "language": null}));
|
||||
assert_eq!((val(&d, "h_scale"), val(&d, "v_scale")), (json!(100.0), json!("")));
|
||||
assert_eq!((val(&d, "h_scale"), val(&d, "v_scale")), (json!("100.0"), json!("")));
|
||||
assert_eq!(val(&d, "language"), json!("English: USA"));
|
||||
assert_eq!(val(&dialog_for(json!({"language": "de"})).0, "language"), json!("German"));
|
||||
assert_eq!(val(&dialog_for(json!({"language": "x-file"})).0, "language"), json!("x-file"));
|
||||
@@ -315,7 +315,7 @@ fn advanced_options_preview_cancel_reset_and_commit() {
|
||||
let before = app.session.doc().unwrap().doc.clone();
|
||||
let undo = app.session.doc().unwrap().history.undo.len();
|
||||
open(&mut app, "Body");
|
||||
assert_eq!(fields::<Existing>(&app)["h_scale"], json!(90.0));
|
||||
assert_eq!(fields::<Existing>(&app)["h_scale"], json!("90.0"));
|
||||
assert_eq!(fields::<Existing>(&app)["rotation"], json!(""));
|
||||
set::<Existing>(&app, "tab", json!("advanced"));
|
||||
set::<Existing>(&app, "h_scale", json!("80"));
|
||||
@@ -380,7 +380,7 @@ fn new_character_style_sets_and_resets_advanced_formats() {
|
||||
#[test]
|
||||
fn tate_chu_yoko_offsets_show_set_reset_and_keep_their_limits() {
|
||||
let (d, o) = dialog_for(json!({"tcyUpDown": 2.0, "size": 12.0}));
|
||||
assert_eq!((val(&d, "tcyUpDown"), val(&d, "tcyLeftRight")), (json!(2.0), json!("")));
|
||||
assert_eq!((val(&d, "tcyUpDown"), val(&d, "tcyLeftRight")), (json!("2.0"), json!("")));
|
||||
assert_eq!(edited_attrs(&d, &o).unwrap(), attrs(json!({"tcyUpDown": 2.0, "size": 12.0})));
|
||||
// A value a style captured from scaled text stays while its field is untouched.
|
||||
let (d, o) = dialog_for(json!({"tcyLeftRight": 3000.0}));
|
||||
@@ -449,7 +449,7 @@ fn tate_chu_yoko_offsets_preview_cancel_and_commit_to_the_style_and_its_text() {
|
||||
#[test]
|
||||
fn insert_aki_fields_show_set_reset_and_stop_at_the_character_panel_limits() {
|
||||
let (d, o) = dialog_for(json!({"akiLeft": 250.0, "size": 12.0}));
|
||||
assert_eq!((val(&d, "akiLeft"), val(&d, "akiRight")), (json!(250.0), json!("")));
|
||||
assert_eq!((val(&d, "akiLeft"), val(&d, "akiRight")), (json!("250.0"), json!("")));
|
||||
assert_eq!(edited_attrs(&d, &o).unwrap(), attrs(json!({"akiLeft": 250.0, "size": 12.0})));
|
||||
|
||||
let (mut d, o) = dialog_for(json!({"akiLeft": 250.0}));
|
||||
@@ -488,7 +488,7 @@ fn insert_aki_fields_commit_to_the_style_and_its_text() {
|
||||
#[test]
|
||||
fn diacritic_position_fields_show_set_reset_and_commit() {
|
||||
let (d, o) = dialog_for(json!({"diacriticHorizontal": -250.0, "size": 12.0}));
|
||||
assert_eq!((val(&d, "diacriticHorizontal"), val(&d, "diacriticVertical")), (json!(-250.0), json!("")));
|
||||
assert_eq!((val(&d, "diacriticHorizontal"), val(&d, "diacriticVertical")), (json!("-250.0"), json!("")));
|
||||
assert_eq!(edited_attrs(&d, &o).unwrap(), attrs(json!({"diacriticHorizontal": -250.0, "size": 12.0})));
|
||||
let (mut d, o) = dialog_for(json!({"diacriticHorizontal": -250.0}));
|
||||
put(&mut d, "diacriticHorizontal", json!(""));
|
||||
@@ -522,7 +522,7 @@ fn tsume_field_shows_sets_resets_and_commits() {
|
||||
let (d, _) = dialog_for(json!({"size": 12.0}));
|
||||
assert_eq!(val(&d, "tsume"), json!(""));
|
||||
let (mut d, o) = dialog_for(json!({"tsume": 50.0}));
|
||||
assert_eq!(val(&d, "tsume"), json!(50.0));
|
||||
assert_eq!(val(&d, "tsume"), json!("50.0"));
|
||||
for (typed, kept) in [("0", 0.0), ("25.5", 25.5), ("150", 100.0), ("-5", 0.0)] {
|
||||
put(&mut d, "tsume", json!(typed));
|
||||
assert_eq!(edited_attrs(&d, &o).unwrap(), attrs(json!({"tsume": kept})), "{typed}");
|
||||
@@ -649,7 +649,7 @@ fn color_tint_and_weight_outside_their_limits_are_errors() {
|
||||
assert_eq!(edited_attrs(&d, &o).unwrap_err(), message, "{key} {value}");
|
||||
}
|
||||
let (mut d, o) = dialog_for(json!({"fill": linked}));
|
||||
assert_eq!(val(&d, "fill_tint"), json!(100.0));
|
||||
assert_eq!(val(&d, "fill_tint"), json!("100.0"));
|
||||
put(&mut d, "fill_tint", json!("40"));
|
||||
put(&mut d, "stroke_width", json!("1.5"));
|
||||
assert_eq!(
|
||||
@@ -740,7 +740,7 @@ fn color_and_features_preview_cancel_commit_and_new_style() {
|
||||
}
|
||||
open(&mut app, "Body");
|
||||
let shown = fields::<Existing>(&app);
|
||||
assert_eq!((shown["stroke_tint"].clone(), shown["ot_figure"].clone()), (json!(40.0), json!("tabularLining")));
|
||||
assert_eq!((shown["stroke_tint"].clone(), shown["ot_figure"].clone()), (json!("40.0"), json!("tabularLining")));
|
||||
cancel::<Existing>(&mut app);
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(app.session.doc().unwrap().doc, before);
|
||||
|
||||
@@ -186,14 +186,12 @@ mod tests {
|
||||
with(app, |h| h.set_json_field(&ctx, dialog_id(KIND), key, value)).unwrap();
|
||||
}
|
||||
|
||||
/// Presses OK; the pump then runs the held answer.
|
||||
/// Presses OK; the app's frames then run the held answer and close the dialog on it.
|
||||
fn confirm(app: &mut VectorcraftApp) {
|
||||
let ctx = app.ui_ctx.clone().unwrap();
|
||||
with(app, |h| h.confirm_by_id(&ctx, dialog_id(KIND)));
|
||||
for _ in 0..2 {
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |_| {});
|
||||
out.textures_delta.clear();
|
||||
crate::dialogs::host::pump(app, &ctx);
|
||||
crate::testing::app_frame(app, &ctx, egui::RawInput::default());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ mod tests {
|
||||
let mut p = Panel::new(app, draw);
|
||||
super::open(&mut p.app()).unwrap();
|
||||
// Add: the Entry field's word (kept in lower case) joins the list.
|
||||
p.type_into("Entry", " ZqvDictB ");
|
||||
p.type_into("Entry:", " ZqvDictB ");
|
||||
p.click("Add");
|
||||
assert_eq!(words(&p.app(), &[A, B, C]), [A, B]);
|
||||
assert!(!has(&mut p.app(), B), "not until Done");
|
||||
@@ -216,9 +216,9 @@ mod tests {
|
||||
super::open(&mut p.app()).unwrap();
|
||||
p.click(A);
|
||||
p.click("Delete");
|
||||
p.type_into("Entry", B);
|
||||
p.type_into("Entry:", B);
|
||||
p.click("Add");
|
||||
p.type_into("Entry", C);
|
||||
p.type_into("Entry:", C);
|
||||
p.click("Add");
|
||||
p.click("Done");
|
||||
assert!(!is_open(&p.app()), "Done closes it");
|
||||
@@ -244,7 +244,7 @@ mod tests {
|
||||
super::open(&mut p.app()).unwrap();
|
||||
p.click(P);
|
||||
p.click("Delete");
|
||||
p.type_into("Entry", Q);
|
||||
p.type_into("Entry:", Q);
|
||||
p.click("Add");
|
||||
assert_eq!(words(&p.app(), &[P, Q]), [Q]);
|
||||
p.click("Done");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! undo step:
|
||||
//!
|
||||
//! - **Warp Options** (`envelopeWarp`): Make with Warp, or Reset with Warp for a selected envelope
|
||||
//! (`reset`). Fields `style` (one of the 15 warp styles), `horizontal` (false: Vertical),
|
||||
//! (`reset`). Fields `style` (one of the 15 warp styles), `horizontal` (`horizontal` | `vertical`),
|
||||
//! `bend`, `h` and `v` (%, -100..100).
|
||||
//! - **Envelope Mesh** (`envelopeMesh`): Make with Mesh, or Reset with Mesh (`reset`, with
|
||||
//! `maintainShape`). Fields `rows`, `cols` (1..50).
|
||||
@@ -145,7 +145,7 @@ pub fn open(app: &mut VectorcraftApp, id: &str) -> Result<Value, String> {
|
||||
let warp = info["type"] == "warp";
|
||||
let own = |k: &str, d: f64| if warp { num(k, d) } else { d };
|
||||
let style = if warp { info["style"].clone() } else { json!("arc") };
|
||||
let horizontal = !warp || info["horizontal"] != false;
|
||||
let horizontal = if !warp || info["horizontal"] != false { "horizontal" } else { "vertical" };
|
||||
(
|
||||
WARP,
|
||||
json!({"reset": envelope, "style": style, "horizontal": horizontal, "bend": own("bend", 50.0), "h": own("h", 0.0), "v": own("v", 0.0)}),
|
||||
@@ -223,8 +223,8 @@ fn command(kind: &str, f: &Map<String, Value>) -> (&'static str, Value, &'static
|
||||
match kind {
|
||||
WARP => {
|
||||
let style = f.get("style").and_then(Value::as_str).unwrap_or("arc");
|
||||
let p =
|
||||
json!({"style": style, "horizontal": flag("horizontal", true), "bend": num("bend", 50.0), "h": num("h", 0.0), "v": num("v", 0.0)});
|
||||
let horizontal = f.get("horizontal").and_then(Value::as_str) != Some("vertical");
|
||||
let p = json!({"style": style, "horizontal": horizontal, "bend": num("bend", 50.0), "h": num("h", 0.0), "v": num("v", 0.0)});
|
||||
if reset { (RESET_WARP, p, "Reset with Warp") } else { (MAKE_WARP, p, "Make Envelope") }
|
||||
}
|
||||
MESH => {
|
||||
|
||||
@@ -97,23 +97,24 @@ fn selected(p: &Panel) -> Vec<u64> {
|
||||
p.app().session.active().unwrap().selection.objects.iter().map(|id| id.0).collect()
|
||||
}
|
||||
|
||||
/// The Edit menu's rows for Find and Replace, Check Spelling and Edit Custom Dictionary are enabled,
|
||||
/// and invoking each puts that dialog on the host.
|
||||
/// The Edit menu's rows for Find and Replace, Check Spelling (in its Spelling submenu) and Edit Custom Dictionary
|
||||
/// are enabled, and invoking each puts that dialog on the host.
|
||||
#[test]
|
||||
fn the_edit_menu_rows_open_their_dialogs() {
|
||||
type Shown = fn(&DialogHost) -> bool;
|
||||
let rows: [(&str, &str, Shown); 3] = [
|
||||
("Find and Replace…", super::COMMAND, |h| h.get::<FindReplaceDialog>().is_some()),
|
||||
("Check Spelling…", crate::dialogs::check_spelling::COMMAND, |h| !h.open_dialogs().is_empty()),
|
||||
("Edit Custom Dictionary…", crate::dialogs::custom_dictionary::COMMAND, |h| {
|
||||
let rows: [(&str, &[&str], &str, Shown); 3] = [
|
||||
("Find and Replace…", &["Edit"], super::COMMAND, |h| h.get::<FindReplaceDialog>().is_some()),
|
||||
("Check Spelling…", &["Edit", "Spelling"], crate::dialogs::check_spelling::COMMAND, |h| !h.open_dialogs().is_empty()),
|
||||
("Edit Custom Dictionary…", &["Edit"], crate::dialogs::custom_dictionary::COMMAND, |h| {
|
||||
h.get::<craft::ui::patterns::form_dialogs::HostedListManager>().is_some()
|
||||
}),
|
||||
];
|
||||
for (label, command, shown) in rows {
|
||||
for (label, path, command, shown) in rows {
|
||||
let (app, _) = app_with(&["Hello zqvmisspelt world"]);
|
||||
let p = Panel::new(app, draw);
|
||||
let e = crate::menus::menu_entries(&p.app()).into_iter().find(|e| e.label == label).unwrap_or_else(|| panic!("{label} is in the Edit menu"));
|
||||
assert_eq!((e.path.as_slice(), e.command.as_deref(), e.enabled), (&["Edit".to_string()][..], Some(command), true), "{label}");
|
||||
let shown_path: Vec<&str> = e.path.iter().map(String::as_str).collect();
|
||||
assert_eq!((shown_path.as_slice(), e.command.as_deref(), e.enabled), (path, Some(command), true), "{label}");
|
||||
choose_command(&p, command);
|
||||
assert!(p.app().dialogs().expect("a window").with(|host| shown(host)), "{label} opens its dialog");
|
||||
}
|
||||
@@ -208,6 +209,8 @@ fn replace_waits_for_a_match_of_the_text_as_it_is() {
|
||||
set(&p, "find", json!("ca"));
|
||||
pump(&p);
|
||||
assert_eq!(matched(&p), None);
|
||||
// The buttons' state is what a frame drew.
|
||||
p.frame();
|
||||
assert!(!p.enabled("Replace"));
|
||||
for button in ["Replace", "Replace & Find"] {
|
||||
p.click(button);
|
||||
|
||||
@@ -212,7 +212,9 @@ pub(crate) fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
let ctx = app.ui_ctx.clone().ok_or("no window")?;
|
||||
let dialog = HostedParamDialog::new(&ctx, KEY, option_fields(&FlattenOptions::default()), |_| {
|
||||
ParamDialog::new(KEY, tl!("Flatten Transparency"), option_params(&[], "")).previews(true)
|
||||
});
|
||||
})
|
||||
// Flattening complex art is slow: the preview waits until it is turned on.
|
||||
.preview_off();
|
||||
let held = HeldOptions {
|
||||
parent: None,
|
||||
cancel: Some(Box::new(|app: &mut VectorcraftApp| {
|
||||
|
||||
@@ -130,10 +130,10 @@ mod tests {
|
||||
app.dialogs().expect("a window")
|
||||
}
|
||||
|
||||
/// One frame: the host's pump carries out what the manager queued.
|
||||
/// One app frame: the host's pump carries out what the manager queued, and answered panels are taken.
|
||||
fn frame(app: &mut VectorcraftApp) {
|
||||
let ctx = ctx(app);
|
||||
super::super::host::pump(app, &ctx);
|
||||
crate::testing::app_frame(app, &ctx, egui::RawInput::default());
|
||||
}
|
||||
|
||||
/// Press a manager button as the user does: the manager queues it and the pump carries it out.
|
||||
|
||||
@@ -242,7 +242,9 @@ impl StackDialog for GradientStopPopover {
|
||||
}
|
||||
"color" => {
|
||||
let hex = value.as_str().ok_or_else(|| rejects(field, &value))?;
|
||||
self.set.color = Some(Color::from_hex(hex).ok_or_else(|| format!("bad colour `{hex}` (#rrggbb)"))?);
|
||||
// Hex digits only: `Color::from_hex` also takes a few colour names.
|
||||
let color = Srgba::from_hex(hex).and_then(|_| Color::from_hex(hex));
|
||||
self.set.color = Some(color.ok_or_else(|| format!("bad colour `{hex}` (#rrggbb)"))?);
|
||||
}
|
||||
"opacity" => self.set.opacity = Some(number()?),
|
||||
"location" => self.set.location = Some(number()?),
|
||||
|
||||
@@ -699,6 +699,8 @@ impl StackDialog for GraphDataDialog {
|
||||
.ok_enabled(!held.is_waiting())
|
||||
.accept_stays_open(true)
|
||||
.enter_confirms(false)
|
||||
// The sheet owns the scroll; the controls above it stay in view.
|
||||
.collection_body(true)
|
||||
.shaped(|dialog| dialog.initial_focus(Initial::Default))
|
||||
.show(ui, |ui, _, values| body(ui, values, &mut pane));
|
||||
// The pass reports a press only in the pass that took the input, so a second pass of the frame files nothing.
|
||||
|
||||
@@ -120,7 +120,8 @@ mod tests {
|
||||
driver::set(&mut app, "hyphenate", json!(true));
|
||||
driver::set(&mut app, "wordsLongerThan", json!(8));
|
||||
driver::set(&mut app, "hyphenLimit", json!(2));
|
||||
driver::set(&mut app, "hyphenationZone", json!("1 in"));
|
||||
// A length row holds points (1 in), whatever unit its field shows.
|
||||
driver::set(&mut app, "hyphenationZone", json!(72));
|
||||
driver::set(&mut app, "hyphenateCapitalized", json!(false));
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
driver::ok(&mut app);
|
||||
|
||||
@@ -165,7 +165,8 @@ mod tests {
|
||||
for (field, value) in [("reduction", "blackWhite"), ("dither", "none")] {
|
||||
host.with(|h| h.set_json_field(&ctx, dialog, field, json!(value))).unwrap();
|
||||
}
|
||||
assert!(host.with(|h| h.confirm_by_id(&ctx, dialog)));
|
||||
// OK files the held answer, which the pump applies.
|
||||
host.with(|h| h.confirm_by_id(&ctx, dialog));
|
||||
crate::dialogs::host::pump(&mut app, &ctx);
|
||||
let st = app.session.doc().unwrap();
|
||||
assert_eq!(st.history.undo.len(), undo + 1);
|
||||
|
||||
@@ -182,11 +182,16 @@ fn selected_row(files: &[(String, String)], selected: &str) -> Option<usize> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The rows the linked-files list shows, empty or not, before it scrolls.
|
||||
const LIST_ROWS: u16 = 6;
|
||||
|
||||
fn body(ui: &mut Ui, files: &[(String, String)], form: &mut Form) {
|
||||
let source = keyed(files, |(linked, _): &(String, String)| linked.clone());
|
||||
let selection =
|
||||
selected_row(files, &form.selected).and_then(|i| files.get(i)).map(|(linked, _)| Selection::single(linked.clone())).unwrap_or_default();
|
||||
let list = List::<String>::options(tl!("Linked files"))
|
||||
.min_rows(LIST_ROWS)
|
||||
.max_rows(LIST_ROWS)
|
||||
.selection(Bind::given(selection))
|
||||
.sizing(Sizing::FillWidth)
|
||||
.empty(tl!("No JavaScript files linked"))
|
||||
|
||||
@@ -264,9 +264,10 @@ impl KinsokuDialog {
|
||||
set.remove("from");
|
||||
set.insert("name".into(), json!(name));
|
||||
list.push(set);
|
||||
let last = list.len() - 1;
|
||||
// The fields are already committed: picking would write them into the new set when the old pick has its index.
|
||||
self.selected = list.len() - 1;
|
||||
self.sets = json!(list);
|
||||
self.pick(last);
|
||||
self.load();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user