Viewer: a locked viewer keeps its comp when the Project panel opens another (#156)

The Project panel (like other panels) runs comp.open while it draws, so the
new comp became the active comp mid-frame. Later in the same frame the
active, locked viewer drew and recorded the active comp as its own. On the
next frame on_open_comp compared that record with the opened comp, found
them equal and skipped the lock, so the locked viewer switched comps.

The active viewer no longer records its comp while an OpenComp event is
pending (it asks for a repaint instead); on_open_comp then sees the comp
the locked viewer really shows and routes the new one to an unlocked or
new viewer.

The viewers test's click helper now releases a frame after the press, as
a hand does: a press in a tab strip focuses the shown panel first, and a
same-frame press and release refocused it after the tab's own click.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-07 13:44:46 +07:00
co-authored by Claude Opus 5.5
parent 72b039c6d5
commit 254e895316
2 changed files with 63 additions and 10 deletions
+8 -2
View File
@@ -73,8 +73,14 @@ pub fn comp_of(app: &EffectcraftApp, id: u32) -> Option<ItemId> {
/// becomes the active viewer when clicked.
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, id: u32, rect: Rect) {
if id == app.ui.active_viewer {
let c = app.session.active_comp_id().map(|c| c.0);
app.ui.viewers.insert(id, c);
// A comp opened earlier this frame (the Project panel) is routed next frame by
// `on_open_comp`, which needs the comp this viewer showed (to keep it when locked).
if app.session.events.iter().any(|e| matches!(e, effectcraft_engine::Event::OpenComp(_))) {
ui.ctx().request_repaint();
} else {
let c = app.session.active_comp_id().map(|c| c.0);
app.ui.viewers.insert(id, c);
}
super::viewer::show(app, ui, rect);
return;
}