Skip to content

Commit

Permalink
fix: Draw title bar correctly when no title bar buttons exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jumanji144 committed Aug 13, 2023
1 parent 2059ad8 commit 33e9ad7
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions main/source/window/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 33e9ad7

Please sign in to comment.