engine: sync editor rendering and ui changes

This commit is contained in:
2026-04-08 16:09:15 +08:00
parent 31756847ab
commit 162f1cc12e
153 changed files with 4454 additions and 2990 deletions

View File

@@ -14,8 +14,17 @@ namespace XCEngine {
namespace Editor {
namespace UI {
inline bool ShouldTracePopupSubmenuLabel(const char* label) {
if (!label) {
return false;
}
const std::string text(label);
return text == "Create" || text == "3D Object";
}
inline void TracePopupSubmenuIfNeeded(const char* label, const std::string& message) {
if (!label || std::string(label) != "Create") {
if (!ShouldTracePopupSubmenuLabel(label)) {
return;
}
@@ -92,7 +101,7 @@ inline bool DrawMenuScope(const char* label, DrawContentFn&& drawContent) {
}
template <typename DrawContentFn>
inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent) {
inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent, bool enabled = true) {
if (!label || label[0] == '\0') {
return false;
}
@@ -103,18 +112,24 @@ inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent
const ImVec2 rowPos = ImGui::GetCursorScreenPos();
const float rowHeight = labelSize.y;
const float rowWidth = ImMax(ImGui::GetContentRegionAvail().x, 1.0f);
const bool popupOpen = ImGui::IsPopupOpen(popupId);
const bool popupOpen = enabled && ImGui::IsPopupOpen(popupId);
ImGuiSelectableFlags selectableFlags = ImGuiSelectableFlags_NoAutoClosePopups;
if (!enabled) {
selectableFlags |= ImGuiSelectableFlags_Disabled;
}
if (ImGui::Selectable(
"##PopupSubmenuRow",
popupOpen,
ImGuiSelectableFlags_NoAutoClosePopups,
selectableFlags,
ImVec2(rowWidth, rowHeight))) {
TracePopupSubmenuIfNeeded(label, "Hierarchy create submenu selectable clicked -> OpenPopup");
ImGui::OpenPopup(popupId);
if (enabled) {
TracePopupSubmenuIfNeeded(label, "Hierarchy create submenu selectable clicked -> OpenPopup");
ImGui::OpenPopup(popupId);
}
}
const bool hovered = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);
const bool hovered = enabled && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);
if (hovered && !popupOpen) {
TracePopupSubmenuIfNeeded(label, "Hierarchy create submenu hovered -> OpenPopup");
ImGui::OpenPopup(popupId);
@@ -127,9 +142,10 @@ inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent
const float parentWindowRight = parentWindowPos.x + parentWindowSize.x;
const float itemHeight = itemMax.y - itemMin.y;
ImDrawList* drawList = ImGui::GetWindowDrawList();
const ImU32 textColor = ImGui::GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled);
drawList->AddText(
ImVec2(itemMin.x + ImGui::GetStyle().FramePadding.x, itemMin.y + (itemHeight - labelSize.y) * 0.5f),
ImGui::GetColorU32(ImGuiCol_Text),
textColor,
label);
const float arrowExtent = PopupSubmenuArrowExtent();
@@ -139,7 +155,12 @@ inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent
ImVec2(arrowCenterX - arrowExtent * 0.30f, arrowCenterY - arrowExtent * 0.50f),
ImVec2(arrowCenterX - arrowExtent * 0.30f, arrowCenterY + arrowExtent * 0.50f),
ImVec2(arrowCenterX + arrowExtent * 0.50f, arrowCenterY),
ImGui::GetColorU32(ImGuiCol_Text));
textColor);
if (!enabled) {
ImGui::PopID();
return false;
}
ImGui::SetNextWindowPos(
ImVec2(parentWindowRight + PopupSubmenuOpenOffsetX(), rowPos.y - PopupWindowPadding().y),
@@ -149,7 +170,7 @@ inline bool DrawPopupSubmenuScope(const char* label, DrawContentFn&& drawContent
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoSavedSettings);
if (std::string(label) == "Create") {
if (ShouldTracePopupSubmenuLabel(label)) {
static bool s_lastCreateOpen = false;
if (open != s_lastCreateOpen) {
TracePopupSubmenuIfNeeded(