Refactor editor UI architecture
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "Core.h"
|
||||
#include <imgui.h>
|
||||
|
||||
namespace XCEngine {
|
||||
@@ -9,194 +10,58 @@ namespace UI {
|
||||
inline bool DrawFloat(
|
||||
const char* label,
|
||||
float& value,
|
||||
float columnWidth = 100.0f,
|
||||
float columnWidth = DefaultControlLabelWidth(),
|
||||
float dragSpeed = 0.1f,
|
||||
float min = 0.0f,
|
||||
float max = 0.0f,
|
||||
const char* format = "%.2f"
|
||||
) {
|
||||
bool changed = false;
|
||||
ImGui::PushID(label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{0, 1});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 1});
|
||||
|
||||
if (ImGui::BeginTable("##FloatTable", 2, ImGuiTableFlags_NoSavedSettings)) {
|
||||
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
||||
ImGui::TableSetupColumn("##control", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + 2.0f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
if (max != min) {
|
||||
if (ImGui::SliderFloat("##value", &value, min, max, format)) {
|
||||
changed = true;
|
||||
}
|
||||
} else {
|
||||
if (ImGui::DragFloat("##value", &value, dragSpeed, min, max, format)) {
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopID();
|
||||
|
||||
return changed;
|
||||
return DrawControlRow(label, columnWidth, [&]() {
|
||||
return ImGui::DragFloat("##value", &value, dragSpeed, min, max, format);
|
||||
});
|
||||
}
|
||||
|
||||
inline bool DrawInt(
|
||||
const char* label,
|
||||
int& value,
|
||||
float columnWidth = 100.0f,
|
||||
float columnWidth = DefaultControlLabelWidth(),
|
||||
int step = 1,
|
||||
int min = 0,
|
||||
int max = 0
|
||||
) {
|
||||
bool changed = false;
|
||||
ImGui::PushID(label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{0, 1});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 1});
|
||||
|
||||
if (ImGui::BeginTable("##IntTable", 2, ImGuiTableFlags_NoSavedSettings)) {
|
||||
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
||||
ImGui::TableSetupColumn("##control", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + 2.0f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
if (ImGui::DragInt("##value", &value, static_cast<float>(step), min, max)) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopID();
|
||||
|
||||
return changed;
|
||||
return DrawControlRow(label, columnWidth, [&]() {
|
||||
return ImGui::DragInt("##value", &value, static_cast<float>(step), min, max);
|
||||
});
|
||||
}
|
||||
|
||||
inline bool DrawBool(
|
||||
const char* label,
|
||||
bool& value,
|
||||
float columnWidth = 100.0f
|
||||
float columnWidth = DefaultControlLabelWidth()
|
||||
) {
|
||||
bool changed = false;
|
||||
ImGui::PushID(label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{0, 1});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 1});
|
||||
|
||||
if (ImGui::BeginTable("##BoolTable", 2, ImGuiTableFlags_NoSavedSettings)) {
|
||||
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
||||
ImGui::TableSetupColumn("##control", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + 2.0f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
if (ImGui::Checkbox("##value", &value)) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopID();
|
||||
|
||||
return changed;
|
||||
return DrawControlRow(label, columnWidth, [&]() {
|
||||
return ImGui::Checkbox("##value", &value);
|
||||
});
|
||||
}
|
||||
|
||||
inline bool DrawColor3(
|
||||
const char* label,
|
||||
float color[3],
|
||||
float columnWidth = 100.0f
|
||||
float columnWidth = DefaultControlLabelWidth()
|
||||
) {
|
||||
bool changed = false;
|
||||
ImGui::PushID(label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{0, 1});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 1});
|
||||
|
||||
if (ImGui::BeginTable("##Color3Table", 2, ImGuiTableFlags_NoSavedSettings)) {
|
||||
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
||||
ImGui::TableSetupColumn("##control", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + 2.0f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
if (ImGui::ColorEdit3("##value", color, ImGuiColorEditFlags_NoInputs)) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopID();
|
||||
|
||||
return changed;
|
||||
return DrawControlRow(label, columnWidth, [&]() {
|
||||
return ImGui::ColorEdit3("##value", color, ImGuiColorEditFlags_NoInputs);
|
||||
});
|
||||
}
|
||||
|
||||
inline bool DrawColor4(
|
||||
const char* label,
|
||||
float color[4],
|
||||
float columnWidth = 100.0f
|
||||
float columnWidth = DefaultControlLabelWidth()
|
||||
) {
|
||||
bool changed = false;
|
||||
ImGui::PushID(label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{0, 1});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 1});
|
||||
|
||||
if (ImGui::BeginTable("##Color4Table", 2, ImGuiTableFlags_NoSavedSettings)) {
|
||||
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
||||
ImGui::TableSetupColumn("##control", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + 2.0f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
if (ImGui::ColorEdit4("##value", color, ImGuiColorEditFlags_NoInputs)) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopID();
|
||||
|
||||
return changed;
|
||||
return DrawControlRow(label, columnWidth, [&]() {
|
||||
return ImGui::ColorEdit4("##value", color, ImGuiColorEditFlags_NoInputs);
|
||||
});
|
||||
}
|
||||
|
||||
inline bool DrawSliderFloat(
|
||||
@@ -204,38 +69,12 @@ inline bool DrawSliderFloat(
|
||||
float& value,
|
||||
float min,
|
||||
float max,
|
||||
float columnWidth = 100.0f,
|
||||
float columnWidth = DefaultControlLabelWidth(),
|
||||
const char* format = "%.2f"
|
||||
) {
|
||||
bool changed = false;
|
||||
ImGui::PushID(label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{0, 1});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 1});
|
||||
|
||||
if (ImGui::BeginTable("##SliderTable", 2, ImGuiTableFlags_NoSavedSettings)) {
|
||||
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
||||
ImGui::TableSetupColumn("##control", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + 2.0f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
if (ImGui::SliderFloat("##value", &value, min, max, format)) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopID();
|
||||
|
||||
return changed;
|
||||
return DrawControlRow(label, columnWidth, [&]() {
|
||||
return ImGui::SliderFloat("##value", &value, min, max, format);
|
||||
});
|
||||
}
|
||||
|
||||
inline bool DrawSliderInt(
|
||||
@@ -243,37 +82,11 @@ inline bool DrawSliderInt(
|
||||
int& value,
|
||||
int min,
|
||||
int max,
|
||||
float columnWidth = 100.0f
|
||||
float columnWidth = DefaultControlLabelWidth()
|
||||
) {
|
||||
bool changed = false;
|
||||
ImGui::PushID(label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{0, 1});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 1});
|
||||
|
||||
if (ImGui::BeginTable("##SliderIntTable", 2, ImGuiTableFlags_NoSavedSettings)) {
|
||||
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
||||
ImGui::TableSetupColumn("##control", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + 2.0f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
if (ImGui::SliderInt("##value", &value, min, max)) {
|
||||
changed = true;
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopID();
|
||||
|
||||
return changed;
|
||||
return DrawControlRow(label, columnWidth, [&]() {
|
||||
return ImGui::SliderInt("##value", &value, min, max);
|
||||
});
|
||||
}
|
||||
|
||||
inline int DrawCombo(
|
||||
@@ -281,39 +94,17 @@ inline int DrawCombo(
|
||||
int currentItem,
|
||||
const char* const items[],
|
||||
int itemCount,
|
||||
float columnWidth = 100.0f,
|
||||
float columnWidth = DefaultControlLabelWidth(),
|
||||
int heightInItems = -1
|
||||
) {
|
||||
ImGui::PushID(label);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2{0, 1});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 1});
|
||||
|
||||
int changedItem = currentItem;
|
||||
|
||||
if (ImGui::BeginTable("##ComboTable", 2, ImGuiTableFlags_NoSavedSettings)) {
|
||||
ImGui::TableSetupColumn("##label", ImGuiTableColumnFlags_WidthFixed, columnWidth);
|
||||
ImGui::TableSetupColumn("##control", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_None, ImGui::GetFontSize() + 2.0f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
ImGui::Text(label);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
DrawControlRow(label, columnWidth, [&]() {
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
if (ImGui::Combo("##value", ¤tItem, items, itemCount, heightInItems)) {
|
||||
changedItem = currentItem;
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopID();
|
||||
|
||||
return false;
|
||||
});
|
||||
return changedItem;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user