141 lines
4.2 KiB
C++
141 lines
4.2 KiB
C++
#include "XCUIDemoPanel.h"
|
|
|
|
#include "UI/UI.h"
|
|
|
|
#include <XCEngine/UI/DrawData.h>
|
|
|
|
#include <imgui.h>
|
|
|
|
namespace {
|
|
|
|
::XCEngine::UI::UIDrawList BuildXCUIDemoDrawList(
|
|
const ImVec2& canvasMin,
|
|
const ImVec2& canvasSize) {
|
|
using ::XCEngine::UI::UIColor;
|
|
using ::XCEngine::UI::UIDrawList;
|
|
using ::XCEngine::UI::UIPoint;
|
|
using ::XCEngine::UI::UIRect;
|
|
|
|
UIDrawList drawList("XCUI Transition Demo");
|
|
drawList.PushClipRect(UIRect(canvasMin.x, canvasMin.y, canvasSize.x, canvasSize.y));
|
|
drawList.AddFilledRect(
|
|
UIRect(canvasMin.x, canvasMin.y, canvasSize.x, canvasSize.y),
|
|
UIColor(0.09f, 0.11f, 0.14f, 1.0f),
|
|
10.0f);
|
|
drawList.AddRectOutline(
|
|
UIRect(canvasMin.x, canvasMin.y, canvasSize.x, canvasSize.y),
|
|
UIColor(0.32f, 0.40f, 0.49f, 1.0f),
|
|
1.0f,
|
|
10.0f);
|
|
|
|
const float cardX = canvasMin.x + 18.0f;
|
|
const float cardY = canvasMin.y + 18.0f;
|
|
const float cardWidth = (canvasSize.x - 36.0f) > 120.0f ? (canvasSize.x - 36.0f) : 120.0f;
|
|
drawList.AddFilledRect(
|
|
UIRect(cardX, cardY, cardWidth, 56.0f),
|
|
UIColor(0.15f, 0.20f, 0.27f, 1.0f),
|
|
8.0f);
|
|
drawList.AddFilledRect(
|
|
UIRect(cardX + 14.0f, cardY + 16.0f, 10.0f, 10.0f),
|
|
UIColor(0.18f, 0.76f, 0.58f, 1.0f),
|
|
5.0f);
|
|
drawList.AddText(
|
|
UIPoint(cardX + 32.0f, cardY + 12.0f),
|
|
"XCUI Transition Backend",
|
|
UIColor(0.96f, 0.97f, 0.99f, 1.0f),
|
|
18.0f);
|
|
drawList.AddText(
|
|
UIPoint(cardX + 32.0f, cardY + 33.0f),
|
|
"This panel is generated by XCUI draw commands, then flushed through ImGui.",
|
|
UIColor(0.74f, 0.79f, 0.86f, 1.0f),
|
|
13.0f);
|
|
|
|
const float statY = cardY + 76.0f;
|
|
drawList.AddFilledRect(
|
|
UIRect(cardX, statY, 140.0f, 74.0f),
|
|
UIColor(0.11f, 0.16f, 0.22f, 1.0f),
|
|
8.0f);
|
|
drawList.AddFilledRect(
|
|
UIRect(cardX + 158.0f, statY, 180.0f, 74.0f),
|
|
UIColor(0.11f, 0.16f, 0.22f, 1.0f),
|
|
8.0f);
|
|
drawList.AddText(
|
|
UIPoint(cardX + 14.0f, statY + 12.0f),
|
|
"Primitive Set",
|
|
UIColor(0.68f, 0.75f, 0.84f, 1.0f),
|
|
13.0f);
|
|
drawList.AddText(
|
|
UIPoint(cardX + 14.0f, statY + 36.0f),
|
|
"Rect / Border / Text / Image",
|
|
UIColor(0.95f, 0.97f, 0.99f, 1.0f),
|
|
15.0f);
|
|
drawList.AddText(
|
|
UIPoint(cardX + 172.0f, statY + 12.0f),
|
|
"Backend Flow",
|
|
UIColor(0.68f, 0.75f, 0.84f, 1.0f),
|
|
13.0f);
|
|
drawList.AddText(
|
|
UIPoint(cardX + 172.0f, statY + 36.0f),
|
|
"UIDrawList -> ImGuiTransitionBackend -> ImDrawList",
|
|
UIColor(0.95f, 0.97f, 0.99f, 1.0f),
|
|
15.0f);
|
|
|
|
const float footerY = canvasMin.y + canvasSize.y - 54.0f;
|
|
if (footerY > statY + 90.0f) {
|
|
drawList.AddFilledRect(
|
|
UIRect(cardX, footerY, cardWidth, 36.0f),
|
|
UIColor(0.14f, 0.17f, 0.22f, 1.0f),
|
|
8.0f);
|
|
drawList.AddText(
|
|
UIPoint(cardX + 14.0f, footerY + 10.0f),
|
|
"Subplan-05 MVP: XCUI owns draw data, ImGui is only the transition renderer.",
|
|
UIColor(0.79f, 0.84f, 0.90f, 1.0f),
|
|
13.0f);
|
|
}
|
|
|
|
drawList.PopClipRect();
|
|
return drawList;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace XCEngine {
|
|
namespace Editor {
|
|
|
|
XCUIDemoPanel::XCUIDemoPanel()
|
|
: Panel("XCUI Demo") {
|
|
}
|
|
|
|
void XCUIDemoPanel::Render() {
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
|
UI::PanelWindowScope panel(m_name.c_str());
|
|
ImGui::PopStyleVar();
|
|
if (!panel.IsOpen()) {
|
|
return;
|
|
}
|
|
|
|
UI::PanelContentScope content("XCUIDemoContent", ImVec2(0.0f, 0.0f));
|
|
if (!content.IsOpen()) {
|
|
return;
|
|
}
|
|
|
|
const ImVec2 availableSize = ImGui::GetContentRegionAvail();
|
|
if (availableSize.x <= 1.0f || availableSize.y <= 1.0f) {
|
|
ImGui::Dummy(ImVec2(0.0f, 0.0f));
|
|
return;
|
|
}
|
|
|
|
const ImVec2 canvasMin = ImGui::GetCursorScreenPos();
|
|
ImGui::InvisibleButton("##XCUIDemoCanvas", availableSize);
|
|
|
|
::XCEngine::UI::UIDrawData drawData = {};
|
|
drawData.AddDrawList(BuildXCUIDemoDrawList(canvasMin, availableSize));
|
|
|
|
m_backend.BeginFrame();
|
|
m_backend.Submit(drawData);
|
|
m_backend.EndFrame(ImGui::GetWindowDrawList());
|
|
}
|
|
|
|
} // namespace Editor
|
|
} // namespace XCEngine
|