mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 22:08:42 +00:00
Give scrolling collections their owner and tests the app's UI context
A collection inside a body that scrolls along its rows now says who scrolls: the Recolor Color Groups list and color bars and the Export for Screens items cap their rows at the height production's panes had; the Symbols, Graphic Styles and Links panels and the Swatches paint popover hand the scroll to their one collection; the plates list, the opacity mask row, the character alternates bar and the Export for Screens tabs take their natural height. Tests that drew on a bare egui context now use testing::ui_context, so the framework runtime and its command registry are installed as in the app.
This commit is contained in:
@@ -62,7 +62,7 @@ fn every_adjustment_offered_is_a_colour_adjustment_with_its_defaults() {
|
||||
#[test]
|
||||
fn the_halftone_effect_dialog_has_the_command_fields_and_edits_the_effect() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
open(&mut app, &ctx, json!({"effect": "addon.color.halftone"}));
|
||||
let (_, fields) = top(&app);
|
||||
let shown: std::collections::BTreeSet<&str> = fields.as_object().unwrap().keys().map(String::as_str).collect();
|
||||
@@ -84,7 +84,7 @@ fn the_halftone_effect_dialog_has_the_command_fields_and_edits_the_effect() {
|
||||
#[test]
|
||||
fn the_duotone_dialog_has_a_row_per_tone_and_the_curve_of_one() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("swatch.new", json!({"name": "Ink", "color": "#e07020", "spot": true})).unwrap();
|
||||
open(&mut app, &ctx, json!({"effect": "addon.color.duotone"}));
|
||||
assert!(app.session.in_interaction(), "the preview runs");
|
||||
|
||||
@@ -115,7 +115,7 @@ fn an_unsaved_document_asks_for_a_folder() {
|
||||
let dir = folder("picked");
|
||||
let mut app = app();
|
||||
let picker = scripted(&mut app);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
click(&mut app, "Save a Timestamped Copy");
|
||||
assert!(asked_for_folder(&picker));
|
||||
picker.answer(&[dir.to_str().unwrap()]);
|
||||
@@ -169,7 +169,7 @@ fn export_all_open_documents_writes_each_to_the_folder_picked() {
|
||||
std::fs::create_dir_all(&out).unwrap();
|
||||
std::fs::write(out.join(format!("{untitled}.pdf")), b"keep").unwrap();
|
||||
let picker = scripted(&mut app);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let active = app.session.active_index();
|
||||
click(&mut app, "Export All Open Documents as PDF");
|
||||
assert!(asked_for_folder(&picker));
|
||||
@@ -214,7 +214,7 @@ fn batch_trace_folder_asks_for_both_folders() {
|
||||
std::fs::write(src.join("b.png"), b"not a png").unwrap();
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let picker = scripted(&mut app);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
click(&mut app, "Batch Trace Folder");
|
||||
// The destination is asked only after the source is answered.
|
||||
assert_eq!(picker.requests().len(), 1);
|
||||
|
||||
@@ -124,6 +124,7 @@ pub(super) fn alternates_bar(app: &mut VectorcraftApp, ui: &mut Ui, space: &Canv
|
||||
.thumb_size(ThumbSize::Small)
|
||||
.caption(CaptionPlace::None)
|
||||
.card_columns(found.count())
|
||||
.natural_height(true)
|
||||
.activate(ActivateOn::Click)
|
||||
.show_items(ui, &Cells(found.count()), &mut |key, _| {
|
||||
let cell = GlyphCell::Glyph(found.gid(*key).unwrap_or_default());
|
||||
|
||||
@@ -209,7 +209,7 @@ fn columns_and_rows(c: &[egui::Rect]) -> (usize, usize) {
|
||||
#[test]
|
||||
fn n_up_shows_that_many_documents_and_keeps_the_rest_under_their_tabs() {
|
||||
let mut app = app_with(5);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
assert_eq!(app.run("window.arrange.tile", json!({"layout": "2up"})).unwrap(), json!({"tiled": true, "panes": 2, "layout": "2up"}));
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert_eq!(panes(&app).0, [0, 4], "the current document takes the last pane");
|
||||
@@ -259,7 +259,7 @@ fn n_up_shows_that_many_documents_and_keeps_the_rest_under_their_tabs() {
|
||||
#[test]
|
||||
fn closing_a_document_in_an_n_up_layout_fits_the_documents_that_change_panes() {
|
||||
let mut app = app_with(4);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("document.activate", json!({"index": 1})).unwrap();
|
||||
app.run("window.arrange.tile", json!({"layout": "2up"})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -284,7 +284,7 @@ fn closing_a_document_in_an_n_up_layout_fits_the_documents_that_change_panes() {
|
||||
#[test]
|
||||
fn closing_a_document_keeps_the_zoom_of_the_documents_whose_panes_stay() {
|
||||
let mut app = app_with(6);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
app.run("window.arrange.tile", json!({"layout": "6up"})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -410,7 +410,7 @@ fn the_arrange_documents_items_tile_and_consolidate() {
|
||||
#[test]
|
||||
fn tile_shows_a_pane_for_each_document_fitted_to_it() {
|
||||
let mut app = app_with(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert!(panes(&app).0.is_empty(), "documents open under their tabs");
|
||||
let tabbed = app.canvas_view().unwrap().rect;
|
||||
@@ -472,7 +472,7 @@ fn tiled_pair() -> (VectorcraftApp, egui::Context) {
|
||||
app.select_tool("selection");
|
||||
app.ui.task_bar = false;
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app_frame(&mut app, &ctx, vec![]);
|
||||
app_frame(&mut app, &ctx, vec![]);
|
||||
(app, ctx)
|
||||
@@ -691,7 +691,7 @@ fn a_drag_released_off_a_panes_art_area_or_after_escape_changes_nothing() {
|
||||
#[test]
|
||||
fn consolidate_all_windows_shows_one_document_again() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let tabbed = app.canvas_view().map(|v| v.rect);
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
@@ -722,7 +722,7 @@ fn arrange_items_follow_the_open_documents() {
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
app.run("file.close", json!({})).unwrap();
|
||||
app.run("file.close", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert_eq!(items(&app), (false, false), "every document closed");
|
||||
assert!(!app.ui.tiled);
|
||||
@@ -731,7 +731,7 @@ fn arrange_items_follow_the_open_documents() {
|
||||
#[test]
|
||||
fn tile_with_one_document_leaves_the_next_one_under_its_tab() {
|
||||
let mut app = app_with(1);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
assert_eq!(app.run("window.arrange.tile", json!({})).unwrap(), json!({"tiled": false, "panes": 1, "layout": "grid"}));
|
||||
assert!(!app.ui.tiled);
|
||||
assert!(!enabled(&app, "window.arrange.consolidateAllWindows"));
|
||||
@@ -743,7 +743,7 @@ fn tile_with_one_document_leaves_the_next_one_under_its_tab() {
|
||||
#[test]
|
||||
fn closing_a_document_while_tiled_tiles_the_others() {
|
||||
let mut app = app_with(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert_eq!(panes(&app).0, [0, 1, 2]);
|
||||
@@ -765,7 +765,7 @@ fn closing_a_document_while_tiled_tiles_the_others() {
|
||||
#[test]
|
||||
fn an_edit_shows_in_its_pane_once_another_document_is_current() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -788,7 +788,7 @@ fn other_panes_draw_their_guides_and_selected_objects() {
|
||||
app.session.execute("guide.add", &json!({"vertical": true, "pos": 300})).unwrap();
|
||||
app.run("document.activate", json!({"index": 1})).unwrap();
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
// The pane hands its document's guides and selected objects to the overlays it shows.
|
||||
@@ -803,7 +803,7 @@ fn other_panes_draw_their_guides_and_selected_objects() {
|
||||
#[test]
|
||||
fn opening_a_document_while_tiled_fits_each_document_to_its_new_pane() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let side_by_side = app.views[0].zoom;
|
||||
@@ -818,7 +818,7 @@ fn opening_a_document_while_tiled_fits_each_document_to_its_new_pane() {
|
||||
#[test]
|
||||
fn other_panes_show_pixel_preview() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.ui.view.pixel_preview = true;
|
||||
@@ -833,7 +833,7 @@ fn other_panes_show_pixel_preview() {
|
||||
#[test]
|
||||
fn other_panes_render_within_the_largest_texture_side() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.set_pixels_per_point(2.0);
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
let mut run = |app: &mut VectorcraftApp| {
|
||||
@@ -861,7 +861,7 @@ fn other_panes_render_within_the_largest_texture_side() {
|
||||
#[test]
|
||||
fn a_panes_key_takes_its_documents_placed_value() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let before = pane_source(&mut app, &ctx, (0, 1)).frame.revision;
|
||||
@@ -875,7 +875,7 @@ fn a_panes_key_takes_its_documents_placed_value() {
|
||||
#[test]
|
||||
fn a_resized_window_fits_the_tiled_documents_again_unless_one_was_zoomed() {
|
||||
let mut app = app_with(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -942,7 +942,7 @@ fn other_panes_draw_through_their_documents_profiles() {
|
||||
}
|
||||
out.shapes.iter().any(|c| any(&c.shape, &|c: Color32| c.a() == 255 && near([c.r(), c.g(), c.b()], rgb)))
|
||||
};
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let raw = || egui::RawInput {
|
||||
screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 800.0))),
|
||||
max_texture_side: Some(8192),
|
||||
@@ -1025,7 +1025,7 @@ fn tiled_documents_blend_translucent_art_over_their_own_paper_before_display_con
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// The second document's pane: the picture it shows, and its width.
|
||||
let pane = |app: &mut VectorcraftApp| -> (Vec<Color32>, usize) {
|
||||
forget(app, &ctx);
|
||||
@@ -1093,7 +1093,7 @@ fn tiled_documents_blend_translucent_art_over_their_own_paper_before_display_con
|
||||
#[test]
|
||||
fn a_pane_draws_its_own_views_outline() {
|
||||
let mut app = translucent_in_two_windows();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let other = (0, 1);
|
||||
let red = |[r, g, b]: [u8; 3]| r > g.saturating_add(60) && r > b.saturating_add(60);
|
||||
let shown = |app: &mut VectorcraftApp, pane_outline: bool, current_outline: bool| {
|
||||
@@ -1123,7 +1123,7 @@ fn a_pane_blends_translucent_art_before_the_display_profile() {
|
||||
let p3 = crate::display_profile::tests::p3();
|
||||
app.display_profile.report(Reading { display: Some("DP-1".into()), found: Found::Profile { icc: p3, from: "test".into() } });
|
||||
app.session.prefs.monitor_profile_display = true;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let other = (0, 1);
|
||||
pane_out(&mut app, &ctx, other).textures_delta.clear();
|
||||
assert!(pane_source(&mut app, &ctx, other).frame.cache.over().is_some(), "the pane's Preview blends with its paper");
|
||||
@@ -1138,7 +1138,7 @@ fn a_pane_blends_translucent_art_before_the_display_profile() {
|
||||
#[test]
|
||||
fn an_edit_in_one_view_shows_in_the_other() {
|
||||
let mut app = app_with(1);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("window.newWindow", json!({})).unwrap();
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -1158,7 +1158,7 @@ fn an_edit_in_one_view_shows_in_the_other() {
|
||||
#[test]
|
||||
fn each_pane_draws_its_own_views_outline_or_preview() {
|
||||
let mut app = app_with(1);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("window.newWindow", json!({})).unwrap();
|
||||
crate::doc_windows::show_window(&mut app, (0, 1));
|
||||
app.run("view.outline", json!({})).unwrap();
|
||||
|
||||
@@ -64,7 +64,7 @@ fn video_rulers_count_the_artboard_in_pixels_of_its_aspect_ratio() {
|
||||
#[test]
|
||||
fn new_ruler_guides_follow_alt_through_preview_release_and_undo() {
|
||||
for along in [Axis::X, Axis::Y] {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
let (before, undo) = (app.session.active().unwrap().doc.clone(), undo_len(&app));
|
||||
let vertical = matches!(along, Axis::Y);
|
||||
send(&mut app, &ctx, drag(along, GesturePhase::Begin, 80.0, false));
|
||||
@@ -82,7 +82,7 @@ fn new_ruler_guides_follow_alt_through_preview_release_and_undo() {
|
||||
|
||||
#[test]
|
||||
fn new_ruler_guide_alt_cancel_keeps_document_and_redo() {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
app.session.execute("shape.rectangle", &json!({"x": 40, "y": 50, "width": 20, "height": 30})).unwrap();
|
||||
app.session.execute("edit.undo", &json!({})).unwrap();
|
||||
let before = app.session.active().unwrap().doc.clone();
|
||||
@@ -102,7 +102,7 @@ fn new_ruler_guide_alt_cancel_keeps_document_and_redo() {
|
||||
#[test]
|
||||
fn cmd_ruler_drags_make_artboard_guides_with_the_preference_on() {
|
||||
for on in [false, true] {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
app.session.execute("prefs.set", &json!({"key": "cmdRulerDragArtboardGuides", "value": on})).unwrap();
|
||||
let board = app.session.active().unwrap().doc.artboards[0].id;
|
||||
let place = |app: &mut VectorcraftApp, at: f64| {
|
||||
@@ -119,7 +119,7 @@ fn cmd_ruler_drags_make_artboard_guides_with_the_preference_on() {
|
||||
|
||||
#[test]
|
||||
fn guides_from_the_rulers_snap_and_artboard_guides_span_their_artboard() {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
app.ui.view.smart_guides = true;
|
||||
app.ui.view.snap_to_point = true;
|
||||
app.session.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 400, "height": 300})).unwrap();
|
||||
@@ -139,7 +139,7 @@ fn guides_from_the_rulers_snap_and_artboard_guides_span_their_artboard() {
|
||||
/// A zero-point drag edits nothing until the release, which is one history step.
|
||||
#[test]
|
||||
fn ruler_guide_shift_origin_preview_release_and_history() {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
let (before, undo) = (app.session.active().unwrap().doc.clone(), undo_len(&app));
|
||||
let to = Point::new(125.25, 90.5);
|
||||
zero(&mut app, &ctx, |app, ui| zero_begin(app, ui));
|
||||
@@ -154,7 +154,7 @@ fn ruler_guide_shift_origin_preview_release_and_history() {
|
||||
|
||||
#[test]
|
||||
fn ruler_guide_shift_origin_cancel_preserves_redo() {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
app.session.execute("shape.rectangle", &json!({"x": 40, "y": 50, "width": 20, "height": 30})).unwrap();
|
||||
app.session.execute("edit.undo", &json!({})).unwrap();
|
||||
let before = app.session.active().unwrap().doc.clone();
|
||||
@@ -170,7 +170,7 @@ fn ruler_guide_shift_origin_cancel_preserves_redo() {
|
||||
/// A guide being dragged shows its position readout.
|
||||
#[test]
|
||||
fn ruler_guide_origin_tooltip_matches_selected_guide_fields() {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
send(&mut app, &ctx, drag(Axis::Y, GesturePhase::Begin, 80.0, false));
|
||||
send(&mut app, &ctx, drag(Axis::Y, GesturePhase::Update, 120.0, false));
|
||||
let overlays = app.session.overlays(app.view_info());
|
||||
@@ -179,7 +179,7 @@ fn ruler_guide_origin_tooltip_matches_selected_guide_fields() {
|
||||
|
||||
#[test]
|
||||
fn trim_view_makes_no_guide_from_the_rulers() {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
app.ui.view.trim_view = true;
|
||||
let undo = undo_len(&app);
|
||||
send(&mut app, &ctx, drag(Axis::Y, GesturePhase::Begin, 80.0, false));
|
||||
@@ -193,7 +193,7 @@ fn trim_view_makes_no_guide_from_the_rulers() {
|
||||
|
||||
#[test]
|
||||
fn a_ruler_drag_trim_view_cancelled_stays_cancelled_until_released() {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
app.ui.view.trim_view = true;
|
||||
send(&mut app, &ctx, drag(Axis::Y, GesturePhase::Begin, 80.0, false));
|
||||
app.ui.view.trim_view = false;
|
||||
@@ -208,7 +208,7 @@ fn a_ruler_drag_trim_view_cancelled_stays_cancelled_until_released() {
|
||||
|
||||
#[test]
|
||||
fn trim_view_toggled_during_a_ruler_origin_drag_cancels_it() {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
let (before, undo) = (app.session.active().unwrap().doc.clone(), undo_len(&app));
|
||||
zero(&mut app, &ctx, |app, ui| zero_begin(app, ui));
|
||||
app.ui.view.trim_view = true;
|
||||
@@ -223,7 +223,7 @@ fn trim_view_toggled_during_a_ruler_origin_drag_cancels_it() {
|
||||
/// A strip's double press reports one `Commit` with no `Begin`: one guide at the pointer, even with guides hidden.
|
||||
#[test]
|
||||
fn double_clicking_a_ruler_adds_a_guide_at_that_position() {
|
||||
let (mut app, ctx) = (app(), egui::Context::default());
|
||||
let (mut app, ctx) = (app(), crate::testing::ui_context());
|
||||
app.ui.view.guides = false;
|
||||
let undo = undo_len(&app);
|
||||
send(&mut app, &ctx, drag(Axis::Y, GesturePhase::Commit, 150.0, false));
|
||||
|
||||
@@ -88,7 +88,7 @@ fn bucket_triple_click_with_a_view_tool_press_between_matches_the_fill_before()
|
||||
v.zoom = 1.0;
|
||||
v.fitted = true;
|
||||
}
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let xf = app.canvas_view().unwrap();
|
||||
let at = xf.to_screen(Point::new(25.0, 125.0));
|
||||
@@ -124,7 +124,7 @@ fn a_release_ends_the_image_trace_hold_without_the_panel() {
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
let made = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
|
||||
let id = vectorcraft_doc::NodeId(made["id"].as_u64().unwrap());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let at = pos2(400.0, 300.0);
|
||||
let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at), press(true)]);
|
||||
@@ -147,7 +147,7 @@ fn a_click_activates_its_artboard_and_paste_in_place_goes_onto_it() {
|
||||
let boards: Vec<_> = app.session.active().unwrap().doc.artboards.iter().map(|a| a.rect).collect();
|
||||
app.session.execute("shape.rectangle", &json!({"x": boards[0].x0 + 10.0, "y": boards[0].y0 + 15.0, "width": 20, "height": 20})).unwrap();
|
||||
app.run("edit.copy", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.select_tool("selection");
|
||||
let view = app.view_info();
|
||||
@@ -180,7 +180,7 @@ fn a_shift_click_activates_its_artboard_and_align_to_artboard_aligns_to_it() {
|
||||
};
|
||||
let ids = [rect(10.0, 15.0), rect(50.0, 40.0)];
|
||||
app.session.execute("select.set", &json!({"ids": [ids[0].0, ids[1].0]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.select_tool("selection");
|
||||
let view = app.view_info();
|
||||
@@ -206,7 +206,7 @@ fn two_finger_tap_in_touch_switches_selection_and_drawing_modes() {
|
||||
app.session.execute("shape.rectangle", &json!({"x": 50, "y": 50, "width": 40, "height": 40})).unwrap();
|
||||
crate::workspaces::switch(&mut app, crate::workspaces::TOUCH).unwrap();
|
||||
app.select_tool("rectangle");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let count = |app: &VectorcraftApp| app.session.active().unwrap().doc.layers[0].children().unwrap().len();
|
||||
let c = app.canvas_view().unwrap().rect.center();
|
||||
@@ -386,7 +386,7 @@ fn a_shape_tool_scales_the_shape_just_drawn_by_its_bounding_box_handle() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.select_tool(tool);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let drag = |app: &mut VectorcraftApp, a: Pos2, b: Pos2| {
|
||||
for ev in [
|
||||
@@ -431,7 +431,7 @@ fn cmd_with_another_tool_drags_with_the_selection_tool_used_last() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].as_u64().unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let xf = app.canvas_view().unwrap();
|
||||
let cmd_frame = |app: &mut VectorcraftApp, events: Vec<egui::Event>| {
|
||||
@@ -571,7 +571,7 @@ fn an_edit_renders_only_its_part_of_the_canvas() {
|
||||
let id = app.run("shape.rectangle", json!({"x":50,"y":50,"width":40,"height":30})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("shape.rectangle", json!({"x":250,"y":200,"width":40,"height":30})).unwrap();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// Where the canvas texture changed in a frame, and how much of it.
|
||||
let canvas = |app: &VectorcraftApp, mut delta: egui::TexturesDelta| {
|
||||
let tex = app.canvas.texture.as_ref().map(|t| t.id());
|
||||
@@ -604,7 +604,7 @@ fn the_art_renders_within_the_largest_texture_side() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width":400,"height":300})).unwrap();
|
||||
app.canvas.worker_started = true; // every frame on this thread, however long it takes
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.set_pixels_per_point(2.0);
|
||||
// The first frame sets the pixels a point, the second draws at them.
|
||||
for _ in 0..2 {
|
||||
@@ -680,7 +680,7 @@ fn a_ready_placed_bitmap() {
|
||||
.collect();
|
||||
app.run("shape.rectangle", json!({"x":250,"y":200,"width":40,"height":30})).unwrap();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// Where the canvas texture changed in a frame, and how much of it.
|
||||
let canvas = |app: &VectorcraftApp, mut delta: egui::TexturesDelta| {
|
||||
let tex = app.canvas.texture.as_ref().map(|t| t.id());
|
||||
@@ -727,7 +727,7 @@ fn an_edit_while_a_mask_is_viewed_renders_all_of_the_canvas() {
|
||||
app.run("select.set", json!({"ids": [obj, mask]})).unwrap();
|
||||
app.run("transparency.makeOpacityMask", json!({})).unwrap();
|
||||
app.run("transparency.viewOpacityMask", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let (_, mut delta) = frame_output(&mut app, &ctx);
|
||||
delta.clear();
|
||||
app.run("paint.setFill", json!({"color": "#ff0000", "ids": [obj]})).unwrap();
|
||||
@@ -748,7 +748,7 @@ fn pixel_preview_shows_the_document_pixels() {
|
||||
// Its 1 pt stroke covers a quarter of document pixel 99 and most of pixel 100.
|
||||
app.session.execute("shape.rectangle", &json!({"x": 100.25, "y": 50, "width": 200, "height": 200})).unwrap();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// The art's raster uploaded by one frame: (width, height, hard-edged, pixels).
|
||||
let upload = |app: &mut VectorcraftApp| {
|
||||
let (_, mut delta) = frame_output(app, &ctx);
|
||||
@@ -799,7 +799,7 @@ fn the_canvas_is_drawn_through_the_display_profile_while_the_preference_is_on()
|
||||
app.session.execute("paint.setFill", &json!({"color": "#ff0000"})).unwrap();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
assert!(app.session.prefs.monitor_profile_display, "on by default");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// How many pixels of the art's raster one frame uploads are `c`, None when it was not re-rendered.
|
||||
let count = |app: &mut VectorcraftApp, c: egui::Color32| -> Option<usize> {
|
||||
let (_, mut delta) = frame_output(app, &ctx);
|
||||
@@ -862,7 +862,7 @@ fn translucent_art_over_the_paper() {
|
||||
app.run("paint.setFill", json!({"ids": [outside], "color": "#00ff00"})).unwrap();
|
||||
app.run("transparency.set", json!({"ids": [outside], "opacity": 50})).unwrap();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// The art's raster one frame uploads: where it goes ([x, y] for a part), its width and its pixels.
|
||||
let upload = |app: &mut VectorcraftApp| -> Option<(Option<[usize; 2]>, usize, Vec<egui::Color32>)> {
|
||||
let (_, mut delta) = frame_output(app, &ctx);
|
||||
@@ -979,7 +979,7 @@ fn hide_template_leaves_template_layers_off_the_canvas() {
|
||||
app.session.execute("shape.rectangle", &json!({"x": 100, "y": 50, "width": 200, "height": 200})).unwrap();
|
||||
let layer = app.session.active().unwrap().doc.layers[0].id.0;
|
||||
app.session.execute("layer.template", &json!({"ids": [layer], "on": true})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// How many pixels of the art's raster one frame uploads are painted, None when it was not
|
||||
// re-rendered.
|
||||
let painted = |app: &mut VectorcraftApp| -> Option<usize> {
|
||||
@@ -1011,7 +1011,7 @@ fn anti_aliased_artwork_preference_smooths_the_canvas() {
|
||||
app.canvas.worker_started = true;
|
||||
// A disc: its edge crosses pixels at every angle.
|
||||
app.session.execute("shape.ellipse", &json!({"x": 100, "y": 50, "width": 200, "height": 200})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// The alphas of the art's raster uploaded by one frame, None when it was not re-rendered.
|
||||
let alphas = |app: &mut VectorcraftApp| -> Option<Vec<u8>> {
|
||||
let (_, mut delta) = frame_output(app, &ctx);
|
||||
@@ -1043,7 +1043,7 @@ fn highlight_substituted_fonts_preference_reaches_the_canvas() {
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
app.session.execute("text.create", &json!({"x": 20, "y": 120, "text": "Hamburg", "size": 60, "font": "Missing Family"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// How many pink pixels the art's raster uploaded by one frame has, None when it was not
|
||||
// re-rendered.
|
||||
let pink = |app: &mut VectorcraftApp| -> Option<usize> {
|
||||
@@ -1137,7 +1137,7 @@ fn undecodable_images_are_marked_and_reported_once() {
|
||||
}
|
||||
st.revision += 1;
|
||||
}
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.status("");
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert!(app.canvas.shown.as_ref().is_some_and(|(_, o)| o.mark_undecoded_images), "the canvas marks them");
|
||||
@@ -1163,7 +1163,7 @@ fn the_first_view_reports_the_plug_in_effects_it_deferred() {
|
||||
// Each reading of the clock is 3 s later: the first run's result comes back after the budget,
|
||||
// and no later run starts.
|
||||
let step = std::sync::Arc::new(AtomicU64::new(3_000));
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
for (count, said) in [
|
||||
(2, "Opened with 2 plug-in effects deferred. Effect › Refresh Deferred Effects runs them."),
|
||||
(1, "Opened with 1 plug-in effect deferred. Effect › Refresh Deferred Effects runs it."),
|
||||
@@ -1238,7 +1238,7 @@ fn dragging_with_raster_effects() {
|
||||
for effect in ["stylize.dropShadow", "texture.craquelure"] {
|
||||
app.run("effect.apply", json!({"effect": effect, "ids": [id]})).unwrap();
|
||||
}
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// The art's raster uploaded by one frame, None when it was not re-rendered.
|
||||
let upload = |app: &mut VectorcraftApp| -> Option<Vec<Color32>> {
|
||||
let (_, mut delta) = frame_output(app, &ctx);
|
||||
@@ -1295,7 +1295,7 @@ fn a_drag_at_a_lower_resolution() {
|
||||
let id = app.run("shape.rectangle", json!({"x": 100, "y": 80, "width": 200, "height": 150})).unwrap()["id"].clone();
|
||||
app.run("effect.apply", json!({"effect": "texture.texturizer", "ids": [id]})).unwrap();
|
||||
app.select_tool("selection");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// One headless frame on a 1920 × 1200 window (a view larger than the drag's budget) with
|
||||
// `events` → the art's raster it uploaded, None when it was not re-rendered.
|
||||
let run = |app: &mut VectorcraftApp, events: Vec<egui::Event>| -> Option<Vec<Color32>> {
|
||||
@@ -1361,7 +1361,7 @@ fn a_drag_over_a_wide_blur() {
|
||||
let square = app.run("shape.rectangle", json!({"x": 260, "y": 380, "width": 60, "height": 60})).unwrap()["id"].clone();
|
||||
app.run("select.set", json!({"ids": [square]})).unwrap();
|
||||
app.select_tool("selection");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// One headless frame with `events`, then, with a worker, its frames rendered and shown
|
||||
// until none is pending.
|
||||
let run = |app: &mut VectorcraftApp, side: &mut Option<WorkerSide>, events: Vec<egui::Event>| {
|
||||
@@ -1424,7 +1424,7 @@ fn an_interaction_stays_on_the_worker_that_drew_the_frame_shown() {
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 100, "y": 50, "width": 200, "height": 200})).unwrap();
|
||||
app.canvas.worker_started = true; // the first frame renders on this thread
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
shapes(&mut app, &ctx);
|
||||
for from_worker in [true, false] {
|
||||
app.canvas.worker = crate::render_worker::Worker::spawn(ctx.clone());
|
||||
@@ -1455,7 +1455,7 @@ fn a_drag_back_to_its_start() {
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
let id = app.run("shape.rectangle", json!({"x": 100, "y": 80, "width": 120, "height": 90})).unwrap()["id"].clone();
|
||||
app.run("effect.apply", json!({"effect": "texture.craquelure", "ids": [id]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
shapes(&mut app, &ctx);
|
||||
app.select_tool("selection");
|
||||
let view = app.view_info();
|
||||
@@ -1624,7 +1624,7 @@ fn a_turned_view() {
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 100, "y": 50, "width": 200, "height": 200})).unwrap();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
shapes(&mut app, &ctx); // the first frame fits the view to the artboard
|
||||
app.view_mut().unwrap().rotation = 30.0;
|
||||
shapes(&mut app, &ctx);
|
||||
@@ -1690,7 +1690,7 @@ fn a_pan_fills_the_area_the_last_frame_leaves_until_the_worker_frame_arrives() {
|
||||
}
|
||||
|
||||
fn a_pan_fills_the_area() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 300, "y": 100, "width": 80, "height": 100})).unwrap();
|
||||
@@ -1826,7 +1826,7 @@ fn without_a_worker_a_heavy_canvas() {
|
||||
assert!(!app.canvas.waits_for_still, "off the web build");
|
||||
app.canvas.worker_started = true; // no worker, as in the web build
|
||||
app.canvas.waits_for_still = true;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// One frame → (the bounds of the mesh that draws the art's texture, the repaint delay asked for).
|
||||
let frame = |app: &mut VectorcraftApp| {
|
||||
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), ..Default::default() };
|
||||
@@ -1935,7 +1935,7 @@ fn edits_while_the_view_is_still() {
|
||||
app.session.execute("shape.rectangle", &json!({"x": 100, "y": 50, "width": 200, "height": 200})).unwrap();
|
||||
app.canvas.worker_started = true; // no worker, as in the web build
|
||||
app.canvas.waits_for_still = true;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let frame = |app: &mut VectorcraftApp| {
|
||||
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw, |ui| show(app, ui));
|
||||
@@ -1970,7 +1970,7 @@ fn the_canvas_waits_only_while_the_view_of_a_slow_frame_changes() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
shapes(&mut app, &egui::Context::default());
|
||||
shapes(&mut app, &crate::testing::ui_context());
|
||||
let shown = app.canvas.key.clone().unwrap();
|
||||
let mut still = Some((shown.clone(), 0.0));
|
||||
let moved = CacheKey { cx: shown.cx + 5.0, zoom: shown.zoom * 2.0, ..shown.clone() };
|
||||
@@ -2019,7 +2019,7 @@ fn a_bitmap_for_another_documents_file() {
|
||||
std::fs::write(&path, vectorcraft_format::save_file(&src.active().unwrap().doc)).unwrap();
|
||||
other.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
other.session.execute("file.place", &json!({"path": path.to_string_lossy(), "at": [100, 100]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let frame = |app: &mut VectorcraftApp| {
|
||||
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw, |ui| show(app, ui));
|
||||
@@ -2034,7 +2034,7 @@ fn a_bitmap_for_another_documents_file() {
|
||||
// The other canvas asks for the bitmap, and it is made: the generation changes before the
|
||||
// bitmap stops being pending.
|
||||
let generation = vectorcraft_render::placed_document::generation();
|
||||
shapes(&mut other, &egui::Context::default());
|
||||
shapes(&mut other, &crate::testing::ui_context());
|
||||
while vectorcraft_render::placed_document::busy() {
|
||||
std::thread::yield_now();
|
||||
}
|
||||
@@ -2131,7 +2131,7 @@ fn the_canvas_key_takes_the_documents_placed_value() {
|
||||
let generation = vectorcraft_render::placed_document::generation();
|
||||
let marked = generation.wrapping_add(1000);
|
||||
app.canvas.placed_keys.insert(uid, crate::PlacedKey { checked: generation, key: marked, before: (marked, generation) });
|
||||
shapes(&mut app, &egui::Context::default());
|
||||
shapes(&mut app, &crate::testing::ui_context());
|
||||
assert_eq!(app.canvas.key.as_ref().map(|k| k.placed), Some(marked));
|
||||
}
|
||||
|
||||
@@ -2197,7 +2197,7 @@ fn pixel_preview_smooths_bitmaps_only_when_asked() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let smooth = |app: &mut VectorcraftApp| {
|
||||
let (_, mut delta) = frame_output(app, &ctx);
|
||||
delta.clear();
|
||||
@@ -2225,7 +2225,7 @@ fn appearance_of_black_on_screen_shows_pure_black_as_rgb_black() {
|
||||
let [c, m, y, k] = cmyk;
|
||||
app.run("paint.setFill", json!({"ids": [id], "color": {"c": c, "m": m, "y": y, "k": k}})).unwrap();
|
||||
};
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// The middle pixel of the art's raster uploaded by one frame, None when it was not re-rendered.
|
||||
let middle = |app: &mut VectorcraftApp| -> Option<[u8; 4]> {
|
||||
let (_, mut delta) = frame_output(app, &ctx);
|
||||
@@ -2265,7 +2265,7 @@ fn top_bounding_box_handle_scales_a_default_mirror_repeat() {
|
||||
app.run("object.repeat.mirror", json!({})).unwrap();
|
||||
app.ui.task_bar = false;
|
||||
app.ui.view.rulers = false;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
|
||||
let initial = app.selection_bounds().unwrap();
|
||||
@@ -2338,7 +2338,7 @@ fn hidden_corner_widgets_do_not_answer_the_pointer() {
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
let id = vectorcraft_doc::NodeId(id);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.select_tool("selection");
|
||||
let widget = |app: &VectorcraftApp| {
|
||||
@@ -2379,7 +2379,7 @@ fn a_hidden_bounding_box_and_type_widget_do_not_answer_the_pointer() {
|
||||
let id = app.session.execute("text.create", &json!({"x": 100, "y": 100, "text": "Type"})).unwrap()["id"].as_u64().unwrap();
|
||||
let id = vectorcraft_doc::NodeId(id);
|
||||
app.session.execute("select.set", &json!({"ids": [id.0]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.select_tool("selection");
|
||||
let bx = |app: &VectorcraftApp| {
|
||||
@@ -2619,7 +2619,7 @@ fn hidden_characters_mark_no_space_at_a_bullet() {
|
||||
fn view_actual_size_follows_display_print_size() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 100})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
// The view's zoom after Actual Size from 250%, and the percent the app's zoom scheme reads it as.
|
||||
let actual = |app: &mut VectorcraftApp| {
|
||||
@@ -2644,7 +2644,7 @@ fn view_actual_size_follows_display_print_size() {
|
||||
fn fit_artboard_fits_the_artboard_turned_with_the_view() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 612, "height": 792, "artboards": 2})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.view_mut().unwrap().artboard = 1;
|
||||
app.run("view.rotate", json!({"angle": 45})).unwrap();
|
||||
@@ -2762,7 +2762,7 @@ fn space_pressed_mid_drag_moves_what_the_tool_draws() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.ui.view.smart_guides = false;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let xf = app.canvas_view().unwrap();
|
||||
let space = |pressed| Event::Key { key: egui::Key::Space, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE };
|
||||
@@ -2807,7 +2807,7 @@ fn double_clicking_type_with_the_selection_tool_puts_the_caret_there() {
|
||||
let id = app.session.execute("text.create", &json!({"x": 100, "y": 150, "text": "Hello world", "size": 24})).unwrap()["id"].as_u64().unwrap();
|
||||
app.session.execute("select.none", &json!({})).unwrap();
|
||||
app.select_tool("selection");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let timed = |app: &mut VectorcraftApp, time: f64, events: Vec<egui::Event>| {
|
||||
let screen = egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0));
|
||||
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), time: Some(time), events, ..Default::default() }, |ui| show(app, ui));
|
||||
@@ -2950,7 +2950,7 @@ fn double_clicking_type_with_the_direct_selection_tool_puts_the_caret_there() {
|
||||
let id = app.session.execute("text.create", &json!({"x": 100, "y": 150, "text": "Hello world", "size": 24})).unwrap()["id"].as_u64().unwrap();
|
||||
app.session.execute("select.none", &json!({})).unwrap();
|
||||
app.select_tool("directSelection");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let timed = |app: &mut VectorcraftApp, time: f64, events: Vec<egui::Event>| {
|
||||
let screen = egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0));
|
||||
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), time: Some(time), events, ..Default::default() }, |ui| {
|
||||
@@ -3110,7 +3110,7 @@ fn escape_while_editing_in_isolation_returns_to_selection_tool_and_keeps_isolati
|
||||
app.session.execute("select.all", &json!({})).unwrap();
|
||||
app.session.execute("object.group", &json!({})).unwrap();
|
||||
app.select_tool("selection");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let timed = |app: &mut VectorcraftApp, time: f64, events: Vec<egui::Event>| {
|
||||
let screen = egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0));
|
||||
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), time: Some(time), events, ..Default::default() }, |ui| {
|
||||
@@ -3166,7 +3166,7 @@ fn escape_leaves_an_isolated_sublayer_in_one_step() {
|
||||
app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 40, "height": 20})).unwrap();
|
||||
app.session.execute("object.isolate", &json!({"id": deep})).unwrap();
|
||||
app.select_tool("selection");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let timed = |app: &mut VectorcraftApp, time: f64, events: Vec<egui::Event>| {
|
||||
let screen = egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0));
|
||||
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), time: Some(time), events, ..Default::default() }, |ui| {
|
||||
@@ -3203,7 +3203,7 @@ fn art_moved_off_the_canvas_waits_and_drops_on_the_panel() {
|
||||
let id = vectorcraft_doc::NodeId(id);
|
||||
app.session.execute("select.none", &json!({})).unwrap();
|
||||
app.select_tool(tool);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let view = app.canvas_view().unwrap();
|
||||
let before = app.session.active().unwrap().doc.clone();
|
||||
@@ -3247,7 +3247,7 @@ fn art_alt_dragged_off_the_canvas_reaches_the_panels_as_the_original() {
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 50, "y": 50, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
let id = vectorcraft_doc::NodeId(id);
|
||||
app.select_tool("selection");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let view = app.canvas_view().unwrap();
|
||||
let before = app.session.active().unwrap().doc.clone();
|
||||
@@ -3278,7 +3278,7 @@ fn art_moved_off_the_canvas_resumes_when_the_pointer_returns() {
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 50, "y": 50, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
app.select_tool("selection");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let view = app.canvas_view().unwrap();
|
||||
let undo = app.session.active().unwrap().history.undo.len();
|
||||
@@ -3520,7 +3520,7 @@ fn a_modifier_changed_mid_scale_applies_with_the_pointer_held_still() {
|
||||
app.ui.view.snap_to_point = false;
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 50})).unwrap()["id"].as_u64().unwrap();
|
||||
app.select_tool("selection");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let xf = app.canvas_view().unwrap();
|
||||
let with = |app: &mut VectorcraftApp, mut events: Vec<Event>, modifiers: Modifiers| {
|
||||
@@ -3563,7 +3563,7 @@ fn backtick_changed_mid_selection_drag_applies_with_the_pointer_held_still() {
|
||||
app.ui.view.rulers = false;
|
||||
app.ui.view.smart_guides = false;
|
||||
app.ui.view.snap_to_point = false;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let xf = app.canvas_view().unwrap();
|
||||
let from = xf.to_screen(Point::new(125.0, 125.0));
|
||||
@@ -3602,7 +3602,7 @@ fn backtick_places_a_flares_rings_anew_with_the_pointer_held_still() {
|
||||
app.ui.task_bar = false;
|
||||
app.ui.view.rulers = false;
|
||||
app.ui.view.smart_guides = false;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let xf = app.canvas_view().unwrap();
|
||||
let from = xf.to_screen(Point::new(100.0, 100.0));
|
||||
@@ -3668,7 +3668,7 @@ fn pen_app() -> (VectorcraftApp, craft::ui::runtime::pen::PenSource, egui::Conte
|
||||
let stylus = craft::ui::runtime::pen::PenSource::default();
|
||||
app.services.pen = Some(stylus.clone());
|
||||
app.session.execute("file.new", &json!({"width": 800, "height": 600})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![egui::Event::PointerMoved(Pos2::new(400.0, 300.0))]);
|
||||
(app, stylus, ctx)
|
||||
}
|
||||
@@ -3869,7 +3869,7 @@ fn a_pen_tap_within_one_frame_clicks_where_it_tapped() {
|
||||
app.session.execute("file.new", &json!({"width": 800, "height": 600})).unwrap();
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
app.session.execute("select.none", &json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.select_tool("selection");
|
||||
let before = app.session.active().unwrap().doc.art_bounds();
|
||||
@@ -4593,7 +4593,7 @@ fn the_pasteboard_fade_leaves_exports_unchanged() {
|
||||
let plain = exports(&mut app);
|
||||
app.run("prefs.set", json!({"key": "fadeRegionOutsideArtboard", "value": true})).unwrap();
|
||||
app.select_tool("artboard");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert!(super::artboards::fades_outside_artboards(&app));
|
||||
assert_eq!(exports(&mut app), plain);
|
||||
@@ -4609,7 +4609,7 @@ fn poll_worker_accepts_frames_not_older_than_displayed_and_discards_obsolete_fra
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.canvas.worker_started = true;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw.clone(), |ui| show(&mut app, ui));
|
||||
out.textures_delta.clear();
|
||||
@@ -4797,7 +4797,7 @@ fn pan_doc() -> (std::sync::Arc<vectorcraft_doc::Document>, CacheKey) {
|
||||
app.run("paint.setFill", json!({"ids": [id], "color": color})).unwrap();
|
||||
}
|
||||
app.canvas.worker_started = true;
|
||||
shapes(&mut app, &egui::Context::default());
|
||||
shapes(&mut app, &crate::testing::ui_context());
|
||||
let key = app.canvas.key.clone().expect("a frame was rendered");
|
||||
(app.session.active().unwrap().doc.clone(), CacheKey { zoom: 1.0, rot: 0.0, ppp: 1.0, pixel: None, ..key })
|
||||
}
|
||||
@@ -4849,7 +4849,7 @@ fn a_plug_in_change() {
|
||||
app.session.execute("file.new", &json!({"width": 256, "height": 128})).unwrap();
|
||||
let rect = app.run("shape.rectangle", json!({"x": 16, "y": 16, "width": 64, "height": 96})).unwrap()["id"].clone();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
shapes(&mut app, &ctx);
|
||||
// Other keys' fields (placed documents' bitmaps) follow what other tests do; this one's don't.
|
||||
let plugins = |app: &VectorcraftApp| app.canvas.key.as_ref().expect("a frame was rendered").plugins;
|
||||
@@ -5171,7 +5171,7 @@ fn a_frame_with_copied_pixels() {
|
||||
app.canvas.worker_started = true;
|
||||
let (worker, jobs, done_tx) = crate::render_worker::Worker::test_channel();
|
||||
app.canvas.worker = Some(worker);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let frame = |app: &mut VectorcraftApp, t: f64| {
|
||||
let raw =
|
||||
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), time: Some(t), ..Default::default() };
|
||||
@@ -5221,7 +5221,7 @@ fn a_pan_after_the_settling_frame() {
|
||||
app.canvas.worker_started = true;
|
||||
let (worker, jobs, done_tx) = crate::render_worker::Worker::test_channel();
|
||||
app.canvas.worker = Some(worker);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let frame = |app: &mut VectorcraftApp, t: f64| {
|
||||
let raw =
|
||||
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), time: Some(t), ..Default::default() };
|
||||
@@ -5300,7 +5300,7 @@ fn a_frame_after_a_zoom_or_an_edit_holds_no_pixels() {
|
||||
#[test]
|
||||
fn the_render_worker_thread_copies_a_pan() {
|
||||
let (doc, key) = pan_doc();
|
||||
let mut worker = crate::render_worker::Worker::spawn(egui::Context::default()).expect("a worker");
|
||||
let mut worker = crate::render_worker::Worker::spawn(crate::testing::ui_context()).expect("a worker");
|
||||
// Blocks until the worker sends its frame. A worker thread that stopped gives None.
|
||||
let wait = |worker: &mut crate::render_worker::Worker| worker.wait(std::time::Duration::MAX).expect("the worker sends the frame");
|
||||
worker.submit(pan_job(&doc, &key, (0.0, 0.0)));
|
||||
@@ -5323,7 +5323,7 @@ fn a_documents_first_frame() {
|
||||
app.canvas.worker_started = true;
|
||||
let (worker, jobs, done_tx) = crate::render_worker::Worker::test_channel();
|
||||
app.canvas.worker = Some(worker);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(800.0, 600.0))), ..Default::default() };
|
||||
let frame = |app: &mut VectorcraftApp| ctx.run_ui(raw.clone(), |ui| show(app, ui)).textures_delta.clear();
|
||||
|
||||
@@ -5351,7 +5351,7 @@ fn the_render_worker_waits_for_a_frame_only_as_long_as_asked() {
|
||||
app.canvas.worker_started = true;
|
||||
let (worker, jobs, _) = crate::render_worker::Worker::test_channel();
|
||||
app.canvas.worker = Some(worker);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(200.0, 150.0))), ..Default::default() };
|
||||
ctx.run_ui(raw, |ui| show(&mut app, ui)).textures_delta.clear();
|
||||
let job = jobs.try_recv().expect("a job to finish");
|
||||
@@ -5385,7 +5385,7 @@ fn an_edit_to_a_3d_effect_redraws_with_the_art_measured() {
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
let id = app.run("shape.rectangle", json!({"x": 380, "y": 280, "width": 40, "height": 40})).unwrap()["id"].clone();
|
||||
app.run("effect.apply", json!({"effect": "threeD.extrude", "ids": [id], "params": {"depth": 60.0}})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
shapes(&mut app, &ctx);
|
||||
assert_eq!(app.canvas.renderer.stats.three_d_built, 1, "the whole frame made the art");
|
||||
app.run("effect.setParams", json!({"ids": [id], "index": 0, "item": null, "params": {"depth": 5.0}})).unwrap();
|
||||
@@ -5409,7 +5409,7 @@ fn art_measured_for_an_edit_not_drawn_here_is_let_go() {
|
||||
let (x, size) = if worker { (0, 800) } else { (5000, 40) };
|
||||
let id = app.run("shape.rectangle", json!({"x": x, "y": 0, "width": size, "height": size})).unwrap()["id"].clone();
|
||||
app.run("effect.apply", json!({"effect": "threeD.extrude", "ids": [id], "params": {"depth": 60.0}})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
shapes(&mut app, &ctx);
|
||||
// A worker whose jobs the test receives: none finishes unless the test says so.
|
||||
let mut jobs = None;
|
||||
@@ -5472,7 +5472,7 @@ fn a_move_stops_snapping_to_guides_hidden_during_it() {
|
||||
app.ui.view.smart_guides = false;
|
||||
app.ui.view.snap_to_point = true;
|
||||
app.ui.view.guides = true;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let xf = app.canvas_view().unwrap();
|
||||
let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
|
||||
|
||||
@@ -25,7 +25,7 @@ fn zoomed_in(tool: &str) -> (VectorcraftApp, egui::Context, vectorcraft_doc::Nod
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 50, "y": 50, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
app.select_tool(tool);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let v = app.view_mut().unwrap();
|
||||
v.zoom = 4.0;
|
||||
|
||||
@@ -54,7 +54,7 @@ fn bucket_modifier_only_hover_updates_the_visible_cursor() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", serde_json::json!({"width": 400, "height": 300})).unwrap();
|
||||
app.select_tool("livePaintBucket");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let at = app.canvas_view().unwrap().to_screen(Point::new(200.0, 150.0));
|
||||
let shown = |app: &mut VectorcraftApp, mods: egui::Modifiers| {
|
||||
|
||||
@@ -225,7 +225,7 @@ fn art_of(layers: &[Arc<vectorcraft_doc::Node>]) -> Vec<vectorcraft_doc::Node> {
|
||||
fn hints_name_keys_as_the_menus_do() {
|
||||
// A drawn frame gives the window its keymap, which the Search Commands shortcut is read from.
|
||||
let mut app = crate::VectorcraftApp::new(Session::new(), crate::Services::default());
|
||||
crate::tests_synthetic::key_frame(&mut app, &egui::Context::default(), vec![]);
|
||||
crate::tests_synthetic::key_frame(&mut app, &crate::testing::ui_context(), vec![]);
|
||||
let text = |tool: &str| super::hint_segments(&app, tool).into_iter().map(|(s, _)| s).collect::<String>();
|
||||
for tool in vectorcraft_tools::catalog::all_tools().map(|t| t.id) {
|
||||
let hint = text(tool);
|
||||
|
||||
@@ -59,7 +59,7 @@ mod tests {
|
||||
#[test]
|
||||
fn link_clicks_open_the_right_urls() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut opened = vec![];
|
||||
for id in ["help.discord", "help.website", "help.appPage", "help.github"] {
|
||||
crate::menus::invoke(&mut app, id, serde_json::json!({}));
|
||||
|
||||
@@ -14,7 +14,7 @@ fn dialog_open(app: &VectorcraftApp) -> bool {
|
||||
|
||||
fn input_request(app: &mut VectorcraftApp, method: &str, params: Value) -> Value {
|
||||
let (req, _) = ControlRequest::new(method, params);
|
||||
let Reply::Done(r) = handle(app, &egui::Context::default(), &req) else { panic!("expected immediate reply") };
|
||||
let Reply::Done(r) = handle(app, &crate::testing::ui_context(), &req) else { panic!("expected immediate reply") };
|
||||
r
|
||||
}
|
||||
|
||||
@@ -667,7 +667,7 @@ fn render_takes_the_artboard_asked_for() {
|
||||
let mut request = |method: &str, params: Value| {
|
||||
let (req, reply) = ControlRequest::new(method, params);
|
||||
tx.send(req).unwrap();
|
||||
app.run_control(&egui::Context::default());
|
||||
app.run_control(&crate::testing::ui_context());
|
||||
reply.try_recv().unwrap()
|
||||
};
|
||||
let new = json!({"width": 64, "height": 64, "units": "Points", "artboards": 2});
|
||||
@@ -882,7 +882,7 @@ fn pointer_replies_name_the_key_object() {
|
||||
let b = app.run("shape.rectangle", json!({"x": 100, "y": 10, "width": 20, "height": 20})).unwrap()["id"].clone();
|
||||
app.run("select.set", json!({"ids": [a, b]})).unwrap();
|
||||
app.run("tool.select", json!({"tool": "selection"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let click = |app: &mut VectorcraftApp| {
|
||||
let events = json!([{"kind": "down", "x": 110, "y": 20}, {"kind": "up", "x": 110, "y": 20}]);
|
||||
let (req, _) = ControlRequest::new("ui.pointer", json!({"events": events}));
|
||||
@@ -906,7 +906,7 @@ fn pointer_reply_waits_for_a_merge_on_another_thread() {
|
||||
}
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
app.run("tool.select", json!({"tool": "shapeBuilder"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let send = |app: &mut VectorcraftApp, events: Value| {
|
||||
let (req, reply) = ControlRequest::new("ui.pointer", json!({"events": events}));
|
||||
tx.send(req).unwrap();
|
||||
|
||||
@@ -724,7 +724,7 @@ mod tests {
|
||||
/// Sets fields as `ui.dialog.set` does, all or none.
|
||||
fn set(app: &VectorcraftApp, fields: &[(&str, Value)]) -> Result<(), String> {
|
||||
let fields: Vec<(String, Value)> = fields.iter().map(|(k, v)| ((*k).to_string(), v.clone())).collect();
|
||||
app.dialogs().unwrap().with(|h| h.set_json_fields(&egui::Context::default(), id(), &fields))
|
||||
app.dialogs().unwrap().with(|h| h.set_json_fields(&crate::testing::ui_context(), id(), &fields))
|
||||
}
|
||||
|
||||
/// Changes the value as the form's controls do (the parts no field names).
|
||||
@@ -735,7 +735,7 @@ mod tests {
|
||||
/// Presses OK: the host files the value, `pump` runs the command, and the host closes the dialog
|
||||
/// when the command succeeded.
|
||||
fn ok(app: &mut VectorcraftApp) -> Result<(), String> {
|
||||
let (ctx, host) = (egui::Context::default(), app.dialogs().unwrap());
|
||||
let (ctx, host) = (crate::testing::ui_context(), app.dialogs().unwrap());
|
||||
host.with(|h| h.confirm_by_id(&ctx, id()));
|
||||
pump(app, &ctx);
|
||||
match host.with(|h| h.held_state(id())) {
|
||||
@@ -977,7 +977,7 @@ mod tests {
|
||||
assert_eq!(bounds, [None, None]);
|
||||
let before = app.session.doc().unwrap().doc.clone();
|
||||
set(&app, &[("width", json!(10))]).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.dialogs().unwrap().with(|h| h.cancel_by_id(&ctx, id()));
|
||||
assert!(!is_open(&app));
|
||||
assert_eq!(*app.session.doc().unwrap().doc, *before);
|
||||
|
||||
@@ -8,7 +8,7 @@ use super::*;
|
||||
/// An app with a window context for the dialog host and no document.
|
||||
pub(in crate::dialogs) fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
}
|
||||
|
||||
|
||||
@@ -562,7 +562,7 @@ mod tests {
|
||||
/// A selected area type object with two paragraphs, in an app with a window for its dialogs.
|
||||
fn app() -> (VectorcraftApp, u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
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()
|
||||
|
||||
@@ -236,7 +236,7 @@ mod tests {
|
||||
/// An app with the window context that hosts the dialog.
|
||||
fn app() -> (VectorcraftApp, egui::Context) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
(app, ctx)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ mod tests {
|
||||
|
||||
/// An app with a window for its dialogs and one open document.
|
||||
fn app() -> (egui::Context, VectorcraftApp) {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
|
||||
@@ -459,7 +459,7 @@ mod tests {
|
||||
/// An app with a window context, so a dialog can open.
|
||||
fn windowed() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::tests::picks::{poll, scripted};
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -543,7 +543,7 @@ mod tests {
|
||||
assert_eq!(label(&app), "Edit Contents");
|
||||
app.run("object.envelope.editContents", json!({})).unwrap();
|
||||
assert_eq!(label(&app), "Edit Envelope");
|
||||
crate::tests_synthetic::key_frame(&mut app, &egui::Context::default(), vec![]);
|
||||
crate::tests_synthetic::key_frame(&mut app, &crate::testing::ui_context(), vec![]);
|
||||
assert!(crate::menus::shortcut_of(&app, "object.envelope.editContents").is_none(), "its reference shortcut is Paste in Place's here");
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,10 @@ const SETTABLE: [&str; 19] = [
|
||||
/// The check column of the list view and its name column.
|
||||
const CHECK: ColumnKey = ColumnKey::new("check");
|
||||
const NAME: ColumnKey = ColumnKey::new("name");
|
||||
/// Rows of the list view and of the grid view the items pane shows before it scrolls, a pane as tall as the options
|
||||
/// column's first sections.
|
||||
const LIST_ROWS: u16 = 9;
|
||||
const GRID_ROWS: u16 = 3;
|
||||
|
||||
/// The longest side of an artboard thumbnail, in pixels.
|
||||
const THUMB_PX: u32 = 92;
|
||||
@@ -547,12 +551,11 @@ impl ExportForScreensDialog {
|
||||
fn items_pane(&mut self, ui: &mut Ui, fields: &mut Map<String, Value>) {
|
||||
let tab = TABS.iter().position(|k| *k == text(fields, "tab")).unwrap_or(0);
|
||||
let titles = Items(vec![(0, tl!("Artboards").to_string()), (1, tl!("Assets").to_string())]);
|
||||
let strip =
|
||||
TabStrip::new(tl!("Export for Screens"))
|
||||
.id_salt("efs-tabs")
|
||||
.kind(TabKind::Text)
|
||||
.shown(tab)
|
||||
.show_items(ui, &titles, &mut |k, _| Tab::new(titles.name(*k)).id_salt(("efs-tab", *k)));
|
||||
let strip = TabStrip::new(tl!("Export for Screens")).id_salt("efs-tabs").kind(TabKind::Text).shown(tab).natural_height(true).show_items(
|
||||
ui,
|
||||
&titles,
|
||||
&mut |k, _| Tab::new(titles.name(*k)).id_salt(("efs-tab", *k)),
|
||||
);
|
||||
let picked = strip.response.events.into_iter().find_map(|e| match e {
|
||||
CollectionEvent::Selection { change: SelectionChange::Set(keys), .. } => keys.last().copied(),
|
||||
_ => None,
|
||||
@@ -730,7 +733,8 @@ impl Shelf<'_> {
|
||||
.space(SpaceAction::ToggleCell)
|
||||
.columns(columns)
|
||||
.rename(rename)
|
||||
.enabled(enabled);
|
||||
.enabled(enabled)
|
||||
.max_rows(LIST_ROWS);
|
||||
if rename {
|
||||
view = view.rename_column(NAME);
|
||||
}
|
||||
@@ -753,7 +757,7 @@ impl Shelf<'_> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let mut grid = TileGrid::<u64>::new(tl!("Export for Screens")).checks(true).rename(rename).enabled(enabled);
|
||||
let mut grid = TileGrid::<u64>::new(tl!("Export for Screens")).checks(true).rename(rename).enabled(enabled).max_rows(GRID_ROWS);
|
||||
if let Some(key) = reveal {
|
||||
grid = grid.reveal(key);
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ mod tests {
|
||||
/// and stop 1 selected, in an app with the window context that hosts the popover.
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.run("file.new", json!({"width": 300, "height": 300})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap();
|
||||
let stops = json!([{"offset": 0, "color": "#ffffff"}, {"offset": 0.5, "color": "#00ff00"}, {"offset": 1, "color": "#000000"}]);
|
||||
|
||||
@@ -800,13 +800,13 @@ mod tests {
|
||||
}
|
||||
|
||||
fn set_field(app: &VectorcraftApp, field: &str, value: Value) -> Result<(), String> {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.dialogs().expect("a window").with(|host| host.set_json_field(&ctx, dialog_id(KIND), field, value))
|
||||
}
|
||||
|
||||
/// OK through the host, then the pump: what Apply does.
|
||||
fn apply_through_host(app: &mut VectorcraftApp) {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let closed = app.dialogs().expect("a window").with(|host| host.confirm::<GraphDataDialog>(&ctx));
|
||||
assert!(!closed, "Apply leaves the window open");
|
||||
pump(app, &ctx);
|
||||
@@ -991,7 +991,7 @@ mod tests {
|
||||
assert_eq!(read(h.state(), |d| cell_of(&d.sheet.grid, 0, 1)), "a");
|
||||
// The tool's Graph Data after drawing opens the same sheet.
|
||||
let app = h.state_mut();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.dialogs().expect("a window").with(|host| host.cancel::<GraphDataDialog>(&ctx));
|
||||
super::super::tools::open_tool_dialog(app, "graphData", json!({}));
|
||||
assert!(app.dialogs().is_some_and(|d| d.with(|host| host.is_open::<GraphDataDialog>())));
|
||||
|
||||
@@ -843,7 +843,7 @@ mod tests {
|
||||
|
||||
fn app_with_design() -> (VectorcraftApp, egui::Context) {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let r = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 10, "height": 10})).unwrap()["id"].as_u64().unwrap();
|
||||
@@ -931,7 +931,7 @@ mod tests {
|
||||
let (src, _) = app_with_design();
|
||||
let bytes = vectorcraft_format::save_file(&src.session.active().unwrap().doc);
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
let p = json!({"dataBase64": vectorcraft_format::base64_encode(&bytes), "name": "Dots.vectorcraft"});
|
||||
app.run("swatch.library.load", p).unwrap();
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::*;
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
app
|
||||
}
|
||||
@@ -29,7 +29,7 @@ fn is_open(app: &VectorcraftApp) -> bool {
|
||||
|
||||
/// Sets a field as automation does.
|
||||
fn set(app: &VectorcraftApp, field: &str, value: Value) {
|
||||
dialog(app, |d| d.set_json_field(&egui::Context::default(), field, value)).unwrap();
|
||||
dialog(app, |d| d.set_json_field(&crate::testing::ui_context(), field, value)).unwrap();
|
||||
}
|
||||
|
||||
/// The picked set's name, as the dialog lists it.
|
||||
@@ -182,7 +182,7 @@ fn ok_sets_the_document_the_dialog_opened_on() {
|
||||
let first = app.session.active().unwrap().uid;
|
||||
app.run("type.kinsokuSets.set", json!({ "sets": [{"name": "First", "cannotStart": "ゝ"}] })).unwrap();
|
||||
open(&mut app).unwrap();
|
||||
assert!(dialog(&app, |d| d.set_json_field(&egui::Context::default(), "__doc", json!(1))).is_err(), "automation cannot change the document");
|
||||
assert!(dialog(&app, |d| d.set_json_field(&crate::testing::ui_context(), "__doc", json!(1))).is_err(), "automation cannot change the document");
|
||||
set(&app, "name", json!("Soft"));
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
let other = app.session.active().unwrap().uid;
|
||||
|
||||
@@ -605,7 +605,7 @@ mod tests {
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ mod tests {
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ mod tests {
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ mod tests {
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -693,7 +693,7 @@ mod tests {
|
||||
/// An app with a window context, so New Document has a host to open on.
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ mod tests {
|
||||
|
||||
/// An app with a window for its dialogs and one open document.
|
||||
fn setup() -> (egui::Context, VectorcraftApp) {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
|
||||
@@ -598,13 +598,13 @@ mod tests {
|
||||
|
||||
/// `ui.dialog.set` on the open dialog.
|
||||
fn set(app: &mut VectorcraftApp, field: &str, value: Value) -> Result<(), String> {
|
||||
let ctx = Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.dialogs().expect("a window").with(|host| host.set_json_field(&ctx, dialog_id(KIND), field, value))
|
||||
}
|
||||
|
||||
/// OK as a click: the dialog files its answer, the app runs the command, and an accepted answer closes the dialog.
|
||||
fn ok(app: &mut VectorcraftApp) {
|
||||
let ctx = Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let confirm = |app: &mut VectorcraftApp| {
|
||||
app.dialogs().expect("a window").with(|host| host.confirm_by_id(&ctx, dialog_id(KIND)));
|
||||
};
|
||||
@@ -637,7 +637,7 @@ mod tests {
|
||||
fn constrain_ratio_percentages_and_use_ratio_set_the_fields() {
|
||||
let mut app = app_with_image();
|
||||
open(&mut app, &json!({"columns": 10, "rows": 10})).unwrap();
|
||||
let ctx = Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
set(&mut app, "lock", json!(true)).unwrap();
|
||||
set(&mut app, "width", json!(300)).unwrap();
|
||||
assert_eq!(number_of(&mut app, "height"), 150.0, "height follows the width");
|
||||
@@ -697,7 +697,7 @@ mod tests {
|
||||
app.run("ui.paramDialog", json!({"command": COMMAND, "params": params})).unwrap();
|
||||
let f = fields(&mut app);
|
||||
assert_eq!((&f["columns"], &f["rows"], &f["constrain"], &f["lock"]), (&json!(8.0), &json!(4.0), &json!("height"), &json!(false)));
|
||||
let ctx = Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.dialogs().unwrap().with(|host| host.cancel::<ObjectMosaicDialog>(&ctx));
|
||||
// Params the command refuses open nothing and say why.
|
||||
for (bad, key) in [(json!({"width": "abc"}), "width"), (json!({"constrain": "both"}), "constrain"), (json!({"widht": 200}), "widht")] {
|
||||
@@ -767,7 +767,7 @@ mod tests {
|
||||
/// With no image selected, switching is refused and the note asks for one.
|
||||
#[test]
|
||||
fn percentages_convert_against_the_image_scaled_while_the_dialog_is_open() {
|
||||
let ctx = Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let control = |app: &mut VectorcraftApp, field: &str, value: Value| {
|
||||
let (req, _) = craft::automation::ControlRequest::new("ui.dialog.set", json!({"field": field, "value": value}));
|
||||
let craft::automation::Reply::Done(r) = crate::control::handle(app, &ctx, &req) else { panic!("expected an immediate reply") };
|
||||
|
||||
@@ -394,7 +394,7 @@ pub(super) mod tests {
|
||||
/// An app with a window context for the dialog host and a blank document.
|
||||
pub(in crate::dialogs) fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ mod tests {
|
||||
|
||||
fn app(artboards: u32) -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.run("file.new", json!({"width": 100, "height": 50, "artboards": artboards})).unwrap();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -173,6 +173,8 @@ const TITLE: &str = "Recolor Artwork";
|
||||
/// The fields of the Color Groups list: whether it is shown, a request from its buttons, and the
|
||||
/// group whose colors the rows were last given.
|
||||
const GROUP_STORAGE: &str = "groupStorage";
|
||||
/// Rows the Color Groups list shows before it scrolls: as tall as the tabs beside it.
|
||||
const GROUP_ROWS: u16 = 10;
|
||||
const GROUP_ACTION: &str = "groupAction";
|
||||
const GROUP_LOADED: &str = "__groupLoaded";
|
||||
/// The `recolor.reduce` parameters the art's rows were last reduced with.
|
||||
@@ -2287,12 +2289,15 @@ fn group_list(ui: &mut Ui, d: &mut Fields, feed: &Feed) {
|
||||
let mut picked: Option<Value> = None;
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let source = keyed(&keys, |k| *k).with_text(|k| Cow::Owned(names.get(*k).cloned().unwrap_or_default()));
|
||||
let out =
|
||||
List::new(tl!("Color Groups")).select(SelectMode::Single).selection(Bind::bound(&mut chosen)).show_items(ui, &source, &mut |key, _| {
|
||||
let out = List::new(tl!("Color Groups")).select(SelectMode::Single).max_rows(GROUP_ROWS).selection(Bind::bound(&mut chosen)).show_items(
|
||||
ui,
|
||||
&source,
|
||||
&mut |key, _| {
|
||||
let colors: Vec<egui::Color32> = feed.groups.get(*key).map(|(_, cs)| cs.iter().map(c32).collect()).unwrap_or_default();
|
||||
ListRow::new(names.get(*key).cloned().unwrap_or_default())
|
||||
.thumb_aspect(ThumbSize::Small, ThumbAspect::new(4, 1), move |cx, rect| cx.data_shapes(chips(rect, &colors)))
|
||||
});
|
||||
},
|
||||
);
|
||||
for event in out.events {
|
||||
if let CollectionEvent::Selection { change, .. } = event {
|
||||
picked = match change {
|
||||
|
||||
@@ -51,6 +51,8 @@ const REMOVE: &str = "remove";
|
||||
const TOOLS: [(&str, &str, &str); 2] = [(ADD, "plus", "Add Color Tool"), (REMOVE, "minus", "Remove Color Tool")];
|
||||
/// A colour bar is this many times as wide as it is high.
|
||||
const BAR_ASPECT: u16 = 6;
|
||||
/// Bars shown before the list scrolls: as tall as the wheel the bars replace.
|
||||
const BAR_ROWS: u16 = 11;
|
||||
/// The target of the wheel's right-click menu: `{marker, line, hs}` (row indexes and the hue and
|
||||
/// saturation clicked).
|
||||
const MENU_AT: &str = "__wheelMenu";
|
||||
@@ -317,10 +319,12 @@ fn bars(ui: &mut Ui, d: &mut Fields, rows: &mut [Value], active: &[usize], base:
|
||||
}
|
||||
let selection = sel.filter(|s| active.contains(s)).map_or_else(Selection::default, Selection::single);
|
||||
let shown: &[Value] = rows;
|
||||
let out = List::new(tl!("Color bars")).select(SelectMode::Single).reorder(ReorderRule::new()).selection(Bind::given(selection)).show_items(
|
||||
ui,
|
||||
&keyed(active, |&i| i),
|
||||
&mut |key, item| {
|
||||
let out = List::new(tl!("Color bars"))
|
||||
.select(SelectMode::Single)
|
||||
.max_rows(BAR_ROWS)
|
||||
.reorder(ReorderRule::new())
|
||||
.selection(Bind::given(selection))
|
||||
.show_items(ui, &keyed(active, |&i| i), &mut |key, item| {
|
||||
let i = *key;
|
||||
let color = shown.get(i).and_then(to_color).map(|c| c32(&c)).unwrap_or_default();
|
||||
let mut state = item.row.clone();
|
||||
@@ -328,8 +332,7 @@ fn bars(ui: &mut Ui, d: &mut Fields, rows: &mut [Value], active: &[usize], base:
|
||||
ListRow::new(color_name(i)).state(state).thumb_aspect(ThumbSize::Small, ThumbAspect::new(BAR_ASPECT, 1), move |cx, rect| {
|
||||
cx.painter.rect_filled(rect, 0.0, color);
|
||||
})
|
||||
},
|
||||
);
|
||||
});
|
||||
let mut moved = false;
|
||||
for event in out.events {
|
||||
match event {
|
||||
|
||||
@@ -55,7 +55,7 @@ mod tests {
|
||||
|
||||
fn app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.run("file.new", json!({"width": 100, "height": 50, "artboards": 3})).unwrap();
|
||||
app.select_tool("artboard");
|
||||
app
|
||||
|
||||
@@ -64,7 +64,7 @@ mod tests {
|
||||
#[test]
|
||||
fn commits_without_a_drawn_frame_as_one_step() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
let id = app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap();
|
||||
|
||||
@@ -90,7 +90,7 @@ mod tests {
|
||||
|
||||
fn app_with_text(text: &str) -> (VectorcraftApp, u64) {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.run("file.new", json!({"width": 200, "height": 100})).unwrap();
|
||||
let id = app.run("text.create", json!({"x": 10, "y": 40, "text": text, "font": "Source Sans 3"})).unwrap()["id"].as_u64().unwrap();
|
||||
(app, id)
|
||||
|
||||
@@ -504,7 +504,7 @@ mod tests {
|
||||
|
||||
/// An app with a window for its dialogs and one open document.
|
||||
fn setup() -> (egui::Context, VectorcraftApp) {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::tests::picks::{poll, scripted};
|
||||
/// Sends `app.open` with `params` through the control channel and returns the reply.
|
||||
fn control(app: &mut VectorcraftApp, params: serde_json::Value) -> serde_json::Value {
|
||||
let (req, _rx) = craft::automation::ControlRequest::new("app.open", params);
|
||||
let craft::automation::Reply::Done(r) = crate::control::handle(app, &egui::Context::default(), &req) else { panic!("not done") };
|
||||
let craft::automation::Reply::Done(r) = crate::control::handle(app, &crate::testing::ui_context(), &req) else { panic!("not done") };
|
||||
r
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ fn open_with_asks_for_an_importer_s_parameters_and_passes_them_on() {
|
||||
let picker = scripted(&mut app);
|
||||
app.run("file.openWith", json!({"importer": "plugin.test.ui.importparams"})).unwrap();
|
||||
picker.answer(&[&file]);
|
||||
poll(&mut app, &egui::Context::default());
|
||||
poll(&mut app, &crate::testing::ui_context());
|
||||
assert_eq!(kind(&app).as_deref(), Some(plugin::IMPORT_KIND));
|
||||
frame(&mut app);
|
||||
set(&mut app, "density", json!(7));
|
||||
|
||||
@@ -207,7 +207,7 @@ fn opens_with_the_rows_selected_in_the_artboards_panel_else_on_the_saved_choice(
|
||||
app.run("file.exportForScreens", json!({"fullDocument": true, "prefix": "proof-", "formats": [{"format": "jpg", "quality": 80, "scale": "2x"}]}))
|
||||
.unwrap();
|
||||
app.run("tool.select", json!({"tool": "artboard"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let screen = Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(240.0, 400.0)));
|
||||
let panel = |app: &mut VectorcraftApp, time: f64, events: Vec<egui::Event>| {
|
||||
let raw = egui::RawInput { events, time: Some(time), screen_rect: screen, ..Default::default() };
|
||||
@@ -1176,7 +1176,7 @@ fn an_applied_preset_keeps_its_item_folders() {
|
||||
set(&mut app, "exportPreset", json!("Items"));
|
||||
set(&mut app, "folder", json!(dir.to_string_lossy()));
|
||||
let (req, _rx) = ControlRequest::new("ui.dialog.set", json!({"field": "subfolders", "value": on}));
|
||||
let Reply::Done(r) = crate::control::handle(&mut app, &egui::Context::default(), &req) else { panic!("not done") };
|
||||
let Reply::Done(r) = crate::control::handle(&mut app, &crate::testing::ui_context(), &req) else { panic!("not done") };
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
try_confirm(&mut app).unwrap();
|
||||
assert_eq!(files_under(&dir).first().map(String::as_str), Some(first), "subfolders {on}");
|
||||
@@ -1274,7 +1274,7 @@ fn an_exported_preset_file_is_named_after_the_preset() {
|
||||
fn setting_the_export_preset_field_applies_the_preset() {
|
||||
use craft::automation::{ControlRequest, Reply};
|
||||
let (mut app, _) = app(1, false);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
open(&mut app);
|
||||
let set_preset = |app: &mut VectorcraftApp, name: &str| {
|
||||
let (req, _rx) = ControlRequest::new("ui.dialog.set", json!({"field": "exportPreset", "value": name}));
|
||||
|
||||
@@ -16,7 +16,7 @@ fn app() -> VectorcraftApp {
|
||||
/// One frame of a window, which builds its keymap, then a pass of Keyboard Shortcuts in it, which
|
||||
/// takes up a pending review.
|
||||
fn frame(app: &mut VectorcraftApp) {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
crate::tests::synthetic::key_frame(app, &ctx, vec![]);
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| shortcut_editor::show(app, ui));
|
||||
out.textures_delta.clear();
|
||||
|
||||
@@ -144,7 +144,7 @@ pub(super) mod test_support {
|
||||
|
||||
/// `app` with a window to host dialogs in.
|
||||
pub fn with_window(mut app: VectorcraftApp) -> VectorcraftApp {
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ pub(super) mod driver {
|
||||
|
||||
/// Gives the app a window context, so a dialog can open.
|
||||
pub fn install(app: &mut VectorcraftApp) {
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
}
|
||||
|
||||
fn ctx(app: &VectorcraftApp) -> egui::Context {
|
||||
|
||||
@@ -101,7 +101,7 @@ fn tab_drawn(shapes: &[Shape], title: &str) -> bool {
|
||||
#[test]
|
||||
fn float_in_window_moves_the_current_document_out_of_the_tabs() {
|
||||
let mut app = app_with(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let shapes = frame(&mut app, &ctx, vec![]);
|
||||
let title = app.session.documents()[2].title();
|
||||
assert!(tab_drawn(&shapes, &title), "the current document has a tab");
|
||||
@@ -128,7 +128,7 @@ fn float_in_window_moves_the_current_document_out_of_the_tabs() {
|
||||
#[test]
|
||||
fn a_press_in_another_documents_window_or_the_main_window_makes_its_document_current() {
|
||||
let mut app = app_with(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
app.run("window.arrange.floatInWindow", json!({})).unwrap();
|
||||
@@ -156,7 +156,7 @@ fn a_press_in_another_documents_window_or_the_main_window_makes_its_document_cur
|
||||
#[test]
|
||||
fn a_resized_window_fits_its_document_again_unless_it_was_zoomed() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
app.run("window.arrange.floatInWindow", json!({})).unwrap();
|
||||
@@ -186,7 +186,7 @@ fn a_resized_window_fits_its_document_again_unless_it_was_zoomed() {
|
||||
#[test]
|
||||
fn cascade_floats_every_document_and_stacks_the_windows() {
|
||||
let mut app = app_with(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
app.run("document.activate", json!({"index": 1})).unwrap();
|
||||
@@ -224,7 +224,7 @@ fn cascade_floats_every_document_and_stacks_the_windows() {
|
||||
#[test]
|
||||
fn float_all_in_windows_floats_the_tabbed_documents_and_consolidate_brings_them_back() {
|
||||
let mut app = app_with(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let tabbed = canvas_rect(&app);
|
||||
app.run("window.arrange.floatInWindow", json!({})).unwrap();
|
||||
@@ -248,7 +248,7 @@ fn float_all_in_windows_floats_the_tabbed_documents_and_consolidate_brings_them_
|
||||
#[test]
|
||||
fn tile_brings_floating_documents_back_into_the_grid() {
|
||||
let mut app = app_with(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.run("window.arrange.tile", json!({})).unwrap();
|
||||
app.run("window.arrange.floatInWindow", json!({})).unwrap();
|
||||
@@ -265,7 +265,7 @@ fn tile_brings_floating_documents_back_into_the_grid() {
|
||||
#[test]
|
||||
fn closing_a_floating_window_closes_its_document_and_asks_to_save_an_unsaved_one() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.run("window.arrange.floatAllInWindows", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -317,7 +317,7 @@ fn closing_a_floating_window_closes_its_document_and_asks_to_save_an_unsaved_one
|
||||
#[test]
|
||||
fn presentation_mode_shows_the_floating_current_document_in_the_main_window() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.run("window.arrange.floatAllInWindows", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -350,7 +350,7 @@ fn presentation_mode_shows_the_floating_current_document_in_the_main_window() {
|
||||
#[test]
|
||||
fn a_document_made_current_in_presentation_mode_comes_to_the_front_after_it() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.run("window.arrange.floatAllInWindows", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -412,7 +412,7 @@ fn native_host() -> std::rc::Rc<std::cell::RefCell<Host>> {
|
||||
#[test]
|
||||
fn closing_an_os_window_keeps_it_while_its_unsaved_document_stays_open() {
|
||||
let host = native_host();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.set_embed_viewports(false);
|
||||
let mut app = app_with(2);
|
||||
if !WindowHost::of(&ctx).viewports_available() {
|
||||
@@ -439,7 +439,7 @@ fn closing_an_os_window_keeps_it_while_its_unsaved_document_stays_open() {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn the_update_prompt_takes_the_keyboard_from_a_document_window() {
|
||||
let _host = native_host();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.set_embed_viewports(false);
|
||||
let mut app = app_with(2);
|
||||
if !WindowHost::of(&ctx).viewports_available() {
|
||||
@@ -482,7 +482,7 @@ fn tab_at(shapes: &[Shape], title: &str) -> Pos2 {
|
||||
#[test]
|
||||
fn dragging_a_tab_off_the_strip_floats_its_document_at_the_pointer() {
|
||||
let mut app = app_with(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let shapes = frame(&mut app, &ctx, vec![]);
|
||||
let title = app.session.documents()[0].title();
|
||||
@@ -511,7 +511,7 @@ fn dragging_a_tab_off_the_strip_floats_its_document_at_the_pointer() {
|
||||
#[test]
|
||||
fn a_window_dragged_by_its_tab_onto_the_strip_goes_back_under_the_tabs() {
|
||||
let mut app = app_with(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.run("window.arrange.floatAllInWindows", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -544,7 +544,7 @@ fn a_window_dragged_by_its_tab_onto_the_strip_goes_back_under_the_tabs() {
|
||||
#[test]
|
||||
fn after_touch_input_a_window_tab_dragged_onto_the_strip_still_docks() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.run("window.arrange.floatAllInWindows", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -567,7 +567,7 @@ fn after_touch_input_a_window_tab_dragged_onto_the_strip_still_docks() {
|
||||
#[test]
|
||||
fn a_document_floated_again_after_cascade_opens_where_it_is_asked_to() {
|
||||
let mut app = app_with(2);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
app.run("window.arrange.floatAllInWindows", json!({})).unwrap();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
@@ -603,7 +603,7 @@ fn float_in_window_and_consolidate_take_a_document() {
|
||||
#[test]
|
||||
fn with_open_documents_as_tabs_cleared_new_documents_open_in_floating_windows() {
|
||||
let mut app = app_with(1);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("prefs.set", json!({"key": "openDocumentsAsTabs", "value": false})).unwrap();
|
||||
assert_eq!(docked(&app), [0], "a document already open stays under its tab");
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
@@ -671,7 +671,7 @@ fn checking_open_documents_as_tabs_again_leaves_floating_documents_where_they_ar
|
||||
#[test]
|
||||
fn an_os_windows_tab_docks_on_the_strip() {
|
||||
let host = native_host();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.set_embed_viewports(false);
|
||||
let mut app = app_with(2);
|
||||
if !WindowHost::of(&ctx).viewports_available() {
|
||||
@@ -735,7 +735,7 @@ fn title_of(app: &VectorcraftApp, w: Win) -> String {
|
||||
#[test]
|
||||
fn new_window_opens_a_numbered_view_with_its_own_zoom() {
|
||||
let mut app = app_with(1);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let name = app.session.documents()[0].title();
|
||||
assert!(!title_of(&app, (0, 1)).contains(&format!("{name}:")), "one view: no number");
|
||||
@@ -763,7 +763,7 @@ fn new_window_opens_a_numbered_view_with_its_own_zoom() {
|
||||
#[test]
|
||||
fn closing_a_view_leaves_the_document_open() {
|
||||
let mut app = app_with(1);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap();
|
||||
app.run("window.newWindow", json!({})).unwrap();
|
||||
app.run("window.newWindow", json!({})).unwrap();
|
||||
@@ -786,7 +786,7 @@ fn closing_a_view_leaves_the_document_open() {
|
||||
#[test]
|
||||
fn arrange_treats_each_view_as_a_window() {
|
||||
let mut app = app_with(1);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert!(!enabled(&app, "window.arrange.tile") && !enabled(&app, "window.arrange.cascade"), "one window");
|
||||
app.run("window.newWindow", json!({})).unwrap();
|
||||
@@ -927,7 +927,7 @@ fn selected_center(app: &VectorcraftApp) -> vectorcraft_geom::Point {
|
||||
|
||||
#[test]
|
||||
fn a_selection_drag_released_in_another_documents_floating_window_copies_the_art_there() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = floating_pair(&ctx);
|
||||
// The target's view differs from the source's: the grab point still lands under the pointer.
|
||||
let v = view_mut(&mut app, (1, 1)).unwrap();
|
||||
@@ -961,7 +961,7 @@ fn a_selection_drag_released_in_another_documents_floating_window_copies_the_art
|
||||
|
||||
#[test]
|
||||
fn a_release_in_the_first_frame_over_a_floating_window_still_copies_the_art() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = floating_pair(&ctx);
|
||||
let source = app.session.documents()[0].doc.clone();
|
||||
grab(&mut app, &ctx, vectorcraft_geom::Point::new(325.0, 255.0));
|
||||
@@ -979,7 +979,7 @@ fn a_release_in_the_first_frame_over_a_floating_window_still_copies_the_art() {
|
||||
|
||||
#[test]
|
||||
fn a_floating_window_drop_lands_where_the_button_went_up() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = floating_pair(&ctx);
|
||||
grab(&mut app, &ctx, vectorcraft_geom::Point::new(325.0, 255.0));
|
||||
let drop = in_noted(&app, (1, 1), vectorcraft_geom::Point::new(200.0, 150.0));
|
||||
@@ -996,7 +996,7 @@ fn a_floating_window_drop_lands_where_the_button_went_up() {
|
||||
|
||||
#[test]
|
||||
fn art_dragged_from_a_floating_window_drops_into_the_main_windows_document() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = floating_pair(&ctx);
|
||||
show_window(&mut app, (1, 1));
|
||||
app_frame(&mut app, &ctx, vec![]);
|
||||
@@ -1021,7 +1021,7 @@ fn art_dragged_from_a_floating_window_drops_into_the_main_windows_document() {
|
||||
|
||||
#[test]
|
||||
fn a_selection_drag_into_a_floating_view_of_its_document_moves_the_art() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = app_with(0);
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 300, "y": 230, "width": 50, "height": 50})).unwrap();
|
||||
@@ -1050,7 +1050,7 @@ fn a_selection_drag_into_a_floating_view_of_its_document_moves_the_art() {
|
||||
#[test]
|
||||
fn a_drag_released_on_a_floating_windows_title_bar_or_after_escape_changes_nothing() {
|
||||
for (case, escape) in [("title bar", false), ("art area after Escape", true)] {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = floating_pair(&ctx);
|
||||
let docs: Vec<_> = app.session.documents().iter().map(|d| (d.doc.clone(), d.history.undo.len())).collect();
|
||||
grab(&mut app, &ctx, vectorcraft_geom::Point::new(325.0, 255.0));
|
||||
@@ -1076,7 +1076,7 @@ fn a_drag_released_on_a_floating_windows_title_bar_or_after_escape_changes_nothi
|
||||
|
||||
#[test]
|
||||
fn a_tab_transfer_whose_source_changed_drops_nothing_in_a_floating_window() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = floating_pair(&ctx);
|
||||
app.run("file.new", json!({"width": 400, "height": 300, "name": "Third"})).unwrap();
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
@@ -1110,7 +1110,7 @@ fn a_tab_transfer_whose_source_changed_drops_nothing_in_a_floating_window() {
|
||||
|
||||
#[test]
|
||||
fn a_tab_transfer_whose_target_is_no_longer_current_drops_nothing_in_a_floating_window() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut app = floating_pair(&ctx);
|
||||
app.run("file.new", json!({"width": 400, "height": 300, "name": "Third"})).unwrap();
|
||||
app.run("document.activate", json!({"index": 0})).unwrap();
|
||||
|
||||
@@ -654,7 +654,7 @@ mod tests {
|
||||
/// An app whose window has a dialog host (it has a context).
|
||||
fn new_app() -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
}
|
||||
|
||||
@@ -860,7 +860,7 @@ mod tests {
|
||||
assert!(!app.ui.status.is_empty());
|
||||
|
||||
app.session.execute("object.unlockAll", &json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| app.tick(ui.ctx()));
|
||||
out.textures_delta.clear();
|
||||
assert_eq!(app.ui.status, "");
|
||||
|
||||
@@ -180,7 +180,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn a_loss_is_reported_once_from_any_thread() {
|
||||
let (loss, ctx) = (GraphicsLoss::default(), egui::Context::default());
|
||||
let (loss, ctx) = (GraphicsLoss::default(), crate::testing::ui_context());
|
||||
let (l, c) = (loss.clone(), ctx.clone());
|
||||
std::thread::spawn(move || {
|
||||
l.report(&c, "Unknown: driver reset");
|
||||
@@ -210,7 +210,7 @@ mod tests {
|
||||
fn the_app_uploads_everything_again_in_a_new_context() {
|
||||
let mut app = app();
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
let old = egui::Context::default();
|
||||
let old = crate::testing::ui_context();
|
||||
for _ in 0..3 {
|
||||
frame(&mut app, &old);
|
||||
}
|
||||
@@ -218,7 +218,7 @@ mod tests {
|
||||
assert_eq!(texture_name(&old, canvas).as_deref(), Some("canvas"));
|
||||
|
||||
// The host lost its graphics and started again: same app, new context.
|
||||
let new = egui::Context::default();
|
||||
let new = crate::testing::ui_context();
|
||||
for _ in 0..3 {
|
||||
frame(&mut app, &new);
|
||||
}
|
||||
|
||||
@@ -533,7 +533,7 @@ mod tests {
|
||||
let input = egui::RawInput { viewport_id: id, viewports, events: events.take(), ..Default::default() };
|
||||
ctx.run_ui(input, |ui| (viewport.viewport_ui_cb)(ui)).textures_delta.clear();
|
||||
});
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.set_embed_viewports(false);
|
||||
watch_input(&B, &ctx);
|
||||
let child = egui::ViewportId::from_hash_of("floating panel");
|
||||
@@ -577,7 +577,7 @@ mod tests {
|
||||
let input = egui::RawInput { viewport_id: id, viewports, ..Default::default() };
|
||||
ctx.run_ui(input, |ui| (viewport.viewport_ui_cb)(ui)).textures_delta.clear();
|
||||
});
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.set_embed_viewports(false);
|
||||
watch_input(&B, &ctx);
|
||||
let child = egui::ViewportId::from_hash_of("floating panel");
|
||||
|
||||
@@ -205,7 +205,7 @@ fn bundled_catalogs_are_consistent() {
|
||||
#[test]
|
||||
fn the_engine_follows_the_interface_language() {
|
||||
let mut app = crate::VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let frame = |app: &mut crate::VectorcraftApp| {
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| app.tick(ui.ctx())).textures_delta.clear();
|
||||
};
|
||||
|
||||
@@ -507,7 +507,7 @@ mod tests {
|
||||
let (mut app, written) = app();
|
||||
app.session.execute("file.new", &json!({"width": 30, "height": 20})).unwrap();
|
||||
let (req, _) = craft::automation::control::ControlRequest::new("app.export", json!({"format": "png", "scale": 2}));
|
||||
let craft::automation::Reply::Done(r) = crate::control::handle(&mut app, &egui::Context::default(), &req) else { panic!("not done") };
|
||||
let craft::automation::Reply::Done(r) = crate::control::handle(&mut app, &crate::testing::ui_context(), &req) else { panic!("not done") };
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
let png = vectorcraft_format::base64_decode(r["result"]["dataBase64"].as_str().unwrap()).unwrap();
|
||||
assert_eq!(&png[16..20], 60u32.to_be_bytes(), "30 pt at scale 2");
|
||||
|
||||
@@ -39,7 +39,7 @@ fn separators(nodes: &[Node]) -> Vec<usize> {
|
||||
|
||||
/// The label the built bar shows for `id`, with the step-naming wording (Undo Move) applied.
|
||||
fn shown_label(app: &mut VectorcraftApp, id: &str) -> Option<String> {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// PLAN: assumed `app.menus.bar` is the `craft::menu::MenuBar` that `refresh` builds, with dynamic labels written into its items
|
||||
crate::menus::model::refresh(app, &ctx);
|
||||
app.menus.bar.items().into_iter().find(|it| it.command.id == id).map(|it| it.label.clone())
|
||||
@@ -391,7 +391,7 @@ fn help_starts_with_search_commands() {
|
||||
);
|
||||
assert!(matches!(help[1], Node::Separator), "{:?}", help[1]);
|
||||
assert!(enabled(&app, "help.commandPalette"));
|
||||
crate::tests_synthetic::key_frame(&mut app, &egui::Context::default(), vec![]);
|
||||
crate::tests_synthetic::key_frame(&mut app, &crate::testing::ui_context(), vec![]);
|
||||
assert!(shortcut_of(&app, "help.commandPalette").is_some(), "the search's shortcut shows next to the item");
|
||||
fn count(nodes: &[Node]) -> usize {
|
||||
nodes
|
||||
@@ -410,7 +410,7 @@ fn help_starts_with_search_commands() {
|
||||
#[test]
|
||||
fn the_bar_starts_at_file() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
crate::menus::model::refresh(&mut app, &ctx);
|
||||
// PLAN: assumed `app.menus.laid` is the `craft::menu::MenuBar` laid out for the window
|
||||
let titles: Vec<&str> = app.menus.laid.menus.iter().map(|menu| menu.title.as_str()).collect();
|
||||
@@ -588,7 +588,7 @@ fn center_on_top_and_bottom_are_type_on_a_path_items() {
|
||||
app.run("select.set", json!({"ids": [closed]})).unwrap();
|
||||
use craft::ui::runtime::commands::{FirePhase, FireSource, Fired};
|
||||
let fired = Fired::new(craft::menu::CommandRef::new(ids[0]), FireSource::Palette, FirePhase::Press, 0.0);
|
||||
crate::shortcuts::run_fired(&mut app, &egui::Context::default(), &fired);
|
||||
crate::shortcuts::run_fired(&mut app, &crate::testing::ui_context(), &fired);
|
||||
let doc = &app.session.active().unwrap().doc;
|
||||
let start = match &doc.node(vectorcraft_doc::NodeId(closed.as_u64().unwrap())).unwrap().kind {
|
||||
vectorcraft_doc::NodeKind::Text(t) => match t.kind {
|
||||
@@ -1117,7 +1117,7 @@ fn precise_cursors_command_is_listed_and_assignable_in_the_shortcut_editor() {
|
||||
assert_eq!(ed::default_of(ID), None, "no default key");
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
|
||||
// The `shortcuts.*` commands read the window's keymap, which its first frame builds.
|
||||
crate::tests::synthetic::key_frame(&mut app, &egui::Context::default(), vec![]);
|
||||
crate::tests::synthetic::key_frame(&mut app, &crate::testing::ui_context(), vec![]);
|
||||
let shortcut = |app: &mut VectorcraftApp| {
|
||||
let rows = app.run("shortcuts.list", json!({ "query": ID })).unwrap();
|
||||
rows.as_array().and_then(|rows| rows.iter().find(|r| r["id"] == ID)).expect("listed")["shortcut"].clone()
|
||||
|
||||
@@ -761,7 +761,7 @@ mod tests {
|
||||
fn app_on(session: Session) -> VectorcraftApp {
|
||||
crate::i18n::set_current(Lang::EN);
|
||||
let mut app = VectorcraftApp::new(session, crate::Services::default());
|
||||
crate::menus::model::refresh(&mut app, &egui::Context::default());
|
||||
crate::menus::model::refresh(&mut app, &crate::testing::ui_context());
|
||||
app
|
||||
}
|
||||
|
||||
@@ -774,7 +774,7 @@ mod tests {
|
||||
/// A pick of result `id`: the command its entry runs ([`crate::keymap::command_of`]), fired
|
||||
/// from the palette.
|
||||
fn pick(app: &mut VectorcraftApp, id: &str) {
|
||||
fire(app, &egui::Context::default(), crate::keymap::command_of(id), FireSource::Palette);
|
||||
fire(app, &crate::testing::ui_context(), crate::keymap::command_of(id), FireSource::Palette);
|
||||
}
|
||||
|
||||
/// Cancels, or confirms, every open dialog.
|
||||
@@ -827,7 +827,7 @@ mod tests {
|
||||
|
||||
/// The entries and index [`show`] builds for `app` in the current language.
|
||||
fn built_for(app: &VectorcraftApp) -> Built {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut built = None;
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| built = Some(build(app, ui)));
|
||||
out.textures_delta.clear();
|
||||
@@ -1081,7 +1081,7 @@ mod tests {
|
||||
let before = outcome(&picked);
|
||||
pick(&mut picked, id);
|
||||
if row.is_enabled() {
|
||||
fire(&mut clicked, &egui::Context::default(), item.clone(), FireSource::Menu);
|
||||
fire(&mut clicked, &crate::testing::ui_context(), item.clone(), FireSource::Menu);
|
||||
assert_eq!(outcome(&picked), outcome(&clicked), "{id} [state {n}]");
|
||||
compared += 1;
|
||||
} else {
|
||||
@@ -1743,7 +1743,7 @@ mod tests {
|
||||
let before = outcome(&picked);
|
||||
pick(&mut picked, shadow);
|
||||
let click = CommandRef::with_params(item.command, json!({ "effect": item.effect }));
|
||||
fire(&mut clicked, &egui::Context::default(), click, FireSource::Menu);
|
||||
fire(&mut clicked, &crate::testing::ui_context(), click, FireSource::Menu);
|
||||
let after = outcome(&picked);
|
||||
assert!(after.0, "the dialog opens: {}", after.2);
|
||||
assert_eq!(after.1, before.1, "nothing changes yet");
|
||||
@@ -1835,7 +1835,7 @@ mod tests {
|
||||
let mut alike = vec![];
|
||||
for lang in Lang::all() {
|
||||
crate::i18n::set_current(lang);
|
||||
crate::menus::model::refresh(&mut app, &egui::Context::default());
|
||||
crate::menus::model::refresh(&mut app, &crate::testing::ui_context());
|
||||
let mut seen = std::collections::HashMap::new();
|
||||
for e in &entries(&app, lang) {
|
||||
let row = (kind_of(id_of(e)).0, e.label().as_str().to_string(), e.home().map(|h| h.as_str().to_string()));
|
||||
@@ -2178,7 +2178,7 @@ mod tests {
|
||||
/// An app over `session` with its menu model built in the current language.
|
||||
fn app_on_current(session: Session) -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(session, crate::Services::default());
|
||||
crate::menus::model::refresh(&mut app, &egui::Context::default());
|
||||
crate::menus::model::refresh(&mut app, &crate::testing::ui_context());
|
||||
app
|
||||
}
|
||||
|
||||
@@ -2260,7 +2260,7 @@ mod tests {
|
||||
fn on(session: Session) -> Window {
|
||||
crate::i18n::set_current(Lang::EN);
|
||||
let app = VectorcraftApp::new(session, crate::Services::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.enable_accesskit();
|
||||
let mut window = Window { app, ctx, time: 0.0 };
|
||||
window.frame(vec![]);
|
||||
|
||||
@@ -114,7 +114,7 @@ impl Harness {
|
||||
let host = Rc::new(RefCell::new(Host { windows: HashMap::new(), focus: ViewportId::ROOT, time: 0.0 }));
|
||||
let shared = host.clone();
|
||||
egui::Context::set_immediate_viewport_renderer(move |ctx, viewport| Host::render(&shared, ctx, viewport));
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.set_embed_viewports(false);
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
|
||||
@@ -24,7 +24,7 @@ impl Harness {
|
||||
fn new() -> Self {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.enable_accesskit();
|
||||
let mut h = Self { app, ctx, time: 0.0, nodes: Vec::new() };
|
||||
h.frames(3);
|
||||
|
||||
@@ -698,7 +698,10 @@ pub(crate) fn paint_chip(app: &mut VectorcraftApp, ui: &mut Ui, stroke: bool) {
|
||||
}
|
||||
// The popover keeps its own open state: the Swatches body opens menus of its own (Swatch
|
||||
// Libraries, Show Swatch Kinds), which close with it (#536).
|
||||
let _ = Popover::new(label, Bind::bound(&mut open)).opened_by(&out.edit.response).show(ui, |ui, _| paint_popover(app, ui));
|
||||
// The Swatches body is one collection that scrolls inside the popover's room; the mixer scrolls with the popover.
|
||||
let popover = Popover::new(label, Bind::bound(&mut open)).opened_by(&out.edit.response);
|
||||
let popover = if app.ui.paint_popover.is_some_and(|p| p.mixer) { popover } else { popover.collection_body() };
|
||||
let _ = popover.show(ui, |ui, _| paint_popover(app, ui));
|
||||
if !open {
|
||||
app.ui.paint_popover = None;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ fn tap(key: egui::Key, modifiers: egui::Modifiers) -> Vec<egui::Event> {
|
||||
|
||||
/// A context whose first whole app frame has run, so the board holds the app's keymap.
|
||||
fn ready(app: &mut VectorcraftApp) -> egui::Context {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
key_frame(app, &ctx, vec![]);
|
||||
ctx
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ fn place_cursor_exec_checks_recording_step_limit_on_completion() {
|
||||
assert_eq!(placed(&app), 0);
|
||||
assert_ne!(app.ui.status, steps, "nothing is checked before the file is placed");
|
||||
// The read runs on the place lane; a frame after it ends places the file.
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let t0 = std::time::Instant::now();
|
||||
while !app.placing.pending.is_empty() && t0.elapsed().as_secs() < 60 {
|
||||
craft::ui::shell::embed::before_input(&ctx, |out| app.frame_input(out));
|
||||
@@ -535,7 +535,7 @@ fn a_journal_rewrite_or_a_direct_commit_is_checked_on_the_next_frame() {
|
||||
let into = set_actions(&app, 0)[0].name.clone();
|
||||
app.run(START_RECORDING, json!({})).unwrap();
|
||||
app.ui.recording_into = Some(into);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let frame = |app: &mut VectorcraftApp| {
|
||||
craft::ui::shell::embed::before_input(&ctx, |out| app.frame_input(out));
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| app.tick(ui.ctx()));
|
||||
|
||||
@@ -87,7 +87,7 @@ fn menu_insert_rows_open_their_dialog_on_the_selected_step_the_action_end_or_the
|
||||
};
|
||||
for id in ["actionsPanel.insertStop", "actionsPanel.insertMenuItem", "ui.action.selectObjectDialog"] {
|
||||
let mut app = with_sets();
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app.ui.actions.insert_step(1, 0, craft::automation::actions::ActionStep::new("a.b", json!({}))).unwrap();
|
||||
app.ui.actions_panel.expanded.insert("A in S2".into());
|
||||
|
||||
|
||||
@@ -130,18 +130,18 @@ fn list_events_and_menu_rows_reach_their_commands() {
|
||||
apply(&mut app, vec![PageListEvent::new_row(None, true)]);
|
||||
assert_eq!(board_names(&app).len(), 5, "no artboard is added before OK");
|
||||
assert!(is_open::<ArtboardOptionsDialog>(&app));
|
||||
cancel_open(&mut app, &egui::Context::default());
|
||||
cancel_open(&mut app, &crate::testing::ui_context());
|
||||
|
||||
// Options, Fit and Rearrange.
|
||||
let mut app = menu_app(3);
|
||||
apply(&mut app, vec![PageListEvent::Options(2)]);
|
||||
assert_eq!((selected(&app, 3), is_open::<ArtboardOptionsDialog>(&app)), (2, true));
|
||||
cancel_open(&mut app, &egui::Context::default());
|
||||
cancel_open(&mut app, &crate::testing::ui_context());
|
||||
apply(&mut app, vec![PageListEvent::Fit(1)]);
|
||||
assert_eq!(app.view().unwrap().artboard, 1);
|
||||
apply(&mut app, vec![PageListEvent::Rearrange]);
|
||||
assert!(is_open::<RearrangeArtboardsDialog>(&app));
|
||||
cancel_open(&mut app, &egui::Context::default());
|
||||
cancel_open(&mut app, &crate::testing::ui_context());
|
||||
|
||||
// The panel menu's rows: Rename asks the list to open a field; another id is not the panel's.
|
||||
let mut app = menu_app(3);
|
||||
@@ -435,7 +435,7 @@ fn the_panel_menus_artboard_options_opens_the_active_artboards_options() {
|
||||
app.session.execute("artboard.new", &json!({"x": 400, "y": 300, "width": 100, "height": 50})).unwrap();
|
||||
select(&mut app, 1);
|
||||
let tool = app.session.tool_id().to_string();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("tool.options", json!({"tool": "artboard"})).unwrap();
|
||||
assert!(is_open::<ArtboardOptionsDialog>(&app));
|
||||
let fields = dialog_fields(&app);
|
||||
@@ -578,7 +578,7 @@ fn choosing_the_artboard_tool_starts_it_on_the_active_artboard() {
|
||||
assert_eq!(app.ui.artboards_ui.rename, None);
|
||||
app.run("tool.options", json!({"tool": "artboard"})).unwrap();
|
||||
assert_eq!(dialog_fields(&app)["index"].as_f64(), Some(1.0), "Artboard Options shows the active artboard");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
cancel_open(&mut app, &ctx);
|
||||
let view = app.view_info();
|
||||
crate::canvas::dispatch(&mut app, &vectorcraft_tools::PointerEvent::new(vectorcraft_tools::PointerKind::Move, 100.0, 75.0), view);
|
||||
@@ -617,7 +617,7 @@ fn dragging_a_row_onto_new_artboard_duplicates_it() {
|
||||
#[test]
|
||||
fn the_row_menus_rename_opens_the_rename_dialog_for_the_selected_artboards() {
|
||||
let mut app = menu_app(4);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
select(&mut app, 2);
|
||||
app.session.set_tool_option("selected", &json!([2, 1]));
|
||||
let steps = undo_steps(&app);
|
||||
@@ -652,7 +652,7 @@ fn the_row_menu_renames_the_right_clicked_artboard_with_any_tool() {
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 50, "units": "Points", "artboards": 3})).unwrap();
|
||||
app.session.execute("artboard.setProps", &json!({"index": 2, "locked": true})).unwrap();
|
||||
select(&mut app, 0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
apply(&mut app, vec![set_rows(&[1])]);
|
||||
assert_eq!((app.session.tool_id(), selected(&app, 3)), (app.session.tool_id(), 1), "the right-clicked artboard is active, the tool unchanged");
|
||||
apply(&mut app, vec![set_rows(&[2])]);
|
||||
@@ -717,7 +717,7 @@ fn alt_clicking_new_artboard_opens_artboard_options_for_the_new_artboard() {
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 150})).unwrap();
|
||||
app.session.execute("artboard.new", &json!({"x": 400, "y": 300, "width": 100, "height": 50})).unwrap();
|
||||
select(&mut app, 0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let count = |app: &VectorcraftApp| app.session.active().unwrap().doc.artboards.len();
|
||||
// Alt: the dialog for Artboard 3, 20 pt right of Artboard 2 and as large; no artboard yet.
|
||||
apply(&mut app, vec![PageListEvent::new_row(None, true)]);
|
||||
@@ -753,7 +753,7 @@ fn alt_clicking_new_artboard_opens_artboard_options_for_the_new_artboard() {
|
||||
#[test]
|
||||
fn new_artboard_options_with_an_empty_name_add_the_default_name() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
assert!(app.run("ui.newArtboard", json!({})).is_err(), "no document");
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 150})).unwrap();
|
||||
app.select_tool("artboard");
|
||||
@@ -1063,7 +1063,7 @@ fn the_artboard_tools_menu_fits_the_selected_artboards_and_undoes() {
|
||||
#[test]
|
||||
fn the_artboard_tools_menu_deletes_empty_artboards_and_opens_dialogs() {
|
||||
let mut app = menu_app(3);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
|
||||
// PLAN: assumed `crate::dialogs::ExportForScreensDialog` (ex.A8).
|
||||
let opened: [(&str, fn(&VectorcraftApp) -> bool); 4] = [
|
||||
|
||||
@@ -255,7 +255,7 @@ mod tests {
|
||||
|
||||
/// The URLs the app asked egui to open in one frame.
|
||||
fn opened(app: &mut VectorcraftApp) -> Vec<String> {
|
||||
let out = egui::Context::default().run_ui(egui::RawInput::default(), |ui| app.tick(ui.ctx()));
|
||||
let out = crate::testing::ui_context().run_ui(egui::RawInput::default(), |ui| app.tick(ui.ctx()));
|
||||
out.platform_output
|
||||
.commands
|
||||
.iter()
|
||||
|
||||
@@ -1359,7 +1359,7 @@ fn panels_show_the_same_with_the_kept_selected_stories() {
|
||||
fn panels_work_out_the_selected_stories_once_per_frame() {
|
||||
let (mut app, [a, ..], other) = story_selected_in_its_first_frame();
|
||||
app.run("select.set", json!({"ids": [other, a]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let frame = |app: &mut VectorcraftApp| {
|
||||
let builds = STORY_BUILDS.get();
|
||||
super::super::tests_appearance::frame_events(&ctx, app, vec![], |app, ui| {
|
||||
|
||||
@@ -312,7 +312,7 @@ fn ui_color_panel_answers_junk_params_without_a_panic() {
|
||||
#[test]
|
||||
fn a_mixed_selection_has_no_colour_to_edit() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let b = app.run("shape.rectangle", json!({"x": 80, "y": 10, "width": 50, "height": 50})).unwrap()["id"].clone();
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#ff0000"})).unwrap();
|
||||
@@ -339,7 +339,7 @@ fn picked_mesh_points_are_the_color_the_panel_shows_and_edits() {
|
||||
use vectorcraft_engine::ViewInfo;
|
||||
use vectorcraft_tools::{PointerEvent, PointerKind};
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let id = app.session.active().unwrap().selection.objects[0];
|
||||
app.run("paint.setFill", json!({"color": "#ff8500"})).unwrap();
|
||||
app.run("object.mesh.create", json!({"rows": 2, "cols": 2})).unwrap();
|
||||
|
||||
@@ -829,7 +829,7 @@ mod tests {
|
||||
/// A click on the cell at `at` of the guide shown now, through the panel's click glue.
|
||||
fn click(app: &mut VectorcraftApp, at: GuideCellAt) {
|
||||
let cell = cell_at(&guide_of(app), at);
|
||||
let mut out = egui::Context::default().run_ui(egui::RawInput::default(), |ui| chosen(app, ui, cell));
|
||||
let mut out = crate::testing::ui_context().run_ui(egui::RawInput::default(), |ui| chosen(app, ui, cell));
|
||||
out.textures_delta.clear();
|
||||
}
|
||||
|
||||
@@ -847,7 +847,7 @@ mod tests {
|
||||
app.run("paint.setFill", json!({"color": "#ff0000"})).unwrap();
|
||||
let blue = app.run("shape.rectangle", json!({"x": 20, "y": 0, "width": 10, "height": 10})).unwrap()["id"].clone();
|
||||
app.run("paint.setFill", json!({"color": "#3366cc"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
assert_eq!(base_color(&app).to_hex(), "#3366cc", "the first show takes the current color");
|
||||
app.run("select.set", json!({"ids": [red]})).unwrap();
|
||||
@@ -872,7 +872,7 @@ mod tests {
|
||||
let mut app = app();
|
||||
app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#3366cc"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let g = guide_of(&app);
|
||||
let fill = |app: &VectorcraftApp| crate::panels::current_paints(app).0.color().map(|c| c.to_hex());
|
||||
@@ -898,7 +898,7 @@ mod tests {
|
||||
#[test]
|
||||
fn save_colors_as_swatches_saves_each_selected_cell() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let before = app.session.doc().unwrap().doc.swatches.len();
|
||||
let cells = picked_cells(&app, &[(0, 0), (1, 4), (0, 8)]);
|
||||
@@ -917,7 +917,7 @@ mod tests {
|
||||
let mut app = app();
|
||||
app.run("file.documentColorMode", json!({"mode": "cmyk"})).unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#3366cc", "keepModel": true})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let cells = picked_cells(&app, &[(0, 0), (0, 6)]);
|
||||
save_selected(&mut app, &cells);
|
||||
@@ -939,7 +939,7 @@ mod tests {
|
||||
#[test]
|
||||
fn save_color_group_saves_the_selected_cells_in_grid_order() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let st = app.session.doc().unwrap();
|
||||
let (groups, swatches, undo) = (st.doc.swatch_groups.len(), st.doc.swatches.len(), st.history.undo.len());
|
||||
@@ -961,7 +961,7 @@ mod tests {
|
||||
#[test]
|
||||
fn save_color_group_without_a_selection_saves_the_harmony_colors() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let g = guide_of(&app);
|
||||
save_group(&mut app, &[]);
|
||||
@@ -976,7 +976,7 @@ mod tests {
|
||||
app.run("file.documentColorMode", json!({"mode": "cmyk"})).unwrap();
|
||||
app.run("paint.setFill", json!({"color": "#c04020", "keepModel": true})).unwrap();
|
||||
app.run("ui.colorGuideLimit", json!({"library": "web-safe-216"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let g = guide(&mut app);
|
||||
let cells: Vec<GuideCell> = [(0, 1), (0, 7)].iter().map(|&(row, column)| cell_at(&g, grid(row, column))).collect();
|
||||
@@ -1019,7 +1019,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_spot_color_base_gives_tints_of_that_spot_color() {
|
||||
let mut app = spot_app(1.0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let g = guide_of(&app);
|
||||
let c = g.centre();
|
||||
@@ -1060,7 +1060,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_tinted_spot_base_gives_lighter_tints_and_a_lost_link_gives_process_colors() {
|
||||
let mut app = spot_app(0.5);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let c = guide_of(&app).centre();
|
||||
let cell = |app: &VectorcraftApp, _: &egui::Context, col| cell_paint(app, &guide_of(app), 0, col).unwrap();
|
||||
@@ -1091,7 +1091,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_renamed_spot_color_stays_the_base() {
|
||||
let mut app = spot_app(1.0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let c = guide_of(&app).centre();
|
||||
app.run("swatch.edit", json!({"name": "Ink", "newName": "Deep Ink"})).unwrap();
|
||||
@@ -1116,7 +1116,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_deleted_spot_color_ends_the_link() {
|
||||
let mut app = spot_app(1.0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let c = guide_of(&app).centre();
|
||||
let linked = |app: &VectorcraftApp, _: &egui::Context| {
|
||||
@@ -1186,7 +1186,7 @@ mod tests {
|
||||
#[test]
|
||||
fn an_undone_rename_keeps_the_link() {
|
||||
let mut app = spot_app(1.0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let c = guide_of(&app).centre();
|
||||
let linked = |app: &VectorcraftApp, _: &egui::Context| {
|
||||
@@ -1240,7 +1240,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_resting_link_keeps_the_color_it_showed() {
|
||||
let mut app = spot_app(1.0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let shown = base_color(&app);
|
||||
app.session.execute("swatch.delete", &json!({"name": "Ink"})).unwrap();
|
||||
@@ -1260,7 +1260,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_script_run_ends_the_link() {
|
||||
let mut app = spot_app(1.0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
// Commands that only list scripts or plug-ins keep the link, also as batch steps.
|
||||
app.run("script.engines", json!({})).unwrap();
|
||||
@@ -1279,7 +1279,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_batch_follows_the_spot_color_across_documents() {
|
||||
let mut app = spot_app(1.0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let c = guide_of(&app).centre();
|
||||
let linked = |app: &VectorcraftApp, _: &egui::Context| {
|
||||
@@ -1409,7 +1409,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_deleted_color_group_ends_the_link() {
|
||||
let mut app = spot_app(1.0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let c = guide_of(&app).centre();
|
||||
let linked = |app: &VectorcraftApp, _: &egui::Context| {
|
||||
@@ -1465,7 +1465,7 @@ mod tests {
|
||||
#[test]
|
||||
fn saved_spot_tints_are_tint_swatches_of_the_spot_color() {
|
||||
let mut app = spot_app(1.0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx);
|
||||
let g = guide_of(&app);
|
||||
let c = g.centre();
|
||||
@@ -1532,7 +1532,7 @@ mod tests {
|
||||
#[test]
|
||||
fn limit_to_library_snaps_the_panel_and_follows_the_document_swatches() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("paint.setFill", json!({"color": "#3a7bd5"})).unwrap();
|
||||
frame(&mut app, &ctx);
|
||||
assert!(shown(&mut app).contains(&"#3a7bd5".to_string()), "no limit: the base itself");
|
||||
@@ -1564,7 +1564,7 @@ mod tests {
|
||||
#[test]
|
||||
fn edit_or_apply_without_art_saves_the_limited_colours_as_a_group() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.run("paint.setFill", json!({"color": "#c04020"})).unwrap();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
app.run("ui.colorGuideLimit", json!({"library": "web-safe-216"})).unwrap();
|
||||
@@ -1582,7 +1582,7 @@ mod tests {
|
||||
let g = guide(&mut app);
|
||||
assert_eq!(rows.len(), g.colors.len());
|
||||
assert!(g.colors.iter().all(|c| members.contains(&c.to_hex())), "the colors are the library's");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
assert!(dialogs.with(|host| host.confirm_by_id(&ctx, recolor.id)), "OK confirms");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ fn escape_ends_the_stop_eyedropper_and_returns_to_the_gradient_tool() {
|
||||
app.run("gradient.selectStop", json!({"index": 0})).unwrap();
|
||||
let (paint, selected) = (current(&app), app.session.active().unwrap().selection.objects.clone());
|
||||
stop_eyedropper(&mut app);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let escape = egui::Event::Key { key: Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE };
|
||||
crate::tests::synthetic::key_frame(&mut app, &ctx, vec![escape]);
|
||||
assert_eq!(app.session.tool_id(), "gradient");
|
||||
|
||||
@@ -490,6 +490,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
]
|
||||
};
|
||||
Panel::new(tl!("Graphic Styles"))
|
||||
.collection_body()
|
||||
.footer(|ui, _| *footer.borrow_mut() = Some(FooterBar::actions(actions.clone()).at_start(AT_START).show_footer(ui)))
|
||||
.show(ui, |ui, _| {
|
||||
PresetBrowser::new(tl!("Graphic Styles"), Bind::bound(&mut panel.state), &source)
|
||||
|
||||
@@ -259,7 +259,7 @@ mod tests {
|
||||
let mut app = app_with_two_rectangles();
|
||||
app.session.execute("edit.undo", &json!({})).unwrap();
|
||||
let source = app.session.active().unwrap().doc.clone();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.enable_accesskit();
|
||||
egui_extras::install_image_loaders(&ctx);
|
||||
let screen = Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(240.0, 400.0)));
|
||||
|
||||
@@ -287,7 +287,7 @@ mod tests {
|
||||
|
||||
/// Every line the panel shows.
|
||||
fn texts(app: &mut VectorcraftApp) -> Vec<String> {
|
||||
let l = lines(app, &egui::Context::default());
|
||||
let l = lines(app, &crate::testing::ui_context());
|
||||
let mut out: Vec<String> = l.left.into_iter().chain(l.right).chain(l.zoom).chain(l.brush).collect();
|
||||
for p in [l.fill, l.stroke] {
|
||||
out.extend(p.values);
|
||||
@@ -321,7 +321,7 @@ mod tests {
|
||||
let id = run(&mut app, "text.create", json!({"x": 10, "y": 150, "text": "Hi", "size": 12}))["id"].clone();
|
||||
run(&mut app, "select.set", json!({ "ids": [id] }));
|
||||
run(&mut app, "object.scale", json!({"sx": 200}));
|
||||
let size = lines(&mut app, &egui::Context::default()).type_block.map(|(_, size)| size);
|
||||
let size = lines(&mut app, &crate::testing::ui_context()).type_block.map(|(_, size)| size);
|
||||
assert_eq!(size.as_deref(), Some("Size: 24 pt Tracking: 0"));
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ fn deleting_a_layer_that_holds_art_asks_first() {
|
||||
let art = app.session.active().unwrap().doc.layers[0].id;
|
||||
run(&mut app, "layer.new", json!({}));
|
||||
let there = |app: &VectorcraftApp| app.session.active().unwrap().doc.node(art).is_some();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let question = Some("Delete this layer and its artwork?".to_string());
|
||||
feed(&mut app, vec![LayersEvent::Delete(vec![layer_key(art)])]);
|
||||
assert_eq!(asked(&app), question, "Delete asks");
|
||||
@@ -195,7 +195,7 @@ fn deleting_a_layer_that_holds_art_asks_first() {
|
||||
#[test]
|
||||
fn delete_selection_asks_only_for_layers_with_art() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let run = |app: &mut VectorcraftApp, id: &str, p: serde_json::Value| app.session.execute(id, &p).unwrap();
|
||||
let id = |v: serde_json::Value| v["id"].as_u64().unwrap();
|
||||
run(&mut app, "file.new", json!({"width": 200, "height": 200}));
|
||||
@@ -240,7 +240,7 @@ fn delete_selection_asks_only_for_layers_with_art() {
|
||||
#[test]
|
||||
fn delete_selection_refusals_and_a_document_change() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let run = |app: &mut VectorcraftApp, id: &str, p: serde_json::Value| app.session.execute(id, &p).unwrap();
|
||||
run(&mut app, "file.new", json!({"width": 200, "height": 200}));
|
||||
run(&mut app, "shape.rectangle", json!({"x": 0, "y": 0, "width": 20, "height": 20}));
|
||||
@@ -350,7 +350,7 @@ pub(super) fn undo_len(app: &VectorcraftApp) -> usize {
|
||||
fn cmd_alt_l_opens_new_layer_options() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let layers = |app: &VectorcraftApp| app.session.active().unwrap().doc.layers.len();
|
||||
// PLAN: assumed `Chord::parse(&str) -> Option<Chord>` and `Chord::to_egui_shortcut() -> egui::KeyboardShortcut`.
|
||||
let press = |app: &mut VectorcraftApp, chord: &str| {
|
||||
|
||||
@@ -150,7 +150,7 @@ fn stored(ctx: &egui::Context, uid: u64) -> (usize, usize) {
|
||||
#[test]
|
||||
fn closing_a_document_releases_only_its_layer_thumbnails() {
|
||||
let (mut app, _, _) = two_rects();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
let first = app.session.active().unwrap().uid;
|
||||
pass(&mut app, &ctx);
|
||||
@@ -174,7 +174,7 @@ fn closing_a_document_releases_only_its_layer_thumbnails() {
|
||||
fn row_thumbnails_wait_for_the_end_of_a_drag() {
|
||||
let (mut app, _, _) = two_rects();
|
||||
app.session.execute("select.all", &json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let uid = app.session.active().unwrap().uid;
|
||||
for _ in 0..4 {
|
||||
pass(&mut app, &ctx);
|
||||
@@ -202,7 +202,7 @@ fn row_thumbnails_wait_for_the_end_of_a_drag() {
|
||||
#[test]
|
||||
fn rename_opens_the_name_field_of_the_selected_object() {
|
||||
let (mut app, _, [a, _]) = two_rects();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
let name = |app: &VectorcraftApp| app.session.doc().unwrap().doc.node(a).unwrap().display_name();
|
||||
let before = name(&app);
|
||||
@@ -227,7 +227,7 @@ fn rename_opens_the_name_field_of_the_selected_object() {
|
||||
#[test]
|
||||
fn rename_names_the_current_layer_and_refuses_several_or_hidden_rows() {
|
||||
let (mut app, layer, [a, b]) = two_rects();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
assert_eq!(app.run("ui.rename", json!({})).unwrap()["id"], json!(layer.0), "nothing selected: the current layer");
|
||||
app.ui.layers_ui.rename = None;
|
||||
@@ -304,7 +304,7 @@ fn isolation_opens_the_isolated_row_and_keeps_drops_inside_it() {
|
||||
#[test]
|
||||
fn isolation_drops_highlights_outside_the_isolated_art() {
|
||||
let (mut app, [_, sub, _, b, _, c]) = nested();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.session.execute("layer.highlight", &json!({"ids": [c.0, b.0], "mode": "set"})).unwrap();
|
||||
app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap();
|
||||
pass(&mut app, &ctx);
|
||||
@@ -315,7 +315,7 @@ fn isolation_drops_highlights_outside_the_isolated_art() {
|
||||
#[test]
|
||||
fn isolation_keeps_rename_and_locate_to_the_rows_listed() {
|
||||
let (mut app, [layer, sub, g, b, _, c]) = nested();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.ui_ctx = Some(ctx.clone());
|
||||
app.session.execute("object.isolate", &json!({"id": sub.0})).unwrap();
|
||||
let err = app.run("ui.rename", json!({"id": c.0})).unwrap_err();
|
||||
@@ -455,7 +455,7 @@ fn isolation_keeps_a_confirmed_delete_to_the_rows_listed() {
|
||||
#[test]
|
||||
fn isolation_opens_the_isolated_row_of_each_document() {
|
||||
let (mut app, [_, _, g, ..]) = nested();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
pass(&mut app, &ctx);
|
||||
app.session.execute("document.activate", &json!({"index": 0})).unwrap();
|
||||
@@ -512,7 +512,7 @@ fn isolation_keeps_alt_clicks_on_eyes_and_locks_inside_it() {
|
||||
#[test]
|
||||
fn with_show_layers_only_locate_object_becomes_locate_layer() {
|
||||
let (mut app, [layer, sub, _, b, _, _]) = nested();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.session.execute("select.set", &json!({"ids": [b.0]})).unwrap();
|
||||
assert!(locate_titled(&app, "Locate Object"));
|
||||
footer_locate(&mut app);
|
||||
@@ -537,7 +537,7 @@ fn with_show_layers_only_locate_object_becomes_locate_layer() {
|
||||
#[test]
|
||||
fn a_repeated_locate_reveals_the_row_it_already_highlighted() {
|
||||
let (mut app, [layer, sub, g, b, _, _]) = nested();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.session.execute("select.set", &json!({"ids": [b.0]})).unwrap();
|
||||
|
||||
options(&mut app).layers_only = true;
|
||||
@@ -595,7 +595,7 @@ fn groups_of_one(n: usize) -> (VectorcraftApp, NodeId, Vec<NodeId>) {
|
||||
#[test]
|
||||
fn without_the_option_a_selection_leaves_the_rows_and_the_scroll_as_they_were() {
|
||||
let (mut app, layer, paths) = groups_of_one(500);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
pass(&mut app, &ctx);
|
||||
app.session.execute("select.set", &json!({"ids": [paths[0].0]})).unwrap();
|
||||
assert_eq!(reveal_of(&app), Some(LayersReveal::Selected(paths[0])));
|
||||
@@ -613,7 +613,7 @@ fn without_the_option_a_selection_leaves_the_rows_and_the_scroll_as_they_were()
|
||||
fn with_the_option_a_selected_object_is_opened_and_scrolled_into_view() {
|
||||
let (mut app, layer, paths) = groups_of_one(500);
|
||||
options(&mut app).locate_selected = true;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let top = parent(&app, paths[499]).unwrap();
|
||||
app.session.execute("layer.highlight", &json!({"ids": [top.0]})).unwrap();
|
||||
pass(&mut app, &ctx);
|
||||
@@ -637,7 +637,7 @@ fn with_the_option_the_panels_own_clicks_locate_nothing() {
|
||||
let (mut app, [layer, sub, g, b, _, c]) = nested();
|
||||
options(&mut app).locate_selected = true;
|
||||
expand(&mut app, &json!({"ids": [sub.0, g.0], "open": false})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
pass(&mut app, &ctx);
|
||||
assert_eq!(listed_ids(&app).len(), 3, "Layer 1, Sub (closed) and c");
|
||||
select_rows(&mut app, &[layer, sub, c]);
|
||||
@@ -658,7 +658,7 @@ fn with_the_option_the_panel_menu_locates_nothing() {
|
||||
let (mut app, [_, sub, g, b, _, c]) = nested();
|
||||
options(&mut app).locate_selected = true;
|
||||
app.session.execute("select.set", &json!({"ids": [b.0, c.0]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
pass(&mut app, &ctx);
|
||||
expand(&mut app, &json!({"ids": [sub.0, g.0], "open": false})).unwrap();
|
||||
app.session.execute("layer.highlight", &json!({"ids": [c.0]})).unwrap();
|
||||
@@ -679,7 +679,7 @@ fn with_the_option_a_selection_recalled_from_the_panel_menu_is_not_located() {
|
||||
app.run("select.set", json!({"ids": [b.0]})).unwrap();
|
||||
app.run("select.save", json!({"name": "Kept"})).unwrap();
|
||||
app.run("select.set", json!({"ids": [c.0]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
pass(&mut app, &ctx);
|
||||
expand(&mut app, &json!({"ids": [sub.0, g.0], "open": false})).unwrap();
|
||||
pass(&mut app, &ctx);
|
||||
@@ -699,7 +699,7 @@ fn with_the_option_a_document_becoming_active_locates_nothing() {
|
||||
options(&mut app).locate_selected = true;
|
||||
app.session.execute("layer.highlight", &json!({"ids": []})).unwrap();
|
||||
app.session.execute("select.set", &json!({"ids": [b.0]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
pass(&mut app, &ctx);
|
||||
expand(&mut app, &json!({"ids": [sub.0, g.0], "open": false})).unwrap();
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
@@ -721,7 +721,7 @@ fn with_the_option_a_selection_made_during_a_drag_is_located_when_it_ends() {
|
||||
let (mut app, [_, sub, g, b, ..]) = nested();
|
||||
options(&mut app).locate_selected = true;
|
||||
app.session.execute("select.set", &json!({"ids": [b.0]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
pass(&mut app, &ctx);
|
||||
expand(&mut app, &json!({"ids": [sub.0, g.0], "open": false})).unwrap();
|
||||
pass(&mut app, &ctx);
|
||||
@@ -749,7 +749,7 @@ fn with_the_option_the_located_object_is_revealed_instead_of_its_active_layer()
|
||||
options(&mut app).locate_selected = true;
|
||||
app.session.execute("layer.new", &json!({})).unwrap();
|
||||
assert_ne!(app.session.active().unwrap().current_layer(), Some(layer));
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
pass(&mut app, &ctx);
|
||||
app.session.execute("select.set", &json!({"ids": [paths[0].0]})).unwrap();
|
||||
assert_eq!(app.session.active().unwrap().current_layer(), Some(layer), "the path's layer is the active one");
|
||||
@@ -776,7 +776,7 @@ fn with_the_option_and_show_layers_only_the_active_layer_is_revealed() {
|
||||
rect(&mut app);
|
||||
}
|
||||
run(&mut app, "select.none", json!({}));
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
pass(&mut app, &ctx);
|
||||
let bottom_layer = app.session.active().unwrap().doc.layer_of(NodeId(bottom)).unwrap();
|
||||
run(&mut app, "select.set", json!({"ids": [bottom]}));
|
||||
@@ -794,7 +794,7 @@ fn with_the_option_and_show_layers_only_the_active_layer_is_revealed() {
|
||||
fn with_the_option_art_the_panel_does_not_list_opens_nothing() {
|
||||
let (mut app, _, paths) = groups_of_one(500);
|
||||
options(&mut app).locate_selected = true;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let open = |app: &VectorcraftApp, i: usize| is_open(app, parent(app, paths[i]).unwrap());
|
||||
let locate = |app: &mut VectorcraftApp, i: usize| {
|
||||
app.session.execute("select.set", &json!({"ids": [paths[i].0]})).unwrap();
|
||||
@@ -830,7 +830,7 @@ fn a_canvas_selection_reveals_its_active_layer() {
|
||||
rects.push(run(&mut app, "shape.rectangle", json!({"x": 0, "y": 0, "width": 5, "height": 5}))["id"].as_u64().unwrap());
|
||||
}
|
||||
run(&mut app, "select.none", json!({}));
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
pass(&mut app, &ctx);
|
||||
let doc = app.session.active().unwrap().doc.clone();
|
||||
let bottom_layer = doc.layer_of(NodeId(rects[0])).unwrap();
|
||||
|
||||
@@ -48,7 +48,7 @@ fn click(app: &mut VectorcraftApp, ctx: &egui::Context, name: &str, draw: fn(&mu
|
||||
}
|
||||
|
||||
fn context() -> egui::Context {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.enable_accesskit();
|
||||
crate::testing::install(&ctx);
|
||||
ctx
|
||||
|
||||
@@ -736,6 +736,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let mut footer_pick = None;
|
||||
let (mut activated, mut menu_for, mut row_act) = (None, None, None);
|
||||
Panel::new(tl!("Links"))
|
||||
.collection_body()
|
||||
.footer(|ui, _| {
|
||||
let info = FooterAction::new(IconId::new(if o.info { "chevron-down" } else { "chevron-right" }), tl!("Show Link Info"));
|
||||
let actions = std::iter::once(info)
|
||||
|
||||
@@ -485,7 +485,7 @@ mod tests {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let request = ThumbRequest::for_cell(100.0, 1.0);
|
||||
// One pass of the panel's picture: the images the store uploaded in it, and the version asked for.
|
||||
let frame = |app: &mut VectorcraftApp, held: bool| {
|
||||
|
||||
@@ -75,7 +75,7 @@ fn start_global_edit_quick_action_and_escape() {
|
||||
assert!(panel.shows("Stop Global Edit") && !panel.shows("Start Global Edit"));
|
||||
// The escape chain is the app's key stage, which the panel harness does not run.
|
||||
let escape = Event::Key { key: Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() };
|
||||
key_frame(&mut panel.app(), &egui::Context::default(), vec![escape]);
|
||||
key_frame(&mut panel.app(), &crate::testing::ui_context(), vec![escape]);
|
||||
panel.frame();
|
||||
assert!(!on(&panel), "Escape stops Global Edit");
|
||||
assert!(panel.shows("Start Global Edit"));
|
||||
@@ -476,7 +476,7 @@ fn artboard_history_delete_after_undo(key: Key, duplicate: bool) {
|
||||
(st.doc.clone(), st.selection.clone(), st.history.undo.len())
|
||||
};
|
||||
let mut panel = artboards_panel(app);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
add_board(&mut panel, duplicate);
|
||||
assert_eq!(undo_depth(&panel.app()), undo + 1);
|
||||
artboard_history_key(&mut panel, &ctx, Key::Z, Modifiers::COMMAND);
|
||||
@@ -569,7 +569,7 @@ fn artboard_history_undo_prunes_only_removed_indices() {
|
||||
(st.doc.clone(), st.selection.clone(), st.history.undo.len())
|
||||
};
|
||||
let mut panel = artboards_panel(app);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
artboard_history_new(&mut panel);
|
||||
let created = panel.app().session.doc().unwrap().doc.clone();
|
||||
for (at, i) in order.into_iter().enumerate() {
|
||||
@@ -606,7 +606,7 @@ fn artboard_history_valid_multiselection_survives_undo_redo() {
|
||||
app.session.set_tool_option("moveArt", &json!(false));
|
||||
app.session.set_tool_option("scaleArt", &json!(true));
|
||||
let mut panel = artboards_panel(app);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
select_artboard_rows(&mut panel, &[0, 1]);
|
||||
let (options, view, before, selection, undo) = {
|
||||
let mut app = panel.app();
|
||||
|
||||
@@ -153,10 +153,14 @@ fn plates_section(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
ColumnSpec::new(NAME, Label::Empty, ColumnWidth::fill(1.0)),
|
||||
];
|
||||
// Disabled while the preview is off: the eyes then take no press and the rows read dim.
|
||||
let out = List::new(tl!("Plates")).id_salt("plates").select(SelectMode::None).sizing(Sizing::Content).enabled(on).columns(columns).show_items(
|
||||
ui,
|
||||
&rows,
|
||||
&mut |key, item| {
|
||||
let out = List::new(tl!("Plates"))
|
||||
.id_salt("plates")
|
||||
.select(SelectMode::None)
|
||||
.sizing(Sizing::Content)
|
||||
.natural_height(true)
|
||||
.enabled(on)
|
||||
.columns(columns)
|
||||
.show_items(ui, &rows, &mut |key, item| {
|
||||
let Some(row) = rows.0.get(*key) else { return ListRow::new(Label::Empty) };
|
||||
let tooltip =
|
||||
if *key == 0 { tl!("Show all plates") } else { tl!("Show/hide plate (Alt-click: only this plate; Alt-click again: all plates)") };
|
||||
@@ -167,8 +171,7 @@ fn plates_section(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
});
|
||||
}
|
||||
list_row.cells(item.cells()).state(item.row.clone())
|
||||
},
|
||||
);
|
||||
});
|
||||
for event in out.events {
|
||||
// A flip lands once: a click's set, or a sweep's commit at the release. It carries the Alt held at the press.
|
||||
let CollectionEvent::Toggle(EditEvent::Set { after: edit, .. } | EditEvent::Commit { after: edit, .. }) = event else { continue };
|
||||
|
||||
@@ -566,6 +566,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
];
|
||||
let footer: RefCell<Option<FooterOutput>> = RefCell::new(None);
|
||||
let mut shown = Panel::new(tl!("Symbols"))
|
||||
.collection_body()
|
||||
.footer(|ui, _| *footer.borrow_mut() = Some(FooterBar::actions(actions.clone()).at_start(AT_START).show_footer(ui)))
|
||||
.show(ui, |ui, _| {
|
||||
// Art dropped anywhere on the list becomes a symbol; dropped on a symbol, the browser's
|
||||
|
||||
@@ -131,7 +131,7 @@ fn window(app: &VectorcraftApp) -> egui::Context {
|
||||
|
||||
/// `app` with a window for its dialogs, as its first frame gives it one.
|
||||
fn windowed(mut app: VectorcraftApp) -> VectorcraftApp {
|
||||
app.ui_ctx = Some(egui::Context::default());
|
||||
app.ui_ctx = Some(crate::testing::ui_context());
|
||||
app
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ pub(super) fn text_rect(texts: &[(String, egui::Rect)], s: &str) -> egui::Rect {
|
||||
|
||||
/// One whole app frame, so the dialog host and the effect dialogs' pump run as in production.
|
||||
pub(super) fn app_frame(app: &mut VectorcraftApp) {
|
||||
key_frame(app, &egui::Context::default(), vec![]);
|
||||
key_frame(app, &crate::testing::ui_context(), vec![]);
|
||||
}
|
||||
|
||||
/// The id of the open effect dialog.
|
||||
@@ -152,7 +152,7 @@ fn shows(panel: &mut Panel, name: &str) -> bool {
|
||||
/// The Cmd+/ or Cmd+Alt+/ key pressed through the whole app frame.
|
||||
fn press_slash(app: &mut VectorcraftApp, modifiers: egui::Modifiers) {
|
||||
let ev = egui::Event::Key { key: egui::Key::Slash, physical_key: None, pressed: true, repeat: false, modifiers };
|
||||
key_frame(app, &egui::Context::default(), vec![ev]);
|
||||
key_frame(app, &crate::testing::ui_context(), vec![ev]);
|
||||
}
|
||||
|
||||
/// The name of the colour chip of the "Fill:" or "Stroke:" row.
|
||||
|
||||
@@ -94,7 +94,7 @@ fn ui_color_wheel_sets_and_reads_the_view_and_the_channel() {
|
||||
let e = app.run("ui.colorWheel", json!({"view": "wheel", "channel": 7})).unwrap_err();
|
||||
assert_eq!(e, "`channel` must be hue, saturation, brightness, red, green or blue");
|
||||
assert_eq!(app.ui.color_wheel, Settings { view: View::Box, channel: Channel::Green, ..Default::default() }, "an error changes nothing");
|
||||
let ui = crate::control::inspect(&app, &egui::Context::default());
|
||||
let ui = crate::control::inspect(&app, &crate::testing::ui_context());
|
||||
assert_eq!(ui["ui"]["color_wheel"], with(json!({"view": "box", "channel": "green"})));
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ fn ui_color_wheel_sets_and_reads_the_settings() {
|
||||
let settings = |view: &str, vision: bool| json!({"view": view, "channel": "hue", "gamut": false, "harmony": false, "harmonyRule": "complementary", "vision": vision, "sliders": "none", "documentColors": false});
|
||||
assert_eq!(app.run("ui.colorWheel", json!({})).unwrap(), settings("wheel", false));
|
||||
assert_eq!(app.run("ui.colorWheel", json!({"vision": true})).unwrap(), settings("wheel", true));
|
||||
assert_eq!(crate::control::inspect(&app, &egui::Context::default())["ui"]["color_wheel"]["vision"], true);
|
||||
assert_eq!(crate::control::inspect(&app, &crate::testing::ui_context())["ui"]["color_wheel"]["vision"], true);
|
||||
assert_eq!(app.run("ui.colorWheel", json!({"vision": "no"})).unwrap_err(), "`vision` must be true or false");
|
||||
assert_eq!(app.run("ui.colorWheel", json!({"view": "box", "channel": "red", "vision": 1})).unwrap_err(), "`vision` must be true or false");
|
||||
assert_eq!(app.run("ui.colorWheel", json!({})).unwrap(), settings("wheel", true));
|
||||
|
||||
@@ -604,7 +604,7 @@ fn unembed_writes_several_images_to_one_picked_folder() {
|
||||
std::fs::create_dir_all(&out).unwrap();
|
||||
// PLAN: assumed `scripted` and `poll` of fl.A20 live in `crate::tests::picks`.
|
||||
let picker = scripted(&mut app);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
assert!(super::links::can_unembed(&app, 2));
|
||||
// No folder picked: nothing written or linked.
|
||||
super::links::unembed_several(&mut app, vec![embedded, other]);
|
||||
|
||||
@@ -71,7 +71,7 @@ fn align_stroke_styles_the_characters_the_type_tool_selects() {
|
||||
app.session.apply_actions(vec![vectorcraft_tools::Action::Notify("text.editNew".into())]).unwrap();
|
||||
app.session.set_tool_option("select", &json!({"start": 0, "end": 2}));
|
||||
assert!(character::text_editing(&app).is_some());
|
||||
assert!(stroke_mixed(&app, &egui::Context::default()).can_align, "the buttons are on");
|
||||
assert!(stroke_mixed(&app, &crate::testing::ui_context()).can_align, "the buttons are on");
|
||||
let mut panel = Panel::new(app, stroke::show);
|
||||
panel.click("Outside");
|
||||
let app = panel.app();
|
||||
@@ -92,13 +92,13 @@ fn the_stroke_panel_shows_the_live_paint_bucket_stroke_as_one_stroke() {
|
||||
run(&mut app, "stroke.set", json!({"weight": 1, "ids": [a]}));
|
||||
run(&mut app, "stroke.set", json!({"weight": 7, "ids": [b]}));
|
||||
run(&mut app, "select.set", json!({ "ids": [] }));
|
||||
let none_selected = stroke_mixed(&app, &egui::Context::default());
|
||||
let none_selected = stroke_mixed(&app, &crate::testing::ui_context());
|
||||
assert!(none_selected.can_align, "Align Stroke applies with nothing selected");
|
||||
run(&mut app, "select.set", json!({ "ids": [a, b] }));
|
||||
let mixed = stroke_mixed(&app, &egui::Context::default());
|
||||
let mixed = stroke_mixed(&app, &crate::testing::ui_context());
|
||||
assert!(mixed.weight, "the selection's weights differ");
|
||||
app.session.select_tool("livePaintBucket", Default::default()).unwrap();
|
||||
let mixed = stroke_mixed(&app, &egui::Context::default());
|
||||
let mixed = stroke_mixed(&app, &crate::testing::ui_context());
|
||||
assert_eq!(mixed, none_selected, "one stroke that Align Stroke applies to, as with nothing selected");
|
||||
assert_eq!(stroke::shown_weight(&app, current_stroke(&app).as_ref(), &mixed), Some(app.session.paint.stroke_width));
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ fn an_object_type_reaches_every_selected_object_in_one_undo_step() {
|
||||
fn a_drag_ends_when_the_selection_goes_away() {
|
||||
let mut app = app();
|
||||
set_type(&mut app, "extrude").unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let history = undo_len(&app);
|
||||
begin(&mut app, GESTURE);
|
||||
update(&mut app, GESTURE, &[("depth", json!(90.0))]);
|
||||
@@ -497,7 +497,7 @@ fn a_light_drag_keeps_the_objects_whose_lights_matched_when_it_started() {
|
||||
fn a_drag_ends_when_the_panel_is_no_longer_drawn() {
|
||||
let mut app = app();
|
||||
set_type(&mut app, "extrude").unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let history = undo_len(&app);
|
||||
begin(&mut app, GESTURE);
|
||||
update(&mut app, GESTURE, &[("depth", json!(90.0))]);
|
||||
|
||||
@@ -863,7 +863,7 @@ fn app_without_transform_panel() -> VectorcraftApp {
|
||||
/// saved steps and in Presentation Mode the panel stays closed.
|
||||
#[test]
|
||||
fn show_on_shape_creation_shows_the_transform_panel_after_a_shape() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let visible = |app: &VectorcraftApp| crate::panel_docking::visible(&app, "transform");
|
||||
let rect = json!({"x": 10, "y": 10, "width": 40, "height": 30});
|
||||
|
||||
|
||||
@@ -209,6 +209,7 @@ fn mask_row(
|
||||
let keys = [()];
|
||||
List::<()>::new(tl!("Opacity mask thumbnails"))
|
||||
.select(SelectMode::None)
|
||||
.natural_height(true)
|
||||
.enabled(object)
|
||||
.show_items(ui, &keyed(&keys, |_| ()), &mut |_, _| row.take().unwrap_or_else(|| ListRow::new("")))
|
||||
.events
|
||||
|
||||
@@ -595,7 +595,7 @@ fn a_synchronous_paste_replaces_a_deferred_swatch_dialog() {
|
||||
app.sync_views();
|
||||
let result = crate::control::handle(
|
||||
&mut app,
|
||||
&egui::Context::default(),
|
||||
&crate::testing::ui_context(),
|
||||
&craft::automation::ControlRequest::new("engine.execute", json!({"command": "edit.pasteInPlace", "params": {}})).0,
|
||||
);
|
||||
let craft::automation::Reply::Done(result) = result else { panic!("expected command result") };
|
||||
@@ -635,7 +635,7 @@ fn a_find_font_dialog_releases_a_deferred_swatch_paste_before_queued_work() {
|
||||
assert!(requested != newer);
|
||||
let result = crate::control::handle(
|
||||
&mut app,
|
||||
&egui::Context::default(),
|
||||
&crate::testing::ui_context(),
|
||||
&craft::automation::ControlRequest::new("engine.execute", json!({"command": "type.findFont", "params": {}})).0,
|
||||
);
|
||||
let craft::automation::Reply::Done(result) = result else { panic!("expected command result") };
|
||||
@@ -683,7 +683,7 @@ fn a_deferred_swatch_paste_rejects_a_changed_token_or_closed_document() {
|
||||
} else {
|
||||
let result = crate::control::handle(
|
||||
&mut app,
|
||||
&egui::Context::default(),
|
||||
&crate::testing::ui_context(),
|
||||
&craft::automation::ControlRequest::new("ui.dialog.set", json!({"field": "__deferredPaste", "value": 999999})).0,
|
||||
);
|
||||
let craft::automation::Reply::Done(result) = result else { panic!("expected dialog result") };
|
||||
@@ -1350,7 +1350,7 @@ fn what_the_user_places_is_read_off_the_ui_thread_and_commands_read_at_once() {
|
||||
assert_eq!(app.ui.status, "Placing a.tif, b.bmp…");
|
||||
assert_eq!(app.session.tool_id(), "selection");
|
||||
let (inspect, _) = craft::automation::ControlRequest::new("ui.inspect", json!({}));
|
||||
let craft::automation::Reply::Done(r) = crate::control::handle(&mut app, &egui::Context::default(), &inspect) else { panic!("not done") };
|
||||
let craft::automation::Reply::Done(r) = crate::control::handle(&mut app, &crate::testing::ui_context(), &inspect) else { panic!("not done") };
|
||||
assert_eq!(r["result"]["placing"], json!(["a.tif, b.bmp"]), "ui.inspect lists the files being read");
|
||||
placed(&mut app);
|
||||
assert_eq!((app.session.tool_id(), app.session.tool_options()["count"].as_u64()), ("place", Some(2)));
|
||||
@@ -1508,7 +1508,7 @@ fn a_placed_image_is_drawn_without_decoding_it_on_the_ui_thread() {
|
||||
let blob = st.doc.images.values().next().unwrap().clone();
|
||||
assert!(vectorcraft_render::image_cached(&blob), "kept before the canvas draws it");
|
||||
let decodes = vectorcraft_render::image_decodes();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 600.0))), ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw, |ui| crate::canvas::show(&mut app, ui));
|
||||
out.textures_delta.clear();
|
||||
|
||||
@@ -131,7 +131,7 @@ fn saved_scheme_accent_and_canvas_color_show_from_the_first_frame() {
|
||||
for (key, value) in [("uiColorScheme", "classic"), ("uiAccent", "pink"), ("canvasColor", "white")] {
|
||||
app.run("prefs.set", json!({"key": key, "value": value})).unwrap();
|
||||
}
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
for _ in 0..2 {
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| app.tick(ui.ctx()));
|
||||
out.textures_delta.clear();
|
||||
@@ -148,7 +148,7 @@ fn saved_scheme_accent_and_canvas_color_show_from_the_first_frame() {
|
||||
#[test]
|
||||
fn a_render_threads_change_restarts_the_renderer_at_the_next_push() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
apply_runtime(&mut app, &ctx);
|
||||
app.canvas.worker_started = true;
|
||||
// The automatic count as an explicit value: the process-wide count other tests read stays the same.
|
||||
|
||||
@@ -1515,7 +1515,7 @@ mod tests {
|
||||
/// An app whose window has drawn a frame, so the `shortcuts.*` commands have its keymap.
|
||||
fn app() -> (VectorcraftApp, egui::Context) {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
crate::tests::synthetic::key_frame(&mut app, &ctx, vec![]);
|
||||
(app, ctx)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ struct Keyboard {
|
||||
|
||||
impl Keyboard {
|
||||
fn new() -> Self {
|
||||
Self { ctx: egui::Context::default() }
|
||||
Self { ctx: crate::testing::ui_context() }
|
||||
}
|
||||
|
||||
/// One frame at `time` seconds delivering `events`.
|
||||
|
||||
@@ -45,7 +45,7 @@ fn press_f() -> Vec<egui::Event> {
|
||||
|
||||
/// A context that has run its first pass, which builds the board's keymap.
|
||||
fn ready(app: &mut VectorcraftApp) -> egui::Context {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
key_frame(app, &ctx, vec![]);
|
||||
ctx
|
||||
}
|
||||
@@ -507,7 +507,7 @@ fn cmd_comma_opens_settings_on_a_mac() {
|
||||
let on = |os, setup: fn(&mut VectorcraftApp)| {
|
||||
let mut app = new_app();
|
||||
setup(&mut app);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.set_os(os);
|
||||
key_frame(&mut app, &ctx, vec![]);
|
||||
key_frame(&mut app, &ctx, tap(Key::Comma, Modifiers::COMMAND));
|
||||
|
||||
@@ -579,7 +579,7 @@ fn a_pass_with_injected_input_runs_inside_the_roots() {
|
||||
}
|
||||
}
|
||||
let (mut app, tx, base) = confined("synthetic");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let (req, _reply) = ControlRequest::new("ui.key", json!({"key": "Escape"}));
|
||||
tx.send(req).unwrap();
|
||||
app.run_control(&ctx);
|
||||
@@ -691,11 +691,11 @@ fn ui_inspect_leaves_out_paths_outside_the_read_root() {
|
||||
"ui.dialog.set",
|
||||
json!({"fields": [{"field": "fontsFolder", "value": inside}, {"field": "templatesFolder", "value": outside}]}),
|
||||
);
|
||||
let Reply::Done(filled) = crate::control::handle(&mut app, &egui::Context::default(), &fill) else { panic!("deferred") };
|
||||
let Reply::Done(filled) = crate::control::handle(&mut app, &crate::testing::ui_context(), &fill) else { panic!("deferred") };
|
||||
assert_eq!(filled["ok"], true, "{filled}");
|
||||
|
||||
// The person sees every path.
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let person = crate::control::inspect(&app, &ctx);
|
||||
assert_eq!(person["opening"], json!([a, b, c]));
|
||||
assert_eq!(person["ui"]["recent_files"], json!([a, b, c]));
|
||||
@@ -745,7 +745,7 @@ fn ui_inspect_leaves_out_an_insert_menu_item_path_outside_the_read_root() {
|
||||
set_top_fields(app, &[("command", json!(load)), ("params", json!({"path": path}))]);
|
||||
};
|
||||
pick(&mut app, &outside);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
assert_eq!(top_dialog_fields(&crate::control::inspect(&app, &ctx))["params"]["path"], outside, "the person sees it");
|
||||
let r = request(&mut app, &tx, "ui.inspect", json!({}));
|
||||
let fields = top_dialog_fields(&r["result"]);
|
||||
@@ -784,7 +784,7 @@ fn ui_inspect_hides_a_selected_javascript_file_outside_the_read_root() {
|
||||
crate::dialogs::javascript_files::open(&mut app).unwrap();
|
||||
set_top_fields(&mut app, &[("selected", json!(outside))]);
|
||||
let selected = |v: &Value| top_dialog_fields(v)["selected"].clone();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
assert_eq!(selected(&crate::control::inspect(&app, &ctx)), json!(outside), "the person's");
|
||||
let r = request(&mut app, &tx, "ui.inspect", json!({}));
|
||||
assert_eq!(selected(&r["result"]), "menu.js", "{r}");
|
||||
@@ -1287,7 +1287,7 @@ fn ui_inspect_hides_a_closed_librarys_path_outside_the_read_root() {
|
||||
assert!(hidden_panels(ui).iter().any(|p| p == "library:swatches:loaded/b.svg"), "{r}");
|
||||
let hidden = json!(s(base.join("outside"))).to_string();
|
||||
assert!(!r.to_string().contains(hidden.trim_matches('"')), "no path outside the root: {r}");
|
||||
assert_eq!(crate::control::inspect(&app, &egui::Context::default())["ui"]["color_guide_limit"], json!(theirs), "the person's");
|
||||
assert_eq!(crate::control::inspect(&app, &crate::testing::ui_context())["ui"]["color_guide_limit"], json!(theirs), "the person's");
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
}
|
||||
|
||||
@@ -1386,7 +1386,7 @@ fn ui_inspect_script_report_leaves_out_files_outside_the_read_root() {
|
||||
}
|
||||
};
|
||||
finish(&mut app, json!({"source": source, "name": "t.js"}));
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let outside = json!(s(base.join("outside"))).to_string();
|
||||
let person = crate::control::inspect(&app, &ctx);
|
||||
assert_eq!(person["scriptReport"]["written"], json!([kept, hidden]), "{person}");
|
||||
|
||||
@@ -33,7 +33,7 @@ impl Gate {
|
||||
/// Gives `app` a window host over `jobs`, as the window installs it, so its background work runs
|
||||
/// where the test says.
|
||||
pub(crate) fn with_jobs(app: &mut VectorcraftApp, jobs: Arc<dyn craft::host::Jobs>) {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
craft::host::Host::builder(craft::host::AppInfo { id: "vectorcraft", name: "VectorCraft", version: env!("CARGO_PKG_VERSION") })
|
||||
.jobs(jobs)
|
||||
.install(&ctx);
|
||||
@@ -557,7 +557,7 @@ fn controlled_with(
|
||||
fn request(app: &mut VectorcraftApp, tx: &std::sync::mpsc::Sender<ControlRequest>, method: &str, params: Value) -> Value {
|
||||
let (req, reply) = ControlRequest::new(method, params);
|
||||
tx.send(req).unwrap();
|
||||
app.run_control(&egui::Context::default());
|
||||
app.run_control(&crate::testing::ui_context());
|
||||
reply.try_recv().unwrap()
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ fn with_system_clipboard(text: &'static str) -> VectorcraftApp {
|
||||
let mut app = VectorcraftApp::new(Session::new(), services);
|
||||
run(&mut app, "file.new", json!({"width": 200, "height": 200}));
|
||||
assert!(!menus::enabled(&app, "edit.paste"), "not checked before a frame");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ctx.run_ui(Default::default(), |ui| app.tick(ui.ctx())).textures_delta.clear();
|
||||
app
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ fn right_click_selects_the_object_and_lists_its_commands() {
|
||||
let mut app = app();
|
||||
let id = rect(&mut app, 50.0, 50.0);
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
assert!(app.ui.context_menu_at.is_none() && !has(&app, "Arrange"));
|
||||
let p = screen(&app, 100.0, 100.0);
|
||||
@@ -121,7 +121,7 @@ fn right_click_selects_the_object_and_lists_its_commands() {
|
||||
fn right_click_on_empty_canvas_offers_the_view_and_selects_nothing() {
|
||||
let mut app = app();
|
||||
app.select_tool("rectangle");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let p = screen(&app, 300.0, 250.0);
|
||||
click(&mut app, &ctx, p, PointerButton::Secondary);
|
||||
@@ -141,7 +141,7 @@ fn right_click_on_a_locked_object_offers_unlock_by_its_name() {
|
||||
let mut app = app();
|
||||
let id = rect(&mut app, 50.0, 50.0);
|
||||
app.run("layer.setProps", json!({"ids": [id.0], "name": "Sky", "locked": true})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let p = screen(&app, 100.0, 100.0);
|
||||
click(&mut app, &ctx, p, PointerButton::Secondary);
|
||||
@@ -166,7 +166,7 @@ fn cmd_alt_shift_u_switches_to_the_next_unit() {
|
||||
let mut app = app();
|
||||
assert_eq!(app.run("shortcuts.conflicts", json!({})).unwrap(), json!([]), "no other default has the key");
|
||||
fn press(app: &mut VectorcraftApp) {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
crate::tests_synthetic::key_frame(app, &ctx, vec![]);
|
||||
let modifiers = egui::Modifiers::COMMAND | egui::Modifiers::ALT | egui::Modifiers::SHIFT;
|
||||
let ev = Event::Key { key: egui::Key::U, physical_key: None, pressed: true, repeat: false, modifiers };
|
||||
@@ -409,7 +409,7 @@ fn right_click_where_three_intertwined_objects_overlap_arranges_the_nearest_one(
|
||||
app.run("select.set", json!({"ids": [a.0, b.0, c.0]})).unwrap();
|
||||
let g = NodeId(app.run("object.intertwine.make", json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
assert_eq!(app.session.tool_id(), "intertwine");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
// By the right edge of A (the first rectangle), where all three overlap.
|
||||
let p = screen(&app, 169.0, 100.0);
|
||||
@@ -515,7 +515,7 @@ fn right_click_on_an_underlined_word_offers_its_suggestions() {
|
||||
.map(|s| s.as_str().unwrap().to_string())
|
||||
.collect();
|
||||
assert!(!want.is_empty(), "the dictionary has suggestions for `speling`");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let p = word_at(&app, id, 4, 11);
|
||||
click(&mut app, &ctx, p, PointerButton::Secondary);
|
||||
@@ -535,7 +535,7 @@ fn right_click_on_an_underlined_word_offers_its_suggestions() {
|
||||
fn no_spelling_items_off_a_misspelled_word_or_with_auto_spell_check_off() {
|
||||
let mut app = app();
|
||||
let id = spelled(&mut app, "the Vqzxtrwk");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let p = word_at(&app, id, 0, 3);
|
||||
click(&mut app, &ctx, p, PointerButton::Secondary);
|
||||
@@ -556,7 +556,7 @@ fn no_spelling_items_off_a_misspelled_word_or_with_auto_spell_check_off() {
|
||||
fn a_word_under_other_type_is_not_the_one_right_clicked() {
|
||||
let mut app = app();
|
||||
let under = spelled(&mut app, "Qzvxtrwk");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let p = word_at(&app, under, 0, 8);
|
||||
click(&mut app, &ctx, p, PointerButton::Secondary);
|
||||
@@ -580,7 +580,7 @@ fn in_an_intertwine_group_the_type_drawn_on_top_is_the_one_right_clicked() {
|
||||
let g = NodeId(app.run("object.intertwine.make", json!({})).unwrap()["id"].as_u64().unwrap());
|
||||
app.select_tool("selection");
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
// A point on the word where glyphs of both overlap: Intertwine's areas follow the outlines.
|
||||
let quad = {
|
||||
|
||||
@@ -23,7 +23,7 @@ fn app_with_line() -> (VectorcraftApp, u64) {
|
||||
|
||||
/// One app frame pressing `key`, after an empty frame that builds the board's keymap.
|
||||
fn press(app: &mut VectorcraftApp, key: Key) {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
key_frame(app, &ctx, vec![]);
|
||||
let ev = egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE };
|
||||
key_frame(app, &ctx, vec![ev]);
|
||||
|
||||
@@ -61,7 +61,7 @@ impl GuideDrag {
|
||||
let (before, selection, undo) = (st.doc.clone(), st.selection.clone(), st.history.undo.len());
|
||||
let mut f = Self {
|
||||
app,
|
||||
ctx: egui::Context::default(),
|
||||
ctx: crate::testing::ui_context(),
|
||||
time: 0.0,
|
||||
vertical,
|
||||
copy,
|
||||
|
||||
@@ -34,7 +34,7 @@ fn home_shows_over_open_documents_until_a_document_is_chosen() {
|
||||
app.run("app.home", json!({})).unwrap();
|
||||
assert!(!shows_document(&mut app), "Home replaces the canvas");
|
||||
assert_eq!(app.session.documents().len(), 1, "the document stays open");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
assert!(!dialogs_open(&mut app, &ctx), "Home is not the New Document dialog");
|
||||
// Choosing the document's tab returns to it.
|
||||
app.ui.home = None;
|
||||
@@ -76,7 +76,7 @@ fn home_screen_without_documents_follows_its_preference() {
|
||||
fn cmd_alt_n_makes_a_document_without_the_new_document_dialog() {
|
||||
use vectorcraft_doc::ColorMode;
|
||||
use vectorcraft_engine::cmd::newdoc;
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let press = |app: &mut VectorcraftApp| {
|
||||
// The first frame of a context builds the keymap the key stage reads.
|
||||
crate::tests_synthetic::key_frame(app, &ctx, vec![]);
|
||||
|
||||
@@ -71,7 +71,7 @@ fn run_frame(
|
||||
#[test]
|
||||
fn a_discarded_rerun_runs_a_duplicate_once() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// Fonts install on the first pass and are ready on the second.
|
||||
run_frame(&mut app, &ctx, vec![], |_| {}, false);
|
||||
run_frame(&mut app, &ctx, vec![], |_| {}, false);
|
||||
@@ -139,7 +139,7 @@ fn preedit(t: &str, chars: usize) -> Event {
|
||||
#[test]
|
||||
fn home_takes_down_a_live_composition() {
|
||||
let (mut app, id) = app_with_text("Same");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ime_frame(&mut app, &ctx, vec![], |_| {});
|
||||
ime_frame(&mut app, &ctx, vec![], |_| {});
|
||||
begin_typing(&mut app, &ctx, id);
|
||||
@@ -157,7 +157,7 @@ fn home_takes_down_a_live_composition() {
|
||||
#[test]
|
||||
fn closing_the_document_takes_down_a_live_composition() {
|
||||
let (mut app, id) = app_with_text("Same");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ime_frame(&mut app, &ctx, vec![], |_| {});
|
||||
ime_frame(&mut app, &ctx, vec![], |_| {});
|
||||
begin_typing(&mut app, &ctx, id);
|
||||
@@ -176,7 +176,7 @@ fn an_ime_quote_commit_uses_the_character_before_its_pre_edit() {
|
||||
let (mut app, id) = app_with_text("a");
|
||||
// The pre-edit ends in an opening quote, but replacement starts after the letter `a`.
|
||||
app.run("document.setup", json!({"quotes": {"double": ["\"", "”"]}})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ime_frame(&mut app, &ctx, vec![], |_| {});
|
||||
ime_frame(&mut app, &ctx, vec![], |_| {});
|
||||
begin_typing(&mut app, &ctx, id);
|
||||
@@ -192,7 +192,7 @@ fn an_ime_quote_commit_uses_the_character_before_its_pre_edit() {
|
||||
#[test]
|
||||
fn ime_delete_surrounding_then_commit_edit_the_type_tool_once_in_order() {
|
||||
let (mut app, id) = app_with_text("abc");
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
ime_frame(&mut app, &ctx, vec![], |_| {});
|
||||
ime_frame(&mut app, &ctx, vec![], |_| {});
|
||||
begin_typing(&mut app, &ctx, id);
|
||||
|
||||
@@ -110,7 +110,7 @@ impl Mac {
|
||||
if native {
|
||||
app.services.native_menu = Some(NativeMenu::new(Box::new(fake.clone())));
|
||||
}
|
||||
let mut m = Mac { app, fake, ctx: egui::Context::default(), time: 0.0 };
|
||||
let mut m = Mac { app, fake, ctx: crate::testing::ui_context(), time: 0.0 };
|
||||
for _ in 0..3 {
|
||||
m.frame(vec![]);
|
||||
}
|
||||
@@ -377,7 +377,7 @@ fn a_key_equivalent_paste_pastes_a_picture_from_another_app() {
|
||||
super::sysclip::copy_elsewhere(&board, vec![(PNG, super::sysclip::blue_png())]);
|
||||
let fake = Fake::default();
|
||||
app.services.native_menu = Some(NativeMenu::new(Box::new(fake.clone())));
|
||||
let mut m = Mac { app, fake, ctx: egui::Context::default(), time: 0.0 };
|
||||
let mut m = Mac { app, fake, ctx: crate::testing::ui_context(), time: 0.0 };
|
||||
for _ in 0..3 {
|
||||
m.frame(vec![]);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ fn cmd_shift_v_pastes_in_place() {
|
||||
app.run("file.new", json!({"width": 400, "height": 400})).unwrap();
|
||||
let id = app.run("shape.rectangle", json!({"x": 10, "y": 20, "width": 30, "height": 30})).unwrap()["id"].clone();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
frame(&mut app, &ctx, Modifiers::NONE, vec![]);
|
||||
frame(&mut app, &ctx, Modifiers::COMMAND, vec![Event::Copy]);
|
||||
let svg = app.clipboard.read_text().ok().flatten().expect("copy publishes SVG");
|
||||
|
||||
@@ -208,7 +208,7 @@ fn laid_out(app: &mut VectorcraftApp, ctx: &egui::Context) -> egui::Rect {
|
||||
#[test]
|
||||
fn a_drop_with_a_position_places_on_the_canvas_and_opens_off_it() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let rect = laid_out(&mut app, &ctx);
|
||||
let pos = rect.center() + vec2(60.0, -40.0);
|
||||
let want = app.canvas_view().unwrap().to_doc(pos);
|
||||
@@ -228,7 +228,7 @@ fn a_drop_with_a_position_places_on_the_canvas_and_opens_off_it() {
|
||||
#[test]
|
||||
fn a_drop_without_a_position_opens_documents_and_places_pictures() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
laid_out(&mut app, &ctx);
|
||||
let center = app.view().unwrap().center;
|
||||
let uid = app.session.active().unwrap().uid;
|
||||
@@ -267,7 +267,7 @@ fn a_dropped_file_of_each_library_kind_opens_in_its_destination() {
|
||||
let path = dir.file(name, &bytes);
|
||||
for route in 0..4 {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let rect = laid_out(&mut app, &ctx);
|
||||
match route {
|
||||
0 => frame(&mut app, &ctx, over(rect), &[&path], false),
|
||||
@@ -310,7 +310,7 @@ fn a_dropped_file_of_each_library_kind_opens_in_its_destination() {
|
||||
#[test]
|
||||
fn a_dropped_png_is_placed_where_it_was_dropped() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let rect = laid_out(&mut app, &ctx);
|
||||
let dir = Folder::new("ui-place-png");
|
||||
let path = dir.file("drop.png", &png(20, 10, 72.0));
|
||||
@@ -333,7 +333,7 @@ fn a_dropped_png_is_placed_where_it_was_dropped() {
|
||||
#[test]
|
||||
fn a_dropped_document_opens_as_a_tab_of_its_own() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
laid_out(&mut app, &ctx);
|
||||
let dir = Folder::new("ui-place-tab");
|
||||
let svg = dir.file("dropped.svg", SVG.as_bytes());
|
||||
@@ -353,7 +353,7 @@ fn a_native_svg_drop_uses_file_open_even_with_a_path_only_handle() {
|
||||
let dir = Folder::new("ui-place-path-only");
|
||||
let path = dir.file("path-only.svg", SVG.as_bytes());
|
||||
let mut dropped = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
laid_out(&mut dropped, &ctx);
|
||||
let handle = Arc::new(MockDrop { path: path.clone().into(), bytes: Err("only a path".into()) }) as egui::DroppedFileHandle;
|
||||
frame_files(&mut dropped, &ctx, vec![], vec![handle], false);
|
||||
@@ -379,7 +379,7 @@ fn a_native_svg_drop_uses_file_open_even_with_a_path_only_handle() {
|
||||
#[test]
|
||||
fn an_svg_drop_without_a_path_is_detected_from_its_bytes() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let rect = laid_out(&mut app, &ctx);
|
||||
let svg = Arc::new(MockDrop { path: Default::default(), bytes: Ok(SVG.as_bytes().to_vec()) }) as egui::DroppedFileHandle;
|
||||
frame_files(&mut app, &ctx, vec![], vec![svg], false);
|
||||
@@ -396,7 +396,7 @@ fn an_svg_drop_without_a_path_is_detected_from_its_bytes() {
|
||||
#[test]
|
||||
fn multiple_svg_drops_open_individually() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
laid_out(&mut app, &ctx);
|
||||
let dir = Folder::new("ui-place-several-svg");
|
||||
let a = dir.file("first.svg", SVG.as_bytes());
|
||||
@@ -410,7 +410,7 @@ fn multiple_svg_drops_open_individually() {
|
||||
#[test]
|
||||
fn unsupported_and_unreadable_drops_leave_the_document_open() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let rect = laid_out(&mut app, &ctx);
|
||||
let dir = Folder::new("ui-place-unreadable");
|
||||
// Over the canvas the first is a place; the SVGs are dropped off it, so they open.
|
||||
@@ -433,7 +433,7 @@ fn unsupported_and_unreadable_drops_leave_the_document_open() {
|
||||
#[test]
|
||||
fn files_dropped_with_no_document_open_open_and_are_recent() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let dir = Folder::new("ui-place-no-document");
|
||||
let path = dir.file("open-me.png", &png(8, 8, 72.0));
|
||||
frame(&mut app, &ctx, vec![], &[], false);
|
||||
@@ -456,7 +456,7 @@ fn a_file_read_after_another_document_became_active_lands_where_it_was_dropped()
|
||||
let mut app = app();
|
||||
let inbox = crate::place::PlaceInbox::default();
|
||||
app.services.place_inbox = Some(inbox.clone());
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let rect = laid_out(&mut app, &ctx);
|
||||
let want = app.canvas_view().unwrap().to_doc(rect.center() + vec2(60.0, -40.0));
|
||||
let drop_on_active = |app: &VectorcraftApp| match app.drop_target("late.png", DropSpot::Canvas(want), false) {
|
||||
@@ -488,7 +488,7 @@ fn a_file_read_after_another_document_became_active_lands_where_it_was_dropped()
|
||||
#[test]
|
||||
fn the_place_dialog_lists_the_files_and_loads_the_cursor_with_several() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let dir = Folder::new("ui-place-dialog");
|
||||
let a = dir.file("a.png", &png(300, 150, 300.0));
|
||||
let b = dir.file("b.png", &png(10, 10, 72.0));
|
||||
@@ -509,7 +509,7 @@ fn the_place_dialog_lists_the_files_and_loads_the_cursor_with_several() {
|
||||
#[test]
|
||||
fn one_file_places_centred_in_the_view_and_replace_swaps_the_selection() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
app.view_mut().unwrap().center = vectorcraft_geom::Point::new(120.0, 80.0);
|
||||
let dir = Folder::new("ui-place-replace");
|
||||
place_picked(&mut app, &ctx, &dir.file("one.png", &png(300, 150, 300.0)));
|
||||
@@ -704,7 +704,7 @@ fn the_control_bars_mask_clips_the_image_and_selects_the_clipping_path() {
|
||||
#[test]
|
||||
fn a_vectorcraft_document_places_linked_and_edit_original_opens_it() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
// A one-artboard document with a rectangle.
|
||||
let mut src = Session::new();
|
||||
src.execute("file.new", &json!({"width": 100, "height": 50})).unwrap();
|
||||
@@ -736,7 +736,7 @@ fn a_vectorcraft_document_places_linked_and_edit_original_opens_it() {
|
||||
#[test]
|
||||
fn the_place_dialog_links_a_pdf_page_and_embeds_it_with_link_off() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut src = Session::new();
|
||||
src.execute("file.new", &json!({"width": 100, "height": 50})).unwrap();
|
||||
src.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 100, "height": 50})).unwrap();
|
||||
@@ -760,7 +760,7 @@ fn the_place_dialog_links_a_pdf_page_and_embeds_it_with_link_off() {
|
||||
#[test]
|
||||
fn the_place_dialog_offers_a_postscript_ai_and_an_eps_file_as_a_locked_object() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let ps = b"%!PS-Adobe-3.0\n%%BoundingBox: 0 0 100 100\n%%EndComments\n1 0 0 setrgbcolor 10 10 50 50 rectfill\nshowpage\n%%EOF\n";
|
||||
let dir = Folder::new("ui-place-postscript");
|
||||
for name in ["legacy.ai", "legacy.eps", "legacy.ps"] {
|
||||
@@ -1347,7 +1347,7 @@ fn a_file_placed_while_idle_follows_its_changes() {
|
||||
// worker during the idle frames asks for a repaint.
|
||||
app.canvas.worker_started = true;
|
||||
app.run("prefs.set", json!({"key": "updateLinks", "value": "automatically"})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut time = 0.0;
|
||||
idle(&mut app, &ctx, &mut time, 3.0, &|_| false);
|
||||
// A look finds the new document without links: no wakes of its own for it.
|
||||
@@ -1386,7 +1386,7 @@ fn a_look_whose_worker_stopped_does_not_stop_later_looks() {
|
||||
let path = dir.file("stopped-watch.png", &png(40, 30, 72.0));
|
||||
app.run("file.place", json!({"path": path})).unwrap();
|
||||
let id = app.session.active().unwrap().selection.objects[0];
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = crate::testing::ui_context();
|
||||
let mut time = 0.0;
|
||||
idle(&mut app, &ctx, &mut time, 3.0, &|_| false);
|
||||
// A look that is due starts in this frame and is applied in the next one, at the same time.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user