Editor: 更新编辑器面板和UI控件系统
- 添加新的UI控件系统(Core.h, ScalarControls.h, VectorControls.h, UI.h) - 更新SceneManager支持场景层级管理 - 优化SelectionManager选择管理 - 改进InspectorPanel/GameViewPanel/HierarchyPanel等面板 - 更新RHI文档说明Vulkan实现计划
This commit is contained in:
150
editor/src/UI/VectorControls.h
Normal file
150
editor/src/UI/VectorControls.h
Normal file
@@ -0,0 +1,150 @@
|
||||
#pragma once
|
||||
|
||||
#include <imgui.h>
|
||||
#include <XCEngine/Core/Math/Vector3.h>
|
||||
#include <XCEngine/Core/Math/Vector2.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
namespace UI {
|
||||
|
||||
inline bool DrawVec3(
|
||||
const char* label,
|
||||
::XCEngine::Math::Vector3& values,
|
||||
float resetValue = 0.0f,
|
||||
float columnWidth = 100.0f,
|
||||
float dragSpeed = 0.1f
|
||||
) {
|
||||
bool changed = false;
|
||||
ImGui::PushID(label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{0, 1});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 1});
|
||||
|
||||
if (ImGui::BeginTable("##Vec3Table", 2, ImGuiTableFlags_NoSavedSettings)) {
|
||||
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
||||
ImGui::TableSetupColumn("##controls", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + 2.0f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{0, 0});
|
||||
|
||||
float lineHeight = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.0f;
|
||||
ImVec2 buttonSize = {lineHeight + 3.0f, lineHeight};
|
||||
float itemWidth = (ImGui::GetContentRegionAvail().x - buttonSize.x * 3.0f) / 3.0f;
|
||||
|
||||
auto drawAxisControl = [&](const char* axisLabel, float& value, ImVec4 color, ImVec4 colorHovered) {
|
||||
bool axisChanged = false;
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colorHovered);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, color);
|
||||
|
||||
if (ImGui::Button(axisLabel, buttonSize)) {
|
||||
value = resetValue;
|
||||
axisChanged = true;
|
||||
}
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(itemWidth);
|
||||
|
||||
if (ImGui::DragFloat((std::string("##") + axisLabel).c_str(), &value, dragSpeed, 0.0f, 0.0f, "%.2f")) {
|
||||
axisChanged = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
return axisChanged;
|
||||
};
|
||||
|
||||
changed |= drawAxisControl("X", values.x, ImVec4{0.8f, 0.1f, 0.15f, 1.0f}, ImVec4{0.9f, 0.2f, 0.2f, 1.0f});
|
||||
changed |= drawAxisControl("Y", values.y, ImVec4{0.2f, 0.7f, 0.2f, 1.0f}, ImVec4{0.3f, 0.8f, 0.3f, 1.0f});
|
||||
changed |= drawAxisControl("Z", values.z, ImVec4{0.1f, 0.25f, 0.8f, 1.0f}, ImVec4{0.2f, 0.35f, 0.9f, 1.0f});
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopID();
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
inline bool DrawVec2(
|
||||
const char* label,
|
||||
::XCEngine::Math::Vector2& values,
|
||||
float resetValue = 0.0f,
|
||||
float columnWidth = 100.0f,
|
||||
float dragSpeed = 0.1f
|
||||
) {
|
||||
bool changed = false;
|
||||
ImGui::PushID(label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{0, 1});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 1});
|
||||
|
||||
if (ImGui::BeginTable("##Vec2Table", 2, ImGuiTableFlags_NoSavedSettings)) {
|
||||
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
||||
ImGui::TableSetupColumn("##controls", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + 2.0f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2{0, 0});
|
||||
|
||||
float lineHeight = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.0f;
|
||||
ImVec2 buttonSize = {lineHeight + 3.0f, lineHeight};
|
||||
float itemWidth = (ImGui::GetContentRegionAvail().x - buttonSize.x * 2.0f) / 2.0f;
|
||||
|
||||
auto drawAxisControl = [&](const char* axisLabel, float& value, ImVec4 color, ImVec4 colorHovered) {
|
||||
bool axisChanged = false;
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, color);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colorHovered);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, color);
|
||||
|
||||
if (ImGui::Button(axisLabel, buttonSize)) {
|
||||
value = resetValue;
|
||||
axisChanged = true;
|
||||
}
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(itemWidth);
|
||||
|
||||
if (ImGui::DragFloat((std::string("##") + axisLabel).c_str(), &value, dragSpeed, 0.0f, 0.0f, "%.2f")) {
|
||||
axisChanged = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
|
||||
return axisChanged;
|
||||
};
|
||||
|
||||
changed |= drawAxisControl("X", values.x, ImVec4{0.8f, 0.1f, 0.15f, 1.0f}, ImVec4{0.9f, 0.2f, 0.2f, 1.0f});
|
||||
changed |= drawAxisControl("Y", values.y, ImVec4{0.2f, 0.7f, 0.2f, 1.0f}, ImVec4{0.3f, 0.8f, 0.3f, 1.0f});
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopID();
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user