mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
UI: Bullets, character color, composite font, Map Art and Find Font lists apply only a chosen entry
These lists read the value their select proposed this pass, so an entry highlighted with the arrow keys was applied before it was chosen, and Escape left it applied. Each one now reads the committed entry: - Bullets and Numbering's Alignment - Character Style Options' Fill and Stroke - the Composite Fonts parts table's Style - the 3D (Classic) Map Art page's Symbol - Find Font's Replace With Font From and Find In Each list has a test that highlights an entry with the arrow keys, checks that nothing changed, presses Escape and checks again, and then chooses an entry with Enter.
This commit is contained in:
1 parent
89a5b64170
commit
fe15116f4c
8 files changed
+223
-6
No files matched your search
@@ -404,7 +404,7 @@ impl BulletsDialog {
|
||||
let entries = [Entry::new(0usize, tl!("Left")), Entry::new(1, tl!("Right"))];
|
||||
let current = self.fields.get("listAlign").and_then(Value::as_str).and_then(|a| ALIGNS.iter().position(|x| *x == a));
|
||||
let edit = Select::new(tl!("Alignment:"), Bind::given(current.map_or(Mixed::Mixed, Mixed::Same)), &entries).show(ui);
|
||||
if let Some(&i) = edit.value()
|
||||
if let Some(&i) = edit.events.committed()
|
||||
&& let Some(a) = ALIGNS.get(i)
|
||||
{
|
||||
self.fields.insert("listAlign".into(), json!(a));
|
||||
@@ -924,6 +924,48 @@ mod tests {
|
||||
assert!(app.run("ui.bulletsAndNumbering", json!({})).is_err(), "no type selected");
|
||||
}
|
||||
|
||||
/// Alignment: an entry highlighted with the arrow keys changes no field and leaves the type as it was, Escape
|
||||
/// closes the list with the dialog open and nothing changed, and Enter applies the entry.
|
||||
#[test]
|
||||
fn a_highlighted_alignment_applies_only_once_it_is_chosen() {
|
||||
use craft::ui::contract::Role;
|
||||
use egui::{Key, Modifiers};
|
||||
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 10, "y": 10, "text": "One\nTwo", "area": {"width": 200, "height": 100}})).unwrap()["id"]
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
let mut panel = Panel::new(app, crate::tests::picks::dialogs);
|
||||
panel.room(egui::vec2(1280.0, 1100.0));
|
||||
panel.app().run("ui.bulletsAndNumbering", json!({})).unwrap();
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
let state = |panel: &Panel| {
|
||||
let app = panel.app();
|
||||
(fields(&app)["listAlign"].clone(), first(&app, id))
|
||||
};
|
||||
let before = state(&panel);
|
||||
assert_eq!(before.0, "left");
|
||||
panel.click_role("Alignment:", Role::COMBO_BOX);
|
||||
panel.key(Key::ArrowDown, Modifiers::NONE);
|
||||
panel.frame();
|
||||
assert_eq!(state(&panel), before, "a highlighted alignment changes no field and leaves the type as it was");
|
||||
panel.key(Key::Escape, Modifiers::NONE);
|
||||
panel.frame();
|
||||
assert!(is_open(&panel.app()), "Escape closes the list, not the dialog");
|
||||
assert_eq!(state(&panel), before, "Escape leaves the alignment as it was");
|
||||
panel.click_role("Alignment:", Role::COMBO_BOX);
|
||||
panel.key(Key::ArrowDown, Modifiers::NONE);
|
||||
panel.key(Key::Enter, Modifiers::NONE);
|
||||
panel.frame();
|
||||
assert!(is_open(&panel.app()), "Enter in the list keeps the dialog open");
|
||||
assert_eq!(state(&panel).0, "right", "Enter applies the alignment");
|
||||
}
|
||||
|
||||
/// Cancel puts back what the preview changed: the list, its alignment and the indents.
|
||||
#[test]
|
||||
fn cancel_puts_the_type_back_as_it_was() {
|
||||
|
||||
@@ -826,7 +826,7 @@ fn paint_row(key: &'static str, label: &'static str, swatches: Vec<(String, Valu
|
||||
entries.push(Entry::new(selected.clone(), Label::from(shown)));
|
||||
}
|
||||
let out = Select::new(Label::from(label), Bind::given(selected), &entries).show(ui);
|
||||
if let Some(id) = out.value().cloned() {
|
||||
if let Some(id) = out.events.committed().cloned() {
|
||||
let paint = match id.as_str() {
|
||||
"" => Some(Value::Null),
|
||||
"none" => Some(json!({"type": "none"})),
|
||||
|
||||
@@ -1007,6 +1007,46 @@ fn color_and_features_preview_cancel_commit_and_new_style() {
|
||||
assert!(t.runs.iter().all(|r| r.style.style_name.as_deref() == Some("Body")));
|
||||
}
|
||||
|
||||
/// Character Color's Fill and Stroke: a paint highlighted with the arrow keys changes no field and leaves the
|
||||
/// document as it was, Escape closes the list with the dialog open and nothing changed, and Enter sets the paint.
|
||||
#[test]
|
||||
fn a_highlighted_character_color_paint_applies_only_once_it_is_chosen() {
|
||||
use craft::ui::contract::Role;
|
||||
use egui::{Key, Modifiers};
|
||||
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
for (name, key) in [("Fill", "fill"), ("Stroke", "stroke")] {
|
||||
let mut app = app();
|
||||
styled(&mut app, json!({"size": 24.0}), "Text");
|
||||
let mut panel = Panel::new(app, crate::tests::picks::dialogs);
|
||||
panel.room(egui::vec2(1280.0, 1100.0));
|
||||
open(&mut panel.app(), "Body");
|
||||
set::<Existing>(&panel.app(), "tab", json!("color"));
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
let state = |panel: &Panel| {
|
||||
let app = panel.app();
|
||||
(fields::<Existing>(&app), app.session.doc().unwrap().doc.clone())
|
||||
};
|
||||
let before = state(&panel);
|
||||
panel.click_role(name, Role::COMBO_BOX);
|
||||
panel.key(Key::ArrowDown, Modifiers::NONE);
|
||||
panel.frame();
|
||||
assert_eq!(state(&panel), before, "a highlighted {name} paint changes nothing");
|
||||
panel.key(Key::Escape, Modifiers::NONE);
|
||||
panel.frame();
|
||||
assert!(is_open::<Existing>(&panel.app()), "Escape closes the {name} list, not the dialog");
|
||||
assert_eq!(state(&panel), before, "Escape leaves {name} as it was");
|
||||
panel.click_role(name, Role::COMBO_BOX);
|
||||
panel.key(Key::ArrowDown, Modifiers::NONE);
|
||||
panel.key(Key::Enter, Modifiers::NONE);
|
||||
panel.frame();
|
||||
assert!(is_open::<Existing>(&panel.app()), "Enter in the {name} list keeps the dialog open");
|
||||
assert_ne!(state(&panel).0[key], before.0[key], "Enter sets the {name} paint");
|
||||
}
|
||||
}
|
||||
|
||||
/// A size or leading below the minimum is refused by OK and runs no preview.
|
||||
#[test]
|
||||
fn size_and_leading_below_minimum_do_not_preview_or_commit() {
|
||||
|
||||
@@ -604,7 +604,7 @@ impl CompositeFontsDialog {
|
||||
}
|
||||
})
|
||||
.cell_field(STYLE, style, move |out| {
|
||||
if let Some(style) = out.value().cloned() {
|
||||
if let Some(style) = out.events.committed().cloned() {
|
||||
edits.borrow_mut().push((at, PartEdit::Style(style)));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -612,6 +612,44 @@ fn custom_character_sets_draw_their_characters_and_the_buttons() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The parts table's Style: a style highlighted with the arrow keys leaves the font's parts as they were, Escape closes
|
||||
/// the list with nothing changed, and Enter sets the style.
|
||||
#[test]
|
||||
fn a_highlighted_part_style_applies_only_once_it_is_chosen() {
|
||||
use craft::ui::contract::Role;
|
||||
use egui::{Key, Modifiers};
|
||||
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
let mut p = Panel::new(app(), crate::tests::picks::dialogs);
|
||||
p.room(egui::vec2(1280.0, 1100.0));
|
||||
open(&mut p.app()).unwrap();
|
||||
new_font(&mut p.app());
|
||||
dialog(&mut p.app(), |d| {
|
||||
for class in CharClass::ALL {
|
||||
d.edit_part(row(class), PartEdit::Font("Source Sans 3".into(), Some("Regular".into())));
|
||||
}
|
||||
});
|
||||
p.frame();
|
||||
p.frame();
|
||||
let parts = |p: &Panel| dialog(&mut p.app(), |d| d.font().map(|f| f.parts.clone()));
|
||||
let before = parts(&p);
|
||||
p.click_role("Style", Role::COMBO_BOX);
|
||||
p.key(Key::ArrowDown, Modifiers::NONE);
|
||||
p.frame();
|
||||
assert_eq!(parts(&p), before, "a highlighted style changes no part");
|
||||
p.key(Key::Escape, Modifiers::NONE);
|
||||
p.frame();
|
||||
assert!(is_open(&p.app()), "Escape closes the list, not the dialog");
|
||||
assert_eq!(parts(&p), before, "Escape leaves the parts as they were");
|
||||
p.click_role("Style", Role::COMBO_BOX);
|
||||
p.key(Key::ArrowDown, Modifiers::NONE);
|
||||
p.key(Key::Enter, Modifiers::NONE);
|
||||
p.frame();
|
||||
assert!(is_open(&p.app()), "Enter in the list keeps the dialog open");
|
||||
assert_ne!(parts(&p), before, "Enter sets the style");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn composite_fonts_approval_does_not_replace_definitions_restored_by_revert() {
|
||||
let mut app = app();
|
||||
|
||||
@@ -158,6 +158,61 @@ fn map_art_maps_a_symbol_onto_a_surface_of_extrude_and_bevel_classic() {
|
||||
assert!(params.get("__mapArt").is_none() && params.get("__mapSurface").is_none(), "the dialog's own state stays out of the effect");
|
||||
}
|
||||
|
||||
/// Map Art's Symbol: a symbol highlighted with the arrow keys maps nothing and leaves the drawing as it was, Escape
|
||||
/// closes the list with the dialog open and nothing changed, and Enter maps the symbol.
|
||||
#[test]
|
||||
fn a_highlighted_map_art_symbol_applies_only_once_it_is_chosen() {
|
||||
use craft::ui::contract::Role;
|
||||
use craft::ui::dialog::StackDialog as _;
|
||||
|
||||
use super::super::three_d;
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
fn whole_frame(app: &mut VectorcraftApp, ui: &mut egui::Ui) {
|
||||
app.tick(ui.ctx());
|
||||
app.ui(ui);
|
||||
}
|
||||
fn settle(panel: &mut Panel) {
|
||||
for _ in 0..6 {
|
||||
panel.frame();
|
||||
}
|
||||
}
|
||||
|
||||
let mut panel = Panel::new(with_symbol("M50 50L150 50L150 150L50 150Z"), whole_frame);
|
||||
panel.room(vec2(1440.0, 900.0));
|
||||
settle(&mut panel);
|
||||
if let Err(e) = effect::open(&mut panel.app(), &json!({"effect": CLASSIC_EXTRUDE, "item": null})) {
|
||||
panic!("the dialog did not open: {e}");
|
||||
}
|
||||
settle(&mut panel);
|
||||
let ctx = panel.ctx().clone();
|
||||
let page = three_d::with_fields(&mut panel.app(), |d| d.set_json_field(&ctx, "__page", json!("mapArt")));
|
||||
assert!(matches!(page, Some(Ok(()))), "{page:?}");
|
||||
settle(&mut panel);
|
||||
let state = |panel: &Panel| {
|
||||
let mut app = panel.app();
|
||||
let maps = three_d::with_fields(&mut app, |d| d.json_fields()).flatten().and_then(|v| v.get("mapArt").cloned()).unwrap_or(Value::Null);
|
||||
(maps, app.session.doc().unwrap().doc.clone())
|
||||
};
|
||||
let before = state(&panel);
|
||||
assert!(vectorcraft_effects::surface_maps(&json!({"mapArt": before.0})).is_empty(), "no surface has a map yet");
|
||||
panel.click_role("Symbol", Role::COMBO_BOX);
|
||||
panel.key(Key::ArrowDown, Modifiers::NONE);
|
||||
settle(&mut panel);
|
||||
assert_eq!(state(&panel), before, "a highlighted symbol maps nothing");
|
||||
panel.key(Key::Escape, Modifiers::NONE);
|
||||
settle(&mut panel);
|
||||
assert!(panel.app().three_d_dialog.is_some(), "Escape closes the list, not the dialog");
|
||||
assert_eq!(state(&panel), before, "Escape leaves the maps as they were");
|
||||
panel.click_role("Symbol", Role::COMBO_BOX);
|
||||
panel.key(Key::ArrowDown, Modifiers::NONE);
|
||||
panel.key(Key::Enter, Modifiers::NONE);
|
||||
settle(&mut panel);
|
||||
assert!(panel.app().three_d_dialog.is_some(), "Enter in the list keeps the dialog open");
|
||||
let maps = vectorcraft_effects::surface_maps(&json!({"mapArt": state(&panel).0}));
|
||||
assert_eq!(maps.iter().map(|m| (m.surface, m.symbol.as_str())).collect::<Vec<_>>(), [(1, "Mark")], "Enter maps the symbol");
|
||||
}
|
||||
|
||||
/// The theme's plot size, as a pass of the app's interface resolves it.
|
||||
fn plot_size() -> egui::Vec2 {
|
||||
let mut plot = None;
|
||||
|
||||
@@ -485,7 +485,7 @@ pub(crate) fn map_art_params(data: &Data, fields: &DialogFields, effect: &str) -
|
||||
// A custom row, so a pick and automation both write the map through `set_map_value`.
|
||||
let symbol = Param::custom(MAP_SYMBOL, tl!("Symbol"), move |ui, fields, _| {
|
||||
let picked = Select::new(tl!("Symbol"), Bind::given(shown.clone()), &entries).id_salt(MAP_SYMBOL).show(ui);
|
||||
if let Some(name) = picked.value().cloned() {
|
||||
if let Some(name) = picked.events.committed().cloned() {
|
||||
// The select lists only what the map takes: a refusal cannot come from it.
|
||||
let _ = set_map_value(fields, MAP_SYMBOL, json!(name));
|
||||
}
|
||||
|
||||
@@ -529,7 +529,7 @@ impl StackDialog for FindFontDialog {
|
||||
crate::panels::section(tl!("Replace With Font").to_string()).show(ui, |ui, _| {
|
||||
Field::new(tl!("Replace With Font From").to_string()).show(ui, |ui, _| {
|
||||
let edit = Select::new(tl!("Replace With Font From").to_string(), Bind::given(source), &source_entries).show(ui);
|
||||
new_source = edit.events.value().copied();
|
||||
new_source = edit.events.committed().copied();
|
||||
});
|
||||
let edit = TextField::search(tl!("Search").to_string(), Bind::given(self.search.clone())).show(ui);
|
||||
new_search = edit.events.value().cloned();
|
||||
@@ -544,7 +544,7 @@ impl StackDialog for FindFontDialog {
|
||||
});
|
||||
Field::new(tl!("Find In").to_string()).show(ui, |ui, _| {
|
||||
let edit = Select::new(tl!("Find In").to_string(), Bind::given(find_in), &find_in_entries).show(ui);
|
||||
new_find_in = edit.events.value().copied();
|
||||
new_find_in = edit.events.committed().copied();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1013,6 +1013,48 @@ mod tests {
|
||||
// PLAN: files-w11 owns Missing Fonts' hosted type; its test asserts the search there
|
||||
}
|
||||
|
||||
/// Replace With Font From and Find In: an entry highlighted with the arrow keys changes no choice, Escape closes
|
||||
/// the list with the dialog open and nothing changed, and Enter applies the entry.
|
||||
#[test]
|
||||
fn a_highlighted_source_or_find_in_applies_only_once_it_is_chosen() {
|
||||
use craft::ui::contract::Role;
|
||||
use egui::{Key, Modifiers};
|
||||
|
||||
use crate::tests::panel_harness::Panel;
|
||||
|
||||
// Replace With Font From opens on System, its last entry, and Find In on Document, its first.
|
||||
for (name, step) in [("Replace With Font From", Key::ArrowUp), ("Find In", Key::ArrowDown)] {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
app.session.execute("text.create", &json!({"x": 10, "y": 40, "text": "Hi", "font": "Inter"})).unwrap();
|
||||
let mut panel = Panel::new(app, crate::tests::picks::dialogs);
|
||||
panel.room(egui::vec2(1280.0, 1100.0));
|
||||
open(&mut panel.app());
|
||||
panel.frame();
|
||||
panel.frame();
|
||||
let state = |panel: &Panel| {
|
||||
let d = opened(&panel.app());
|
||||
(d.replace_from, d.find_in)
|
||||
};
|
||||
let before = state(&panel);
|
||||
assert_eq!(before, ("system".to_string(), "document".to_string()));
|
||||
panel.click_role(name, Role::COMBO_BOX);
|
||||
panel.key(step, Modifiers::NONE);
|
||||
panel.frame();
|
||||
assert_eq!(state(&panel), before, "a highlighted {name} entry changes no choice");
|
||||
panel.key(Key::Escape, Modifiers::NONE);
|
||||
panel.frame();
|
||||
assert!(panel.app().dialogs().unwrap().with(|host| host.is_open::<FindFontDialog>()), "Escape closes the {name} list, not the dialog");
|
||||
assert_eq!(state(&panel), before, "Escape leaves {name} as it was");
|
||||
panel.click_role(name, Role::COMBO_BOX);
|
||||
panel.key(step, Modifiers::NONE);
|
||||
panel.key(Key::Enter, Modifiers::NONE);
|
||||
panel.frame();
|
||||
assert!(panel.app().dialogs().unwrap().with(|host| host.is_open::<FindFontDialog>()), "Enter in the {name} list keeps the dialog open");
|
||||
assert_ne!(state(&panel), before, "Enter applies the {name} entry");
|
||||
}
|
||||
}
|
||||
|
||||
/// `f`'s answer, read while the font menu held still: tests running alongside add fonts to
|
||||
/// the shared database and lend it composite fonts.
|
||||
fn while_fonts_hold<T>(mut f: impl FnMut() -> T) -> T {
|
||||
|
||||
Reference in new issue
Block a user