[glass] Add hamburger menu icon to titlebars (#4874)

This does the same thing as right clicking, but provides a visual indicator.
The icon disappears if the window is too small or docked (right click keeps working).
This commit is contained in:
ohowe
2023-01-01 21:05:09 -07:00
committed by GitHub
parent f0fa8205ac
commit b0c6724eed
16 changed files with 254 additions and 100 deletions

View File

@@ -4,6 +4,8 @@
#include "glass/support/ExtraGuiWidgets.h"
#include <imgui.h>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui_internal.h>
@@ -174,4 +176,46 @@ bool HeaderDeleteButton(const char* label) {
return rv;
}
bool HamburgerButton(const ImGuiID id, const ImVec2 position) {
const ImGuiStyle& style = ImGui::GetStyle();
ImGuiWindow* window = ImGui::GetCurrentWindow();
// Frame padding on both sides, then one character in the middle
const ImRect bb{
position, position + ImVec2(ImGui::GetFontSize(), ImGui::GetFontSize()) +
style.FramePadding * 2.0f};
ImGui::ItemAdd(bb, id);
bool hovered, held;
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held);
const ImU32 bgCol =
ImGui::GetColorU32(held ? ImGuiCol_ButtonActive : ImGuiCol_ButtonHovered);
const ImVec2 center = bb.GetCenter();
if (hovered) {
window->DrawList->AddCircleFilled(
center, ImMax(2.0f, ImGui::GetFontSize() * 0.5f + 1.0f), bgCol, 12);
}
const ImU32 fgCol = ImGui::GetColorU32(ImGuiCol_Text);
const float halfLineWidth = ImGui::GetFontSize() * 0.5 * 0.7071;
const float halfTotalHeight = halfLineWidth * 0.875;
ImVec2 lineStart = {center.x - halfLineWidth, center.y - halfTotalHeight};
ImVec2 lineEnd = {center.x + halfLineWidth, center.y - halfTotalHeight};
ImVec2 increment = {0.0, halfTotalHeight};
for (int i = 0; i < 3; i++) {
window->DrawList->AddLine(lineStart, lineEnd, fgCol);
lineStart += increment;
lineEnd += increment;
}
return pressed;
}
} // namespace glass