mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Bind live East Asian text settings fields
This commit is contained in:
1 parent
315c07fe9d
commit
a8540a2dfb
2 files changed
+40
-2
No files matched your search
@@ -10,6 +10,7 @@
|
||||
//! Behavior reference (public documentation):
|
||||
//! <https://helpx.adobe.com/illustrator/desktop/design-with-text/edit-format-text/format-east-asian-characters-in-vertical-text.html>.
|
||||
|
||||
use craft::ui::contract::Bind;
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, Param, ParamDialog};
|
||||
// PLAN: assumed path of `LengthUnits`
|
||||
use craft::ui::runtime::env::LengthUnits;
|
||||
@@ -47,7 +48,9 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
let initial = fields.clone();
|
||||
let ctx = app.ui_ctx.clone().ok_or("no window")?;
|
||||
let lengths = crate::canvas::rulers::type_lengths(app);
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |_| ParamDialog::new(KIND, tl!("Tate-chu-yoko Settings"), rows(lengths)));
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |fields| {
|
||||
ParamDialog::new(KIND, tl!("Tate-chu-yoko Settings"), rows(lengths)).values(Bind::bound(fields))
|
||||
});
|
||||
super::host::open_held(app, dialog, move |app, result| {
|
||||
let p = params(&result.fields, &initial);
|
||||
if p.is_empty() {
|
||||
@@ -99,6 +102,17 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tate_chu_yoko_settings_step_the_opening_number_on_ok() {
|
||||
let (mut app, id) = app();
|
||||
app.run("text.setFormat", json!({"tcyUpDown": 3, "tcyLeftRight": -7})).unwrap();
|
||||
let mut panel = crate::tests::panel_harness::Panel::new(app, crate::tests::picks::dialogs);
|
||||
panel.app().run("ui.tateChuYokoSettings", json!({})).unwrap();
|
||||
driver::step_number_and_ok(&mut panel, "Up/Down");
|
||||
assert_eq!(offsets(&panel.app(), id), [(4.0, -7.0)]);
|
||||
assert!(!driver::is_open(&panel.app()));
|
||||
}
|
||||
|
||||
/// `ui.tateChuYokoSettings` opens on the characters' values; OK sets both in one undo step.
|
||||
/// Automation sets the offsets in points, as a number row takes them.
|
||||
#[test]
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
//! Behavior reference (public documentation):
|
||||
//! <https://helpx.adobe.com/illustrator/using/formatting-asian-characters.html>.
|
||||
|
||||
use craft::ui::contract::Bind;
|
||||
use craft::ui::patterns::form_dialogs::{DialogFields, FieldValue, HostedParamDialog, Param, ParamDialog, ParamKind};
|
||||
// PLAN: assumed path of `UnitKind`
|
||||
use craft::ui::runtime::env::UnitKind;
|
||||
@@ -78,7 +79,9 @@ pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
let initial = fields.clone();
|
||||
let ctx = app.ui_ctx.clone().ok_or("no window")?;
|
||||
let lengths = crate::canvas::rulers::type_lengths(app);
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |_| ParamDialog::new(KIND, tl!("Warichu Settings"), rows(lengths)));
|
||||
let dialog = HostedParamDialog::new(&ctx, KIND, fields, move |fields| {
|
||||
ParamDialog::new(KIND, tl!("Warichu Settings"), rows(lengths)).values(Bind::bound(fields))
|
||||
});
|
||||
super::host::open_held(app, dialog, move |app, result| {
|
||||
let p = params(&result.fields, &initial);
|
||||
if p.is_empty() {
|
||||
@@ -165,6 +168,16 @@ pub(super) mod driver {
|
||||
app.dialogs().expect("window").with(|h| h.set_json_field(&ctx, id, key, value))
|
||||
}
|
||||
|
||||
/// Steps a focused number field up once and clicks the dialog's OK button.
|
||||
pub fn step_number_and_ok(panel: &mut crate::tests::panel_harness::Panel, label: &str) {
|
||||
panel.frame();
|
||||
let field = panel.rect_role(label, craft::ui::contract::Role::SPIN_BUTTON).center();
|
||||
panel.click_at(field);
|
||||
panel.key(egui::Key::ArrowUp, egui::Modifiers::NONE);
|
||||
panel.key(egui::Key::Tab, egui::Modifiers::NONE);
|
||||
panel.click("OK");
|
||||
}
|
||||
|
||||
/// Runs the frame's pump.
|
||||
pub fn pump(app: &mut VectorcraftApp) {
|
||||
let ctx = ctx(app);
|
||||
@@ -216,6 +229,17 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warichu_settings_step_the_opening_number_on_ok() {
|
||||
let (mut app, id) = app();
|
||||
app.run("text.setFormat", json!({"warichuLines": 3, "warichuScale": 70})).unwrap();
|
||||
let mut panel = crate::tests::panel_harness::Panel::new(app, crate::tests::picks::dialogs);
|
||||
panel.app().run("ui.warichuSettings", json!({})).unwrap();
|
||||
driver::step_number_and_ok(&mut panel, "Lines");
|
||||
assert_eq!(settings(&panel.app(), id), [(false, 4, 0.0, 70.0, WarichuAlign::Auto)]);
|
||||
assert!(!driver::is_open(&panel.app()));
|
||||
}
|
||||
|
||||
/// `ui.warichuSettings` opens on the characters' values; OK sets the changed ones in one undo
|
||||
/// step without turning Warichu on. A value past the ends is refused as it is set (the framework's
|
||||
/// `FieldRefusal::Rejects`); OK keeps an unedited one to them (the test below). Automation sets the
|
||||
|
||||
Reference in new issue
Block a user