mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Menus: the start of a drag keeps every row's state
While an interaction is open (a move, scale or shape drag, a dialog's preview, a typing session), the menus' state key left the document revision out, so the key changed in the frame the interaction began and the menus rebuilt every row's state for it, on top of the rebuilds for the press and the release. A rebuild costs about 8 ms on small documents and about 160 ms with 10,000 objects selected. An interaction now records the revision it began from, and the key uses that revision while the interaction is open. The key stays the same as a drag begins and through its previews, and changes when it ends. The new test drives a Selection tool move through the whole app and counts the rebuilds in each frame: one for the press and one for the release, none as the move begins.
This commit is contained in:
1 parent
1772dfcce3
commit
950467b7de
4 files changed
+36
-3
No files matched your search
@@ -10,6 +10,9 @@ pub struct Interaction {
|
||||
pub doc: Arc<Document>,
|
||||
/// The selection the previews start from (shared, so a preview frame copies nothing).
|
||||
pub selection: Arc<Selection>,
|
||||
/// The document's [`crate::DocState::revision`] when the interaction began. The previews change the document's
|
||||
/// revision, and this value stays the same until the interaction ends.
|
||||
pub revision: u64,
|
||||
pub preview: Option<(String, Value)>,
|
||||
/// The active tool began it (a drag): a command from outside the tool runs as a step of its
|
||||
/// own under it ([`crate::Session::outside_interaction`]). A dialog or a panel that begins an
|
||||
|
||||
@@ -545,6 +545,7 @@ impl Session {
|
||||
effect: None,
|
||||
doc: st.doc.clone(),
|
||||
selection: Arc::new(st.selection.clone()),
|
||||
revision: st.revision,
|
||||
preview: None,
|
||||
tool: false,
|
||||
paint,
|
||||
|
||||
@@ -841,6 +841,35 @@ fn the_move_of_a_releasing_frame_counts_for_the_tool_drag() {
|
||||
assert_eq!(draw(true), Rect::new(130.0, 115.0, 160.0, 130.0), "with Space held through the release the last move moves it");
|
||||
}
|
||||
|
||||
/// A Selection tool move builds the menus' states again twice, in the frame of its press and in the frame of its
|
||||
/// release, which commits the move. The frame the move begins in and the frames of its previews, which change the
|
||||
/// document's revision, keep them.
|
||||
#[test]
|
||||
fn a_selection_move_rebuilds_the_menus_for_its_press_and_release_only() {
|
||||
let (mut app, ctx, xf) = rectangle_tool();
|
||||
let id = app.session.execute("shape.rectangle", &json!({"x": 100, "y": 100, "width": 60, "height": 30})).unwrap()["id"].as_u64().unwrap();
|
||||
app.select_tool("selection");
|
||||
app.session.execute("select.set", &json!({"ids": [id]})).unwrap();
|
||||
let (from, to) = (xf.to_screen(Point::new(130.0, 115.0)), xf.to_screen(Point::new(170.0, 135.0)));
|
||||
app_step(&mut app, &ctx, vec![egui::Event::PointerMoved(from)]);
|
||||
for _ in 0..2 {
|
||||
app_step(&mut app, &ctx, vec![]);
|
||||
}
|
||||
let none = egui::Modifiers::NONE;
|
||||
let mut steps = vec![vec![primary(from, true, none)]];
|
||||
steps.extend((1..=8).map(|i| vec![egui::Event::PointerMoved(from.lerp(to, i as f32 / 8.0))]));
|
||||
steps.push(vec![primary(to, false, none)]);
|
||||
steps.extend([vec![], vec![], vec![]]);
|
||||
let mut rebuilt = vec![];
|
||||
for events in steps {
|
||||
let before = app.menus.rebuilds;
|
||||
app_step(&mut app, &ctx, events);
|
||||
rebuilt.push(app.menus.rebuilds - before);
|
||||
}
|
||||
assert_eq!(drawn_paths(&app), vec![Rect::new(140.0, 120.0, 200.0, 150.0)], "the drag moves the rectangle");
|
||||
assert_eq!(rebuilt, [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], "rebuilds in each frame: press, 8 moves, release, 3 idle");
|
||||
}
|
||||
|
||||
/// #6369: only the selection box remains over the temporary halftone, and the original
|
||||
/// selection's outlines come back when Preview is turned off or the dialog is cancelled.
|
||||
#[test]
|
||||
|
||||
@@ -89,8 +89,8 @@ pub(crate) fn translate_label(english: &'static str) -> String {
|
||||
/// button pressed or released or a key pressed ([`last_press`]), changes once for each, which covers what the hash
|
||||
/// doesn't list (panels shown, a tool picked). While an
|
||||
/// interaction is open (for example a move, scale or shape drag, a dialog's or the font menu's
|
||||
/// preview, or a typing session), the revision, which each of its previews changes, is left out:
|
||||
/// the hash changes as the interaction begins and as it ends.
|
||||
/// preview, or a typing session), the hash takes the revision the interaction began from in place of the current one,
|
||||
/// which each of its previews changes: the hash stays the same as the interaction begins, and changes as it ends.
|
||||
pub(crate) fn state_key(app: &VectorcraftApp, input: Option<u64>) -> u64 {
|
||||
let mut h = DefaultHasher::new();
|
||||
input.hash(&mut h);
|
||||
@@ -101,7 +101,7 @@ pub(crate) fn state_key(app: &VectorcraftApp, input: Option<u64>) -> u64 {
|
||||
let s = &app.session;
|
||||
(s.journal.len(), s.active_index(), s.clipboard.is_empty(), s.tool_composing()).hash(&mut h);
|
||||
if let Some(d) = s.active() {
|
||||
let revision = d.interaction.is_none().then_some(d.revision);
|
||||
let revision = d.interaction.as_ref().map_or(d.revision, |it| it.revision);
|
||||
(d.uid, revision, d.history.undo.len(), d.history.redo.len(), d.transparency_grid, d.print_tiling).hash(&mut h);
|
||||
}
|
||||
(app.system_paste, app.last_effect.is_some(), app.ui.recent_files.len(), app.ui.recent_files.first(), app.recent_fonts().len()).hash(&mut h);
|
||||
|
||||
Reference in new issue
Block a user