Skip to content

Commit

Permalink
feat: Refactor ImGuiAppExtension's onRender to onUpdate
Browse files Browse the repository at this point in the history
The onRender method in ImGuiAppExtension has been refactored as an onUpdate method to handle changes over time rather than frame-by-frame. Now, each window in the application iterates through specific ImGuiContextWrapper updates. This change ensures more efficient and reliable context updates for every window in the application.
  • Loading branch information
Anonymous committed Feb 26, 2024
1 parent d497af8 commit b143412
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion big2/include/big2/imgui/imgui_app_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ImGuiAppExtension final : public AppExtensionBase {
protected:
void OnWindowCreated(Window& window) override;
void OnWindowDestroyed(Window& window) override;
void OnRender(Window& window) override;
void OnUpdate(std::float_t dt) override;

private:
std::vector<ImGuiContextWrapper> contexts_;
Expand Down
24 changes: 13 additions & 11 deletions big2/src/imgui/imgui_app_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,22 @@ void ImGuiAppExtension::OnWindowDestroyed(Window& window) {
});
}

void ImGuiAppExtension::OnRender(Window& window) {
AppExtensionBase::OnRender(window);
void ImGuiAppExtension::OnUpdate(std::float_t dt) {
AppExtensionBase::OnUpdate(dt);

std::optional<ImGuiContextWrapper> maybe_context = big2::FirstIf<ImGuiContextWrapper>(contexts_.begin(), contexts_.end(), [&window](ImGuiContextWrapper& context) {
return context.GetWindow() == window.GetWindowHandle();
});
for(Window& window : app_->GetWindows()) {
std::optional<ImGuiContextWrapper> maybe_context = big2::FirstIf<ImGuiContextWrapper>(contexts_.begin(), contexts_.end(), [&window](ImGuiContextWrapper& context) {
return context.GetWindow() == window.GetWindowHandle();
});

if(!maybe_context.has_value())
{
return;
}
if(!maybe_context.has_value())
{
return;
}

ImGui::SetCurrentContext(maybe_context.value().GetContext());
big2::GlfwEventQueue::UpdateImGuiEvents(window.GetWindowHandle());
ImGui::SetCurrentContext(maybe_context.value().GetContext());
big2::GlfwEventQueue::UpdateImGuiEvents(window.GetWindowHandle());
}
}

}
Expand Down

0 comments on commit b143412

Please sign in to comment.