mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-15 21:57:04 +00:00
Type: Composite Fonts takes custom, entry and char from ui.dialog.set on open
The dialog opened without the custom, entry and char fields, so ui.dialog.set refused them until Custom was clicked or an entry typed. The spec now lists them in its inputs, and the dialog opens with custom off and an empty entry.
This commit is contained in:
@@ -42,12 +42,21 @@ const CHARS_PER_ROW: usize = 20;
|
||||
/// and a few custom sets.
|
||||
const TABLE_HEIGHT: f32 = 340.0;
|
||||
|
||||
pub(super) const SPEC: DialogSpec = DialogSpec { heading: |_| tl!("Composite Fonts").into(), body, confirm, min_width: 760.0, ..DialogSpec::FORM };
|
||||
/// `char` is held only while a character is picked, so `ui.dialog.set` takes it from `inputs`.
|
||||
pub(super) const SPEC: DialogSpec = DialogSpec {
|
||||
heading: |_| tl!("Composite Fonts").into(),
|
||||
body,
|
||||
confirm,
|
||||
min_width: 760.0,
|
||||
inputs: |_| &["custom", "entry", "char"],
|
||||
..DialogSpec::FORM
|
||||
};
|
||||
|
||||
/// Open Composite Fonts on the active document's composite fonts, the first one picked.
|
||||
/// Open Composite Fonts on the active document's composite fonts, the first one picked, with the
|
||||
/// custom character sets hidden and nothing typed.
|
||||
pub fn open(app: &mut VectorcraftApp) -> Result<Value, String> {
|
||||
let fonts = app.session.active().ok_or("no document open")?.doc.composite_fonts.to_vec();
|
||||
let mut d = Dialog::new(KIND, json!({ "fonts": fonts, "selected": 0, "entryMode": "direct" }));
|
||||
let mut d = Dialog::new(KIND, json!({ "fonts": fonts, "selected": 0, "custom": false, "entryMode": "direct", "entry": "" }));
|
||||
show_selected(&mut d);
|
||||
app.ui.dialog = Some(d);
|
||||
Ok(Value::Null)
|
||||
|
||||
@@ -244,6 +244,27 @@ fn custom_character_sets_are_edited_in_the_dialog() {
|
||||
assert_eq!((f.custom.len(), f.custom[0].name.as_str(), f.custom[0].characters.as_str()), (1, "Letters", "Aあ"));
|
||||
}
|
||||
|
||||
/// `ui.dialog.set` takes `custom`, `entry` and `char` as soon as the dialog opens, before Custom is
|
||||
/// clicked or anything is typed, and Add then adds the characters it set.
|
||||
#[test]
|
||||
fn custom_set_fields_are_set_right_after_open() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let font =
|
||||
json!({"name": "UI Composite Open", "parts": {"kanji": {"font": "Inter"}}, "custom": [{"name": "Marks", "characters": "", "font": "Inter"}]});
|
||||
app.run(COMMAND, json!({ "fonts": [font] })).unwrap();
|
||||
open(&mut app).unwrap();
|
||||
for (field, value) in [("custom", json!(true)), ("entry", json!("※〒")), ("char", json!(0))] {
|
||||
let (req, _) = crate::control::ControlRequest::new("ui.dialog.set", json!({"field": field, "value": value}));
|
||||
let crate::control::Outcome::Done(r) = crate::control::handle(&mut app, &ctx, &req) else { panic!("not done") };
|
||||
assert!(r.get("error").is_none(), "{field}: {r}");
|
||||
assert_eq!(dialog(&mut app).fields.get(field), Some(&value), "{field}");
|
||||
}
|
||||
frame(&mut app);
|
||||
press(&mut app, Action::AddChars);
|
||||
assert_eq!(sets(&mut app)[0].characters, "※〒");
|
||||
}
|
||||
|
||||
/// Two sets of the same name keep the dialog open and change nothing.
|
||||
#[test]
|
||||
fn custom_sets_sharing_a_name_keep_the_dialog_open() {
|
||||
|
||||
+2
-1
@@ -9333,7 +9333,8 @@ picked. Custom shows the font's custom character sets: Character Set picks one,
|
||||
Delete Set takes it out, and Name renames it. Character › Direct Entry adds the characters typed, and Character ›
|
||||
Unicode adds the characters of hexadecimal codes (`3042`, `U+3042`, several separated by spaces or commas); Add skips
|
||||
characters the set already lists. Delete takes the character picked out of the set. OK runs `type.compositeFonts.set`
|
||||
with every font as one undo step; a refused font keeps the dialog open.
|
||||
with every font as one undo step; a refused font keeps the dialog open. `ui.dialog.set` takes `custom`, `entry` and
|
||||
`char` (the index of the character picked in the set) as soon as the dialog opens.
|
||||
|
||||
```json
|
||||
{"name":"run_command","arguments":{"command":"type.compositeFonts.set","params":{"fonts":[{"name":"My Composite","parts":{"kanji":{"font":"Source Han Sans"},"roman":{"font":"Source Sans 3","size":95,"baseline":-2},"numerals":{"font":"Source Sans 3"}}}]}}}
|
||||
|
||||
Reference in New Issue
Block a user