mirror of
https://github.com/barkeser2002/flower.git
synced 2026-09-25 17:16:14 +03:00
146 lines
4.9 KiB
C++
146 lines
4.9 KiB
C++
#include "ImGuiExtension.h"
|
|
#include "ImGuiInternal.h"
|
|
|
|
#include <stb/stb_image.h>
|
|
#include <glfw/glfw3.h>
|
|
|
|
namespace ImGui
|
|
{
|
|
struct IconContext
|
|
{
|
|
GLFWimage images[1];
|
|
IconContext()
|
|
{
|
|
images[0].pixels = stbi_load("Image/AppIcon.png", &images[0].width, &images[0].height, 0, 4);
|
|
}
|
|
~IconContext()
|
|
{
|
|
stbi_image_free(images[0].pixels);
|
|
}
|
|
};
|
|
IconContext GIconContext{ };
|
|
|
|
void ImGui::setWindowIcon(GLFWwindow* window)
|
|
{
|
|
glfwSetWindowIcon(window, 1, GIconContext.images);
|
|
}
|
|
|
|
static ImVector<ImRect> s_GroupPanelLabelStack;
|
|
|
|
void ImGui::BeginGroupPanel(const char* name, const ImVec2& size)
|
|
{
|
|
ImGui::BeginGroup();
|
|
|
|
|
|
auto cursorPos = ImGui::GetCursorScreenPos();
|
|
auto itemSpacing = ImGui::GetStyle().ItemSpacing;
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
|
|
|
|
auto frameHeight = ImGui::GetFrameHeight();
|
|
ImGui::BeginGroup();
|
|
|
|
ImVec2 effectiveSize = size;
|
|
if (size.x < 0.0f)
|
|
effectiveSize.x = ImGui::GetContentRegionAvail().x;
|
|
else
|
|
effectiveSize.x = size.x;
|
|
ImGui::Dummy(ImVec2(effectiveSize.x, 0.0f));
|
|
|
|
ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f));
|
|
ImGui::SameLine(0.0f, 0.0f);
|
|
ImGui::BeginGroup();
|
|
ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f));
|
|
ImGui::SameLine(0.0f, 0.0f);
|
|
ImGui::TextUnformatted(name);
|
|
auto labelMin = ImGui::GetItemRectMin();
|
|
auto labelMax = ImGui::GetItemRectMax();
|
|
ImGui::SameLine(0.0f, 0.0f);
|
|
ImGui::Dummy(ImVec2(0.0, frameHeight + itemSpacing.y));
|
|
ImGui::BeginGroup();
|
|
|
|
//ImGui::GetWindowDrawList()->AddRect(labelMin, labelMax, IM_COL32(255, 0, 255, 255));
|
|
|
|
ImGui::PopStyleVar(2);
|
|
|
|
ImGui::GetCurrentWindow()->ContentRegionRect.Max.x -= frameHeight * 0.5f;
|
|
ImGui::GetCurrentWindow()->WorkRect.Max.x -= frameHeight * 0.5f;
|
|
ImGui::GetCurrentWindow()->InnerRect.Max.x -= frameHeight * 0.5f;
|
|
ImGui::GetCurrentWindow()->Size.x -= frameHeight;
|
|
|
|
auto itemWidth = ImGui::CalcItemWidth();
|
|
ImGui::PushItemWidth(ImMax(0.0f, itemWidth - frameHeight));
|
|
|
|
s_GroupPanelLabelStack.push_back(ImRect(labelMin, labelMax));
|
|
}
|
|
|
|
void ImGui::EndGroupPanel()
|
|
{
|
|
ImGui::PopItemWidth();
|
|
|
|
auto itemSpacing = ImGui::GetStyle().ItemSpacing;
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f));
|
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
|
|
|
|
auto frameHeight = ImGui::GetFrameHeight();
|
|
|
|
ImGui::EndGroup();
|
|
|
|
//ImGui::GetWindowDrawList()->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), IM_COL32(0, 255, 0, 64), 4.0f);
|
|
|
|
ImGui::EndGroup();
|
|
|
|
ImGui::SameLine(0.0f, 0.0f);
|
|
ImGui::Dummy(ImVec2(frameHeight * 0.5f, 0.0f));
|
|
ImGui::Dummy(ImVec2(0.0, frameHeight - frameHeight * 0.5f - itemSpacing.y));
|
|
|
|
ImGui::EndGroup();
|
|
|
|
auto itemMin = ImGui::GetItemRectMin();
|
|
auto itemMax = ImGui::GetItemRectMax();
|
|
//ImGui::GetWindowDrawList()->AddRectFilled(itemMin, itemMax, IM_COL32(255, 0, 0, 64), 4.0f);
|
|
|
|
auto labelRect = s_GroupPanelLabelStack.back();
|
|
s_GroupPanelLabelStack.pop_back();
|
|
|
|
ImVec2 halfFrame = ImVec2(frameHeight * 0.25f * 0.5f, frameHeight * 0.5f);
|
|
ImRect frameRect = ImRect(
|
|
ImVec2{ itemMin.x + halfFrame.x, itemMin.y + halfFrame.y },
|
|
ImVec2{ itemMax.x - halfFrame.x, itemMax.y });
|
|
labelRect.Min.x -= itemSpacing.x;
|
|
labelRect.Max.x += itemSpacing.x;
|
|
for (int i = 0; i < 4; ++i)
|
|
{
|
|
switch (i)
|
|
{
|
|
// left half-plane
|
|
case 0: ImGui::PushClipRect(ImVec2(-FLT_MAX, -FLT_MAX), ImVec2(labelRect.Min.x, FLT_MAX), true); break;
|
|
// right half-plane
|
|
case 1: ImGui::PushClipRect(ImVec2(labelRect.Max.x, -FLT_MAX), ImVec2(FLT_MAX, FLT_MAX), true); break;
|
|
// top
|
|
case 2: ImGui::PushClipRect(ImVec2(labelRect.Min.x, -FLT_MAX), ImVec2(labelRect.Max.x, labelRect.Min.y), true); break;
|
|
// bottom
|
|
case 3: ImGui::PushClipRect(ImVec2(labelRect.Min.x, labelRect.Max.y), ImVec2(labelRect.Max.x, FLT_MAX), true); break;
|
|
}
|
|
|
|
ImGui::GetWindowDrawList()->AddRect(
|
|
frameRect.Min, frameRect.Max,
|
|
ImColor(ImGui::GetStyleColorVec4(ImGuiCol_Border)),
|
|
halfFrame.x);
|
|
|
|
ImGui::PopClipRect();
|
|
}
|
|
|
|
ImGui::PopStyleVar(2);
|
|
|
|
ImGui::GetCurrentWindow()->ContentRegionRect.Max.x += frameHeight * 0.5f;
|
|
ImGui::GetCurrentWindow()->WorkRect.Max.x += frameHeight * 0.5f;
|
|
ImGui::GetCurrentWindow()->InnerRect.Max.x += frameHeight * 0.5f;
|
|
ImGui::GetCurrentWindow()->Size.x += frameHeight;
|
|
|
|
ImGui::Dummy(ImVec2(0.0f, 0.0f));
|
|
|
|
ImGui::EndGroup();
|
|
}
|
|
} |