9#include "imgui/imgui.h"
10#include "imgui/imgui_internal.h"
14namespace property_inspector_internal {
17 ImGuiContext* ctx = ImGui::GetCurrentContext();
18 return ctx !=
nullptr && ctx->CurrentTable !=
nullptr;
21void BeginRow(
const char* label,
const char* tooltip) {
25 ImGui::TableNextColumn();
26 ImGui::AlignTextToFramePadding();
27 ImGui::TextUnformatted(label);
28 if (tooltip && tooltip[0] !=
'\0' && ImGui::IsItemHovered()) {
29 ImGui::SetTooltip(
"%s", tooltip);
31 ImGui::TableNextColumn();
32 ImGui::SetNextItemWidth(-FLT_MIN);
38 result.reserve(std::strlen(label) + 2);
39 result.append(
"##").append(label);
50namespace pi = property_inspector_internal;
55 const T lo =
static_cast<T
>(opts.
min);
56 const T hi =
static_cast<T
>(opts.
max);
78 const bool changed = ImGui::Checkbox(
id.c_str(), value);
86 const int step =
static_cast<int>(opts.
step);
87 const int step_fast =
static_cast<int>(opts.
step_fast);
90 ImGui::InputInt(
id.c_str(), value, step, step_fast, opts.
text_flags);
93 ClampIfBounded(value, opts);
101 const std::uint8_t step =
static_cast<std::uint8_t
>(opts.
step);
102 const std::uint8_t step_fast =
static_cast<std::uint8_t
>(opts.
step_fast);
104 const bool changed = ImGui::InputScalar(
105 id.c_str(), ImGuiDataType_U8, value, step ? &step :
nullptr,
106 step_fast ? &step_fast :
nullptr, IntFormat(opts), opts.
text_flags);
107 ImGui::EndDisabled();
109 ClampIfBounded(value, opts);
117 const std::uint16_t step =
static_cast<std::uint16_t
>(opts.
step);
118 const std::uint16_t step_fast =
static_cast<std::uint16_t
>(opts.
step_fast);
120 const bool changed = ImGui::InputScalar(
121 id.c_str(), ImGuiDataType_U16, value, step ? &step :
nullptr,
122 step_fast ? &step_fast :
nullptr, IntFormat(opts), opts.
text_flags);
123 ImGui::EndDisabled();
125 ClampIfBounded(value, opts);
133 const std::uint32_t step =
static_cast<std::uint32_t
>(opts.
step);
134 const std::uint32_t step_fast =
static_cast<std::uint32_t
>(opts.
step_fast);
136 const bool changed = ImGui::InputScalar(
137 id.c_str(), ImGuiDataType_U32, value, step ? &step :
nullptr,
138 step_fast ? &step_fast :
nullptr, IntFormat(opts), opts.
text_flags);
139 ImGui::EndDisabled();
141 ClampIfBounded(value, opts);
149 const float step =
static_cast<float>(opts.
step > 0 ? opts.
step : 0.0);
150 const float step_fast =
154 ImGui::InputFloat(
id.c_str(), value, step, step_fast,
156 ImGui::EndDisabled();
158 ClampIfBounded(value, opts);
166 const double step = opts.
step > 0 ? opts.
step : 0.0;
170 ImGui::InputDouble(
id.c_str(), value, step, step_fast,
172 ImGui::EndDisabled();
174 ClampIfBounded(value, opts);
181 if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) {
182 auto* str =
static_cast<std::string*
>(data->UserData);
183 str->resize(
static_cast<std::size_t
>(data->BufTextLen));
184 data->Buf = str->data();
197 if (value->capacity() < value->size() + 1) {
198 value->reserve(value->size() + 32);
201 ImGui::InputText(
id.c_str(), value->data(), value->capacity() + 1,
202 opts.
text_flags | ImGuiInputTextFlags_CallbackResize,
203 &StringInputCallback, value);
204 ImGui::EndDisabled();
213 const bool changed = ImGui::ColorEdit4(
id.c_str(), &value->x);
214 ImGui::EndDisabled();
224 const bool changed = ImGui::ColorEdit4(
id.c_str(), rgba);
225 ImGui::EndDisabled();
227 value->
red = rgba[0];
228 value->
green = rgba[1];
229 value->
blue = rgba[2];
230 value->
alpha = rgba[3];
242 const char* fmt = opts.
format ? opts.
format : default_fmt;
243 const T step =
static_cast<T
>(opts.
step);
244 const T step_fast =
static_cast<T
>(opts.
step_fast);
246 const bool changed = ImGui::InputScalar(
247 id.c_str(), type, value, step ? &step :
nullptr,
248 step_fast ? &step_fast :
nullptr, fmt,
249 opts.
text_flags | ImGuiInputTextFlags_CharsHexadecimal |
250 ImGuiInputTextFlags_CharsUppercase);
251 ImGui::EndDisabled();
261 return DrawHexScalar(label, value, ImGuiDataType_U8,
"%02X", opts);
266 return DrawHexScalar(label, value, ImGuiDataType_U16,
"%04X", opts);
271 return DrawHexScalar(label, value, ImGuiDataType_U32,
"%08X", opts);
const char * IntFormat(const PropertyOptions &opts)
const char * FloatFormat(const PropertyOptions &opts, const char *fallback)
int StringInputCallback(ImGuiInputTextCallbackData *data)
void ClampIfBounded(T *value, const PropertyOptions &opts)
bool DrawHexScalar(const char *label, T *value, ImGuiDataType type, const char *default_fmt, const PropertyOptions &opts)
void BeginRow(const char *label, const char *tooltip)
std::string ResolveWidgetId(const char *label)
bool DrawProperty(const char *label, bool *value, const PropertyOptions &opts)
bool DrawPropertyHex(const char *label, std::uint8_t *value, const PropertyOptions &opts)
ImGuiInputTextFlags text_flags