33#ifndef DVD_EDITOR_UTILS_INL_
34#define DVD_EDITOR_UTILS_INL_
49template<
typename T,
bool SeparateActivate,
typename Pred>
55 if (!SeparateActivate || ImGui::IsItemActivated())
60 if (ImGui::IsItemDeactivatedAfterEdit())
70template<
typename T,
bool isSl
ider>
79 const ImVec4 buttonColour,
80 const ImVec4 buttonColourHovered,
81 const ImVec4 buttonColourActive,
82 ImGuiInputTextFlags flags,
85 bool ret =
false, wasDeactivated =
false;
87 const T cStep =
IS_ZERO( step ) ? 100 : (step * 100);
88 const void* step_ptr =
IS_ZERO(step) ? nullptr : (
void*)&step;
89 const void* step_fast_ptr =
IS_ZERO(stepFast) ? (step_ptr ==
nullptr ? nullptr : (
void*)&cStep) : (
void*)&stepFast;
92 const ImVec2 buttonSize = { lineHeight + 3.f, lineHeight };
93 const bool readOnly = (flags & ImGuiInputTextFlags_ReadOnly);
99 PushButtonStyle(
true, buttonColour, buttonColourHovered, buttonColourActive);
100 if (ImGui::Button(label, buttonSize)) {
106 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) {
113 if constexpr(isSlider)
115 ret = ImGui::DragScalar( fieldName.c_str(), data_type, &value, 0.1f, &minValue, &maxValue, format, readOnly ? ImGuiSliderFlags_NoInput : 0u ) || ret;
119 ret = ImGui::InputScalar( fieldName.c_str(), data_type, &value, step_ptr, step_fast_ptr, format, flags) || ret;
122 if (ret && ImGui::IsItemDeactivated()) {
123 wasDeactivated =
true;
126 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
128 ImGui::SetTooltip(format, value);
136 return { ret, wasDeactivated };
139template<
typename T,
size_t N,
bool isSl
ider>
142 const char*
const compLabels[],
144 const ImGuiInputTextFlags flags,
152 bool ret =
false, wasDeactivated =
false;
154 for (
size_t i = 0; i < N; ++i)
156 const DrawReturnValue temp = DrawVecComponent<T, isSlider>(data_type, compLabels[i], values[i], resetValue, minValue, maxValue, step, stepFast,
Colours[i % 3],
ColoursHovered[i % 3],
Colours[i % 3], flags, format);
161 ImGui::Dummy(ImVec2(0,0));
164 return { ret, wasDeactivated };
167template<
typename T,
size_t N,
bool isSl
ider>
171 const ImGuiInputTextFlags flags,
175 return DrawVec<T, N, isSlider>(data_type, label,
FieldLabels, values, flags, resetValue, T{ 0 }, T{ 0 }, T{ 0 }, T{ 0 }, format);
178template<
typename Pred>
188 const bool ret = ImGui::ColorEdit4(
"", col.
_v, ImGuiColorEditFlags_DefaultOptions_);
198 if (!readOnly && ret)
203 return readOnly ? false : (ret ? dataSetter(col) :
false);
206template<
typename Pred>
217 const bool ret = ImGui::ColorEdit3(
"", col.
_v, ImGuiColorEditFlags_DefaultOptions_);
227 if (!readOnly && ret)
232 return readOnly ? false : (ret ? dataSetter(col) :
false);
235template<
typename FieldDataType,
typename ComponentType,
size_t num_comp>
240 return inputOrSlider<FieldDataType, ComponentType, num_comp, true>(
parent, label, stepIn, data_type, field, flags, format);
243 return inputOrSlider<FieldDataType, ComponentType, num_comp, false>(
parent, label, stepIn, data_type, field, flags, format);
246template<
typename FieldDataType,
typename ComponentType,
size_t num_comp,
bool IsSl
ider>
249 FieldDataType val = field.
get<FieldDataType>();
262 if constexpr (num_comp > 1)
272 Util::DrawVec<ComponentType, num_comp, IsSlider>(data_type,
285 if constexpr(num_comp > 1)
287 for (
I32 i = 0; i <
to_I32(num_comp); ++i)
289 val[i] =
CLAMPED(val[i], min, max);
300 auto* tempData = field.
_data;
303 RegisterUndo<FieldDataType, IsSlider>(
parent, field.
_basicType, field.
get<FieldDataType>(), val, label, [tempData, tempSetter](
const FieldDataType& oldVal)
305 if (tempSetter != nullptr)
311 *static_cast<FieldDataType*>(tempData) = oldVal;
316 if (!field._readOnly && ret.wasChanged && !
COMPARE(val, field.get<FieldDataType>()))
321 return ret.wasChanged;
324template<
typename T,
size_t num_rows>
328 ImGui::Text(
"[ %s ]", label);
330 if (Util::IsPushedTooltip() && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
332 ImGui::SetTooltip(Util::PushedToolTip());
334 const T cStep =
static_cast<T
>(stepIn * 100);
335 const void* step =
IS_ZERO(stepIn) ? nullptr : (
void*)&stepIn;
336 const void* step_fast = step ==
nullptr ? nullptr : (
void*)&cStep;
338 T mat = field.
get<T>();
344 bool showTooltip =
false, copyToClipboard =
false;;
348 ImGui::PushItemWidth(250);
349 ret = ImGui::InputScalarN(Util::StringFormat(
"##{}_0", label).c_str(), data_type, (
void*)mat._vec[0]._v, num_rows, step, step_fast, parsedFormat, flags);
350 showTooltip = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) || showTooltip;
351 copyToClipboard = (showTooltip && ImGui::IsMouseClicked(0)) || copyToClipboard;
353 ret = ImGui::InputScalarN(Util::StringFormat(
"##{}_1", label).c_str(), data_type, (
void*)mat._vec[1]._v, num_rows, step, step_fast, parsedFormat, flags) || ret;
354 showTooltip = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) || showTooltip;
355 copyToClipboard = (showTooltip && ImGui::IsMouseClicked(0)) || copyToClipboard;
357 if constexpr(num_rows > 2)
359 ret = ImGui::InputScalarN(Util::StringFormat(
"##{}_2", label).c_str(), data_type, (
void*)mat._vec[2]._v, num_rows, step, step_fast, parsedFormat, flags) || ret;
360 showTooltip = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) || showTooltip;
361 copyToClipboard = (showTooltip && ImGui::IsMouseClicked(0)) || copyToClipboard;
363 if constexpr(num_rows > 3)
365 ret = ImGui::InputScalarN(Util::StringFormat(
"##{}_3", label).c_str(), data_type, (
void*)mat._vec[3]._v, num_rows, step, step_fast, parsedFormat, flags) || ret;
366 showTooltip = ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) || showTooltip;
367 copyToClipboard = (showTooltip && ImGui::IsMouseClicked(0)) || copyToClipboard;
371 ImGui::PopItemWidth();
379 const char* tooltip =
"\n\nClick to copy values to clipboard.";
380 string matrixText =
"";
382 for (
size_t i = 0; i < num_rows; ++i)
384 auto& row = mat.m[i];
385 for (
size_t j = 0; j < num_rows; ++j)
389 matrixText.append(
" ");
392 matrixText.append(Util::StringFormat(parsedFormat, row[j]));
393 if (j < num_rows - 1)
395 matrixText.append(
" ");
399 if (i < num_rows - 1)
401 matrixText.append(
"\n\n");
405 ImGui::SetTooltip((matrixText + tooltip).c_str());
409 parent.showStatusMessage(
"Copied values to clipboard!", Time::SecondsToMilliseconds<F32>(3.f),
false);
415 auto* tempData = field.
_data;
417 RegisterUndo<T, false>(
parent, field.
_basicType, field.
get<T>(), mat, label, [tempData, tempSetter](
const T& oldVal)
419 if (tempSetter != nullptr)
425 *static_cast<T*>(tempData) = oldVal;
void registerUndoEntry(const UndoEntry< T > &entry)
DrawReturnValue DrawVec(ImGuiDataType data_type, const char *label, T *values, ImGuiInputTextFlags flags, T resetValue=0, const char *format="%.2f")
Str StringFormat(const char *fmt, Args &&...args)
void RegisterUndo(Editor &editor, PushConstantType type, const T &oldVal, const T &newVal, const char *name, Pred &&dataSetter)
F32 GetLineHeight() noexcept
static const ImVec4 Colours[]
bool colourInput4(Editor &parent, EditorComponentField &field)
static const ImVec4 ColoursHovered[]
void PushButtonStyle(bool bold, ImVec4 buttonColour, ImVec4 buttonColourHovered, ImVec4 buttonColourActive)
bool colourInput3(Editor &parent, EditorComponentField &field)
bool inputOrSlider(Editor &parent, const bool isSlider, const char *label, const F32 stepIn, ImGuiDataType data_type, EditorComponentField &field, ImGuiInputTextFlags flags, const char *format)
bool inputMatrix(Editor &parent, const char *label, const F32 stepIn, const ImGuiDataType data_type, EditorComponentField &field, const ImGuiInputTextFlags flags, const char *format)
const char * GetFormat(ImGuiDataType dataType, const char *input, bool hex)
DrawReturnValue DrawVecComponent(ImGuiDataType data_type, const char *label, T &value, T resetValue, T minValue, T maxValue, T step, T stepFast, ImVec4 buttonColour, ImVec4 buttonColourHovered, ImVec4 buttonColourActive, ImGuiInputTextFlags flags, const char *format="%.2f")
constexpr const char * FieldLabels[]
void BeginPropertyTable(I32 numComponents, const char *label)
void SetClipboardText(const char *text) noexcept
bool IS_ZERO(const T X) noexcept
void PushReadOnly(const bool fade)
constexpr U64 _ID(const char *const str, const U64 value=val_64_const) noexcept
::value constexpr T CLAMPED(T n, T min, T max) noexcept
bool COMPARE(T X, U Y) noexcept
constexpr I32 to_I32(const T value)
hashAlg::unordered_map< K, V, HashFun, Predicate > hashMapDefaultAlloc
void set(const T &dataIn)
DELEGATE_STD< void, const void * > _dataSetter
vec2< F32 > _range
Used by slider_type as a min / max range or dropdown as selected_index / count.
PushConstantType _basicType
const char *const * _labels
DELEGATE_STD< void, const T & > _dataSetter