323 lines
8.3 KiB
C
323 lines
8.3 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <imgui.h>
|
||
|
|
|
||
|
|
namespace XCEngine {
|
||
|
|
namespace Editor {
|
||
|
|
namespace UI {
|
||
|
|
|
||
|
|
inline bool DrawFloat(
|
||
|
|
const char* label,
|
||
|
|
float& value,
|
||
|
|
float columnWidth = 100.0f,
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool DrawInt(
|
||
|
|
const char* label,
|
||
|
|
int& value,
|
||
|
|
float columnWidth = 100.0f,
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool DrawBool(
|
||
|
|
const char* label,
|
||
|
|
bool& value,
|
||
|
|
float columnWidth = 100.0f
|
||
|
|
) {
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool DrawColor3(
|
||
|
|
const char* label,
|
||
|
|
float color[3],
|
||
|
|
float columnWidth = 100.0f
|
||
|
|
) {
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool DrawColor4(
|
||
|
|
const char* label,
|
||
|
|
float color[4],
|
||
|
|
float columnWidth = 100.0f
|
||
|
|
) {
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool DrawSliderFloat(
|
||
|
|
const char* label,
|
||
|
|
float& value,
|
||
|
|
float min,
|
||
|
|
float max,
|
||
|
|
float columnWidth = 100.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("##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;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool DrawSliderInt(
|
||
|
|
const char* label,
|
||
|
|
int& value,
|
||
|
|
int min,
|
||
|
|
int max,
|
||
|
|
float columnWidth = 100.0f
|
||
|
|
) {
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline int DrawCombo(
|
||
|
|
const char* label,
|
||
|
|
int currentItem,
|
||
|
|
const char* const items[],
|
||
|
|
int itemCount,
|
||
|
|
float columnWidth = 100.0f,
|
||
|
|
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();
|
||
|
|
|
||
|
|
ImGui::SetNextItemWidth(-1);
|
||
|
|
if (ImGui::Combo("##value", ¤tItem, items, itemCount, heightInItems)) {
|
||
|
|
changedItem = currentItem;
|
||
|
|
}
|
||
|
|
|
||
|
|
ImGui::EndTable();
|
||
|
|
}
|
||
|
|
|
||
|
|
ImGui::PopStyleVar(2);
|
||
|
|
ImGui::PopID();
|
||
|
|
|
||
|
|
return changedItem;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|