From 33e9ad7775e7be9d2a3c5a8c6e1b7791ce6ef8ff Mon Sep 17 00:00:00 2001 From: Justus Garbe Date: Sun, 13 Aug 2023 23:54:22 +0200 Subject: [PATCH] fix: Draw title bar correctly when no title bar buttons exist --- main/source/window/window.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index 466cb8a7b..506352e0a 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -258,12 +258,14 @@ namespace hex { auto &titleBarButtons = ContentRegistry::Interface::impl::getTitleBarButtons(); // Draw custom title bar buttons - ImGui::SetCursorPosX(ImGui::GetWindowWidth() - buttonSize.x * (4 + titleBarButtons.size())); - for (const auto &[icon, tooltip, callback] : titleBarButtons) { - if (ImGui::TitleBarButton(icon.c_str(), buttonSize)) { - callback(); + if(!titleBarButtons.empty()) { + ImGui::SetCursorPosX(ImGui::GetWindowWidth() - buttonSize.x * (4 + titleBarButtons.size())); + for (const auto &[icon, tooltip, callback]: titleBarButtons) { + if (ImGui::TitleBarButton(icon.c_str(), buttonSize)) { + callback(); + } + ImGui::InfoTooltip(LangEntry(tooltip)); } - ImGui::InfoTooltip(LangEntry(tooltip)); } // Draw minimize, restore and maximize buttons @@ -306,12 +308,14 @@ namespace hex { auto &titleBarButtons = ContentRegistry::Interface::impl::getTitleBarButtons(); // Draw custom title bar buttons - ImGui::SetCursorPosX(ImGui::GetWindowWidth() - buttonSize.x * (titleBarButtons.size()+0.5)); - for (const auto &[icon, tooltip, callback] : titleBarButtons) { - if (ImGui::TitleBarButton(icon.c_str(), buttonSize)) { - callback(); + if(!titleBarButtons.empty()) { + ImGui::SetCursorPosX(ImGui::GetWindowWidth() - buttonSize.x * (titleBarButtons.size() + 0.5)); + for (const auto &[icon, tooltip, callback]: titleBarButtons) { + if (ImGui::TitleBarButton(icon.c_str(), buttonSize)) { + callback(); + } + ImGui::InfoTooltip(LangEntry(tooltip)); } - ImGui::InfoTooltip(LangEntry(tooltip)); } ImGui::PopStyleColor(3);