Timeline: per-frame work runs once, not once per row

Escape, the context menu (and its shortcuts), frame resize drags and the
frame-move drop now run once from frames_child instead of inside every
row's child. draw() hands popups and global shortcuts to popups_update()
and shortcuts_update(). Drops a dead style push/pop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 19:01:40 -04:00
1 parent 146e5d4ff1
commit 69e78ff77a
6 files changed
+63 -50

No files matched your search

+4 -2
View File
@@ -77,10 +77,12 @@ namespace anm2ed::imgui
} }
} }
bool actions_context_window_draw(const char* label, Actions& actions, Settings& settings, ImGuiPopupFlags flags) bool actions_context_window_draw(const char* label, Actions& actions, Settings& settings, ImGuiPopupFlags flags,
ImGuiHoveredFlags hoveredFlags)
{ {
auto mouseButton = flags & ImGuiPopupFlags_MouseButtonMask_; auto mouseButton = flags & ImGuiPopupFlags_MouseButtonMask_;
if (ImGui::IsMouseReleased(mouseButton) && ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup)) if (ImGui::IsMouseReleased(mouseButton) &&
ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | hoveredFlags))
if (!(flags & ImGuiPopupFlags_NoOpenOverItems) || !ImGui::IsAnyItemHovered()) ImGui::OpenPopup(label, flags); if (!(flags & ImGuiPopupFlags_NoOpenOverItems) || !ImGui::IsAnyItemHovered()) ImGui::OpenPopup(label, flags);
if (!ImGui::BeginPopup(label, ImGuiWindowFlags_NoMove)) return false; if (!ImGui::BeginPopup(label, ImGuiWindowFlags_NoMove)) return false;
+2 -1
View File
@@ -86,7 +86,8 @@ namespace anm2ed::imgui
int = ACTION_COUNT); int = ACTION_COUNT);
void actions_undo_redo_add(Actions&, Manager&, Document&); void actions_undo_redo_add(Actions&, Manager&, Document&);
void actions_menu_draw(Actions&, Settings&); void actions_menu_draw(Actions&, Settings&);
bool actions_context_window_draw(const char*, Actions&, Settings&, ImGuiPopupFlags = ImGuiPopupFlags_MouseButtonRight); bool actions_context_window_draw(const char*, Actions&, Settings&, ImGuiPopupFlags = ImGuiPopupFlags_MouseButtonRight,
ImGuiHoveredFlags = ImGuiHoveredFlags_None);
bool actions_popup_draw(const char*, Actions&, Settings&); bool actions_popup_draw(const char*, Actions&, Settings&);
void actions_shortcuts_update(Actions&, Manager&, types::shortcut::Type = types::shortcut::FOCUSED); void actions_shortcuts_update(Actions&, Manager&, types::shortcut::Type = types::shortcut::FOCUSED);
void action_button_draw(Action&, Manager&, Settings&, ImVec2, bool&); void action_button_draw(Action&, Manager&, Settings&, ImVec2, bool&);
+3
View File
@@ -254,7 +254,10 @@ namespace anm2ed::imgui
ImVec2 frame_box_screen_point_get(ImVec2); ImVec2 frame_box_screen_point_get(ImVec2);
void frame_overlay_draw(ImDrawList*, ImVec2, ImVec2); void frame_overlay_draw(ImDrawList*, ImVec2, ImVec2);
void frame_child(const TimelineRow&, int&, float); void frame_child(const TimelineRow&, int&, float);
void frame_drag_update();
void frames_child(); void frames_child();
void popups_update();
void shortcuts_update();
void draw(); void draw();
}; };
} }
+36 -33
View File
@@ -107,11 +107,6 @@ namespace anm2ed::imgui
auto colorActiveHidden = to_imvec4(colorActiveVec * COLOR_HIDDEN_MULTIPLIER); auto colorActiveHidden = to_imvec4(colorActiveVec * COLOR_HIDDEN_MULTIPLIER);
auto colorHoveredHidden = to_imvec4(colorHoveredVec * COLOR_HIDDEN_MULTIPLIER); auto colorHoveredHidden = to_imvec4(colorHoveredVec * COLOR_HIDDEN_MULTIPLIER);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, style.WindowPadding);
ImGui::PopStyleVar(2);
ImGui::PushID(index); ImGui::PushID(index);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2()); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2());
@@ -161,19 +156,6 @@ namespace anm2ed::imgui
if (isFramesChildVisible) if (isFramesChildVisible)
{ {
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
ImGui::Shortcut(ImGuiKey_Escape, ImGuiInputFlags_RouteFocused))
{
if (!document.selection.uids[SelectionKind::FRAMES].empty())
{
reference_set(item_reference_from_frame_get(reference));
document.frame_references_clear();
}
else if (reference.itemType != NONE || reference.itemID != -1)
group_selection_reset_for(document);
document.focus_clear();
}
if (type == NONE) if (type == NONE)
{ {
if (length > 0) if (length > 0)
@@ -503,8 +485,24 @@ namespace anm2ed::imgui
} }
} }
if (isDraggedFrameActive) ImGui::EndChild();
if (isLightTheme && isDefaultChild) ImGui::PopStyleColor();
ImGui::PopStyleVar();
index++;
ImGui::PopID();
}
// Frame drags, once per frame after the rows: dropping moved frames, and resizing frames (or moving a trigger).
void TimelineContext::frame_drag_update()
{ {
if (frameMoveDrag.isActive && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
{
if (frameMoveDropTarget) frames_move_to(*frameMoveDropTarget);
frameMoveDrag = {};
}
if (!isDraggedFrameActive) return;
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand); ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
auto durationDelta = auto durationDelta =
draggedFrameWidth > 0.0f draggedFrameWidth > 0.0f
@@ -523,16 +521,15 @@ namespace anm2ed::imgui
auto targetReference = draggedFrameReference; auto targetReference = draggedFrameReference;
if (draggedFrameType == TRIGGER) if (draggedFrameType == TRIGGER)
{ {
auto atFrame = glm::clamp( auto atFrame = glm::clamp(hoveredTime, 0,
hoveredTime, 0, settings.playbackIsClamp && animation ? animation->frameNum - 1 : FRAME_NUM_MAX - 1); settings.playbackIsClamp && animation ? animation->frameNum - 1 : FRAME_NUM_MAX - 1);
command_push([=](Manager&, Document& document) command_push([=](Manager&, Document& document)
{ edit::trigger_at_frame_set(document.model, targetReference, atFrame); }); { edit::trigger_at_frame_set(document.model, targetReference, atFrame); });
} }
else else
{ {
std::map<Reference, int> durations{}; std::map<Reference, int> durations{};
if (draggedFrameStartDurations.empty()) if (draggedFrameStartDurations.empty()) durations[targetReference] = draggedFrameStartDuration + durationDelta;
durations[targetReference] = draggedFrameStartDuration + durationDelta;
for (auto frameDuration : draggedFrameStartDurations) for (auto frameDuration : draggedFrameStartDurations)
durations[frameDuration.reference] = frameDuration.duration + durationDelta; durations[frameDuration.reference] = frameDuration.duration + durationDelta;
command_push([=](Manager&, Document& document) { edit::frame_durations_set(document.model, durations); }); command_push([=](Manager&, Document& document) { edit::frame_durations_set(document.model, durations); });
@@ -562,16 +559,6 @@ namespace anm2ed::imgui
} }
} }
context_menu();
ImGui::EndChild();
if (isLightTheme && isDefaultChild) ImGui::PopStyleColor();
ImGui::PopStyleVar();
index++;
ImGui::PopID();
}
void TimelineContext::frames_child() void TimelineContext::frames_child()
{ {
auto cursorPos = ImGui::GetCursorPos(); auto cursorPos = ImGui::GetCursorPos();
@@ -612,6 +599,19 @@ namespace anm2ed::imgui
document.frame_references_set(document.selected_item_frame_references_get()); document.frame_references_set(document.selected_item_frame_references_get());
} }
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
ImGui::Shortcut(ImGuiKey_Escape, ImGuiInputFlags_RouteFocused))
{
if (!document.selection.uids[SelectionKind::FRAMES].empty())
{
reference_set(item_reference_from_frame_get(reference));
document.frame_references_clear();
}
else if (reference.itemType != NONE || reference.itemID != -1)
group_selection_reset_for(document);
document.focus_clear();
}
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2()); ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2());
if (ImGui::BeginTable("##Frames List Table", 1, if (ImGui::BeginTable("##Frames List Table", 1,
ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY))
@@ -696,6 +696,9 @@ namespace anm2ed::imgui
ImGui::EndTable(); ImGui::EndTable();
} }
frame_drag_update();
context_menu();
if (isFrameBoxClipSet) if (isFrameBoxClipSet)
{ {
auto overlayCursor = ImGui::GetCursorScreenPos(); auto overlayCursor = ImGui::GetCursorScreenPos();
+2 -1
View File
@@ -153,7 +153,8 @@ namespace anm2ed::imgui
actions.add(ACTION_CUT, [=, this]() { return !selectedFrames.empty(); }, [this]() { cut(); }); actions.add(ACTION_CUT, [=, this]() { return !selectedFrames.empty(); }, [this]() { cut(); });
actions.add(ACTION_COPY, [=, this]() { return !copyFrames.empty(); }, [this]() { copy(); }); actions.add(ACTION_COPY, [=, this]() { return !copyFrames.empty(); }, [this]() { copy(); });
actions.add(ACTION_PASTE, [&]() { return !clipboard.is_empty(); }, [this]() { paste(); }); actions.add(ACTION_PASTE, [&]() { return !clipboard.is_empty(); }, [this]() { paste(); });
actions_context_window_draw("##Context Menu", actions, settings); actions_context_window_draw("##Context Menu", actions, settings, ImGuiPopupFlags_MouseButtonRight,
ImGuiHoveredFlags_ChildWindows);
ImGui::PopStyleVar(2); ImGui::PopStyleVar(2);
} }
+16 -13
View File
@@ -47,11 +47,6 @@ namespace anm2ed::imgui
isWindowHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | isWindowHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows |
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem); ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);
frames_child(); frames_child();
if (frameMoveDrag.isActive && ImGui::IsMouseReleased(ImGuiMouseButton_Left))
{
if (frameMoveDropTarget) frames_move_to(*frameMoveDropTarget);
frameMoveDrag = {};
}
items_child(); items_child();
} }
ImGui::PopStyleVar(); ImGui::PopStyleVar();
@@ -60,6 +55,14 @@ namespace anm2ed::imgui
if (itemProperties.update(manager, settings, document, reference)) group_selection_reset_for(document); if (itemProperties.update(manager, settings, document, reference)) group_selection_reset_for(document);
group_properties_update(); group_properties_update();
popups_update();
shortcuts_update();
if (isTextPushed) ImGui::PopStyleColor();
}
void TimelineContext::popups_update()
{
makeManyRegionsPopup.trigger(); makeManyRegionsPopup.trigger();
if (ImGui::BeginPopupModal(makeManyRegionsPopup.label(), &makeManyRegionsPopup.isOpen, ImGuiWindowFlags_NoResize)) if (ImGui::BeginPopupModal(makeManyRegionsPopup.label(), &makeManyRegionsPopup.isOpen, ImGuiWindowFlags_NoResize))
{ {
@@ -174,9 +177,13 @@ namespace anm2ed::imgui
ImGui::EndPopup(); ImGui::EndPopup();
} }
}
if (animation) // Global timeline shortcuts: playback, playhead, frame resizing and frame/item navigation.
void TimelineContext::shortcuts_update()
{ {
if (!animation) return;
if (shortcut(manager.chords[SHORTCUT_PLAY_PAUSE], shortcut::GLOBAL)) playback.toggle(); if (shortcut(manager.chords[SHORTCUT_PLAY_PAUSE], shortcut::GLOBAL)) playback.toggle();
if (shortcut(manager.chords[SHORTCUT_MOVE_PLAYHEAD_BACK], shortcut::GLOBAL)) if (shortcut(manager.chords[SHORTCUT_MOVE_PLAYHEAD_BACK], shortcut::GLOBAL))
@@ -216,8 +223,7 @@ namespace anm2ed::imgui
{ {
for (auto frameReference : selectedFrames) for (auto frameReference : selectedFrames)
if (auto frame = document.model.frame_edit(frameReference)) if (auto frame = document.model.frame_edit(frameReference))
frame->duration = frame->duration = std::clamp(frame->duration + resize.delta, FRAME_DURATION_MIN, FRAME_DURATION_MAX);
std::clamp(frame->duration + resize.delta, FRAME_DURATION_MIN, FRAME_DURATION_MAX);
document.change(); document.change();
}); });
} }
@@ -233,8 +239,8 @@ namespace anm2ed::imgui
if (auto item = selected_item_get(); item && !item->frames.empty()) if (auto item = selected_item_get(); item && !item->frames.empty())
{ {
auto frameReference = reference; auto frameReference = reference;
frameReference.frameIndex = glm::clamp(reference.frameIndex + (int)isNextFrame - (int)isPreviousFrame, 0, frameReference.frameIndex =
(int)item->frames.size() - 1); glm::clamp(reference.frameIndex + (int)isNextFrame - (int)isPreviousFrame, 0, (int)item->frames.size() - 1);
reference_set(frameReference); reference_set(frameReference);
document.frame_focus_select(); document.frame_focus_select();
document.frameTime = model::frame_time_from_index_get(*item, reference.frameIndex); document.frameTime = model::frame_time_from_index_get(*item, reference.frameIndex);
@@ -243,7 +249,4 @@ namespace anm2ed::imgui
if (isPreviousItem) reference_set_adjacent_item(-1); if (isPreviousItem) reference_set_adjacent_item(-1);
if (isNextItem) reference_set_adjacent_item(1); if (isNextItem) reference_set_adjacent_item(1);
} }
if (isTextPushed) ImGui::PopStyleColor();
}
} }