Files
XCEngine/editor/src/UI/ScalarControls.h

114 lines
2.6 KiB
C
Raw Normal View History

#pragma once
2026-03-26 21:18:33 +08:00
#include "Core.h"
#include <imgui.h>
namespace XCEngine {
namespace Editor {
namespace UI {
inline bool DrawFloat(
const char* label,
float& value,
2026-03-26 21:18:33 +08:00
float columnWidth = DefaultControlLabelWidth(),
float dragSpeed = 0.1f,
float min = 0.0f,
float max = 0.0f,
const char* format = "%.2f"
) {
2026-03-26 21:18:33 +08:00
return DrawControlRow(label, columnWidth, [&]() {
return ImGui::DragFloat("##value", &value, dragSpeed, min, max, format);
});
}
inline bool DrawInt(
const char* label,
int& value,
2026-03-26 21:18:33 +08:00
float columnWidth = DefaultControlLabelWidth(),
int step = 1,
int min = 0,
int max = 0
) {
2026-03-26 21:18:33 +08:00
return DrawControlRow(label, columnWidth, [&]() {
return ImGui::DragInt("##value", &value, static_cast<float>(step), min, max);
});
}
inline bool DrawBool(
const char* label,
bool& value,
2026-03-26 21:18:33 +08:00
float columnWidth = DefaultControlLabelWidth()
) {
2026-03-26 21:18:33 +08:00
return DrawControlRow(label, columnWidth, [&]() {
return ImGui::Checkbox("##value", &value);
});
}
inline bool DrawColor3(
const char* label,
float color[3],
2026-03-26 21:18:33 +08:00
float columnWidth = DefaultControlLabelWidth()
) {
2026-03-26 21:18:33 +08:00
return DrawControlRow(label, columnWidth, [&]() {
return ImGui::ColorEdit3("##value", color, ImGuiColorEditFlags_NoInputs);
});
}
inline bool DrawColor4(
const char* label,
float color[4],
2026-03-26 21:18:33 +08:00
float columnWidth = DefaultControlLabelWidth()
) {
2026-03-26 21:18:33 +08:00
return DrawControlRow(label, columnWidth, [&]() {
return ImGui::ColorEdit4("##value", color, ImGuiColorEditFlags_NoInputs);
});
}
inline bool DrawSliderFloat(
const char* label,
float& value,
float min,
float max,
2026-03-26 21:18:33 +08:00
float columnWidth = DefaultControlLabelWidth(),
const char* format = "%.2f"
) {
2026-03-26 21:18:33 +08:00
return DrawControlRow(label, columnWidth, [&]() {
return ImGui::SliderFloat("##value", &value, min, max, format);
});
}
inline bool DrawSliderInt(
const char* label,
int& value,
int min,
int max,
2026-03-26 21:18:33 +08:00
float columnWidth = DefaultControlLabelWidth()
) {
2026-03-26 21:18:33 +08:00
return DrawControlRow(label, columnWidth, [&]() {
return ImGui::SliderInt("##value", &value, min, max);
});
}
inline int DrawCombo(
const char* label,
int currentItem,
const char* const items[],
int itemCount,
2026-03-26 21:18:33 +08:00
float columnWidth = DefaultControlLabelWidth(),
int heightInItems = -1
) {
int changedItem = currentItem;
2026-03-26 21:18:33 +08:00
DrawControlRow(label, columnWidth, [&]() {
ImGui::SetNextItemWidth(-1);
if (ImGui::Combo("##value", &currentItem, items, itemCount, heightInItems)) {
changedItem = currentItem;
}
2026-03-26 21:18:33 +08:00
return false;
});
return changedItem;
}
}
}
}