Skip to content

Commit

Permalink
fix: ID collision with multiple banners on screen
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jan 17, 2025
1 parent a1d8cbd commit 56c4f2a
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions main/gui/source/window/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,36 +571,32 @@ namespace hex {
#endif

for (const auto &banner : impl::BannerBase::getOpenBanners() | std::views::take(5)) {
ImGui::PushID(banner.get());
{
auto &style = ImGui::GetStyle();
ImGui::SetNextWindowPos(ImVec2(windowPos.x + 1_scaled, startY));
ImGui::SetNextWindowSize(ImVec2(ImHexApi::System::getMainWindowSize().x - 2_scaled, height));
ImGui::PushStyleColor(ImGuiCol_WindowBg, banner->getColor().Value);
auto prevShadowOffset = style.WindowShadowOffsetDist;
auto prevShadowAngle = style.WindowShadowOffsetAngle;
style.WindowShadowOffsetDist = 12_scaled;
style.WindowShadowOffsetAngle = 0.5 * std::numbers::pi;
ON_SCOPE_EXIT {
style.WindowShadowOffsetDist = prevShadowOffset;
style.WindowShadowOffsetAngle = prevShadowAngle;
};
if (ImGui::Begin("##Banner", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing)) {
if (ImGui::BeginChild("##Content", ImGui::GetContentRegionAvail() - ImVec2(20_scaled, 0))) {
banner->draw();
}
ImGui::EndChild();
auto &style = ImGui::GetStyle();
ImGui::SetNextWindowPos(ImVec2(windowPos.x + 1_scaled, startY));
ImGui::SetNextWindowSize(ImVec2(ImHexApi::System::getMainWindowSize().x - 2_scaled, height));
ImGui::PushStyleColor(ImGuiCol_WindowBg, banner->getColor().Value);
auto prevShadowOffset = style.WindowShadowOffsetDist;
auto prevShadowAngle = style.WindowShadowOffsetAngle;
style.WindowShadowOffsetDist = 12_scaled;
style.WindowShadowOffsetAngle = 0.5 * std::numbers::pi;
ON_SCOPE_EXIT {
style.WindowShadowOffsetDist = prevShadowOffset;
style.WindowShadowOffsetAngle = prevShadowAngle;
};
if (ImGui::Begin(fmt::format("##Banner{}", static_cast<void*>(banner.get())).c_str(), nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing)) {
if (ImGui::BeginChild("##Content", ImGui::GetContentRegionAvail() - ImVec2(20_scaled, 0))) {
banner->draw();
}
ImGui::EndChild();

ImGui::SameLine();
ImGui::SameLine();

if (ImGui::CloseButton(ImGui::GetID("BannerCloseButton"), ImGui::GetCursorScreenPos())) {
banner->close();
}
if (ImGui::CloseButton(ImGui::GetID("BannerCloseButton"), ImGui::GetCursorScreenPos())) {
banner->close();
}
ImGui::End();
ImGui::PopStyleColor();
}
ImGui::PopID();
ImGui::End();
ImGui::PopStyleColor();

startY += height;
}
Expand Down

0 comments on commit 56c4f2a

Please sign in to comment.