Merge outside PR #222 (jayzed80): a click on the playhead and the frame keys (M8)

This commit is contained in:
Tanish Manku committed 2026-11-23 17:14:03 -07:00
commit bfdb361d0c
2 files changed
+81 -4

No files matched your search

+6 -4
View File
@@ -202,10 +202,10 @@ As in Animate, the keys keep you moving along the timeline:
* **F6** or **F7** on a frame that is already a keyframe adds the new keyframe on the *next*
frame and moves there, so you can draw, press **F6**, draw again, and so on. On any other
frame they key the frame you're on.
* With no frames selected (for example after scrubbing the playhead), **F5** adds a frame on
every layer that has frames at or after the playhead, so the layers stay in step. Layers that
end before the playhead are left alone. When no layer reaches the playhead, it lengthens the
layer you're on up to it.
* With no frames selected (for example after stepping the playhead out of the selection),
**F5** adds a frame on every layer that has frames at or after the playhead, so the layers
stay in step. Layers that end before the playhead are left alone. When no layer reaches the
playhead, it lengthens the layer you're on up to it.
* With a frame selected, the keys act on that frame's layer, and the selection moves with the
playhead.
* With several frames selected, **F6** makes every one of them a keyframe of what it showed, and
@@ -220,6 +220,8 @@ An empty frame shows a hint in **Properties › Frame**: press **F7** to start d
* Click a frame to select it and move the playhead there.
* **Shift**-click, or drag across frames, to select a range. A selection can span several
layers.
* Click the playhead (the frame ruler) to select that frame on every layer. **F5**, **F6**
and the other frame keys then act on all layers, until you click a frame of one layer.
* **Ctrl+Alt+A** selects every frame.
The frame keys, the header buttons and the right-click menu all act on the whole selection.
+75
View File
@@ -681,6 +681,15 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
&& let Some(p) = ruler_resp.interact_pointer_pos() {
app.playing = false;
app.run("timeline.goto", json!({"frame": playhead_target(frame_at(p.x), app.s.frame_count())}));
// The playhead's frame on every layer, as in Animate: F5, F6, Shift+F5 and the
// other frame commands then act on all layers until a frame of one layer is clicked.
let layers = &app.s.timeline().layers;
if let (Some(a), Some(b)) = (layers.first(), layers.last()) {
app.frame_sel = Some(FrameSel { anchor: (a.id, app.s.frame), head: (b.id, app.s.frame) });
}
// Keyboard focus follows the click, as it does on a frame: Ctrl+X/C/V then act on
// the selected frames, not on artwork.
app.timeline_focus = true;
}
// The onion menu on a right-click, as the markers live here (ADR 0047).
ruler_resp.context_menu(|ui| crate::onion::menu(app, ui));
@@ -2315,6 +2324,72 @@ mod tests {
assert!(FrameSel { anchor: (LayerId(9), 0), head: (LayerId(1), 0) }.layers(&ls).is_empty());
}
/// Each layer's length, in frames.
fn ends(app: &App) -> Vec<(LayerId, u32)> {
app.s.timeline().layers.iter().map(|l| (l.id, l.end_frame())).collect()
}
/// Issue 195: a click on the playhead (the frame ruler) picks that frame on every layer, so
/// F5 adds a frame to all of them; a click on one layer's frame goes back to that layer.
#[test]
fn a_click_on_the_playhead_makes_frame_keys_act_on_every_layer() {
let ctx = egui::Context::default();
ctx.enable_accesskit();
let mut app = App::with_context(&ctx, anicraft_engine::Session::new(anicraft_engine::doc::sample::demo()), Some(std::path::PathBuf::from("unused.png")));
let screen = Rect::from_min_size(egui::Pos2::ZERO, vec2(1600.0, 940.0) / app.prefs.ui_scale);
let frame = |app: &mut App, events: Vec<egui::Event>| {
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| app.frame(ui));
out.textures_delta.clear();
out.platform_output.accesskit_update
};
let mut tree = None;
for _ in 0..3 {
tree = frame(&mut app, Vec::new()).or(tree);
}
let layers: Vec<LayerId> = app.s.timeline().layers.iter().filter(|l| l.kind != LayerKind::Folder).map(|l| l.id).collect();
assert!(layers.len() >= 2, "the sample has several layers: {layers:?}");
// The second layer is the active one, as after a click on its name.
app.s.layer = layers[1];
// The frame ruler, found by its name for screen readers.
let ppp = ctx.pixels_per_point();
let ruler = tree
.and_then(|t| t.nodes.into_iter().find(|(_, n)| n.label() == Some("Playhead (frame ruler)")))
.and_then(|(_, n)| n.bounds())
.map(|b| Rect::from_min_max(pos2(b.x0 as f32, b.y0 as f32) / ppp, pos2(b.x1 as f32, b.y1 as f32) / ppp))
.unwrap_or_else(|| panic!("no frame ruler on screen"));
// Click the ruler a little way in (frame 3 or so).
let at = pos2(ruler.left() + 40.0, ruler.center().y);
let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE };
frame(&mut app, vec![egui::Event::PointerMoved(at)]);
frame(&mut app, vec![press(true)]);
frame(&mut app, vec![press(false)]);
frame(&mut app, Vec::new());
// The click takes the keyboard focus to the timeline, as a click on a frame does, so
// Ctrl+C copies the selected frames rather than artwork.
assert!(app.timeline_focus, "a click on the ruler focuses the timeline");
app.invoke("edit.copy");
assert!(!app.s.frame_clipboard.is_empty(), "Ctrl+C after a click on the ruler copies frames");
let f = app.s.frame;
assert!(f > 0, "the click moved the playhead");
let before = ends(&app);
let steps = app.s.history_len();
app.invoke("timeline.insert_frame");
assert_eq!(app.s.history_len(), steps + 1, "one undo step");
// The same as F5 on every layer at the playhead.
let all = ends(&app);
app.s.undo().expect("undo");
assert_eq!(ends(&app), before, "one undo takes it all back");
app.run("timeline.insert_frame", json!({"layers": layers.iter().map(|l| l.0).collect::<Vec<_>>(), "frame": f}));
assert_eq!(all, ends(&app), "F5 after a click on the playhead adds a frame on every layer");
app.s.undo().expect("undo");
assert!(before.iter().zip(&all).filter(|(b, a)| b != a).count() >= 2, "more than one layer grew: {before:?} → {all:?}");
// A click on one layer's frame (what the grid does) acts on that layer only again.
app.frame_sel = Some(FrameSel::cell(layers[1], f));
app.invoke("timeline.insert_frame");
let one = ends(&app);
assert_eq!(before.iter().zip(&one).filter(|(b, a)| b != a).map(|(b, _)| b.0).collect::<Vec<_>>(), vec![layers[1]]);
}
use egui::{Event, Modifiers, PointerButton, Pos2};
/// One frame of the whole app with these events; the cursor it asked for.