3#include "Headers/Utils.h"
5#include <imgui_internal.h>
20 bool InputDoubleN(
const char* label,
double* v,
const int components,
const char* display_format,
const ImGuiInputTextFlags extra_flags )
22 const ImGuiWindow* window = GetCurrentWindow();
23 if ( window->SkipItems )
26 const ImGuiContext& g = *GImGui;
27 bool value_changed =
false;
30 PushMultiItemsWidths( components, CalcItemWidth() );
31 for (
int i = 0; i < components; i++ )
34 value_changed |= InputDouble(
"##v", &v[i], 0.0, 0.0, display_format, extra_flags );
35 SameLine( 0, g.Style.ItemInnerSpacing.x );
41 TextUnformatted( label, FindRenderedTextEnd( label ) );
47 bool InputDouble2(
const char* label,
double v[2],
const char* display_format,
const ImGuiInputTextFlags extra_flags )
49 return InputDoubleN( label, v, 2, display_format, extra_flags );
52 bool InputDouble3(
const char* label,
double v[3],
const char* display_format,
const ImGuiInputTextFlags extra_flags )
54 return InputDoubleN( label, v, 3, display_format, extra_flags );
57 bool InputDouble4(
const char* label,
double v[4],
const char* display_format,
const ImGuiInputTextFlags extra_flags )
59 return InputDoubleN( label, v, 4, display_format, extra_flags );
220 return ImGuiKey_None;
226 return GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.f;
231 ImVec2 min = ImGui::GetItemRectMin();
232 const ImVec2 max = ImGui::GetItemRectMax();
234 ImGui::GetWindowDrawList()->AddLine( min, max, ImGui::GetColorU32( ImGuiCol_Text ), 1.0f );
239 ImFont* boldFont = ImGui::GetIO().Fonts->Fonts[1];
241 ImGui::PushID( label );
244 ImGui::PushFont( boldFont );
245 ImGui::Text( label );
246 if ( ImGui::IsItemHovered( ImGuiHoveredFlags_AllowWhenDisabled ) )
254 ImGui::SetTooltip( label );
260 if ( numComponents == 1 )
262 ImGui::PushItemWidth( ImGui::CalcItemWidth() );
266 ImGui::PushMultiItemsWidths( numComponents, ImGui::CalcItemWidth() );
268 g_lastComponentWidhtPushCount = numComponents;
273 for (
I32 i = 0; i < g_lastComponentWidhtPushCount; ++i )
275 ImGui::PopItemWidth();
277 g_lastComponentWidhtPushCount = 0;
284 if ( !g_isBoldButtonPushed )
286 ImGui::PushFont( ImGui::GetIO().Fonts->Fonts[1] );
287 g_isBoldButtonPushed =
true;
293 if ( g_isBoldButtonPushed )
296 g_isBoldButtonPushed =
false;
302 if ( !g_isNarrowLabelWidthPushed )
304 g_isNarrowLabelWidthPushed =
true;
310 if ( g_isNarrowLabelWidthPushed )
312 g_isNarrowLabelWidthPushed =
false;
318 g_pushedTooltip = tooltip;
323 g_pushedTooltip =
"";
328 return strlen( g_pushedTooltip ) > 0;
333 return g_pushedTooltip;
337 const ImVec4 buttonColour,
338 const ImVec4 buttonColourHovered,
339 const ImVec4 buttonColourActive )
345 ImGui::PushStyleColor( ImGuiCol_Button, buttonColour );
346 ImGui::PushStyleColor( ImGuiCol_ButtonHovered, buttonColourHovered );
347 ImGui::PushStyleColor( ImGuiCol_ButtonActive, buttonColourActive );
353 ImGui::PopStyleColor( 3 );
357 const char*
GetFormat( ImGuiDataType dataType,
const char* input,
const bool hex )
359 if ( input ==
nullptr || strlen( input ) == 0 )
361 const auto unsignedType = [dataType]()
363 return dataType == ImGuiDataType_U8 || dataType == ImGuiDataType_U16 || dataType == ImGuiDataType_U32 || dataType == ImGuiDataType_U64;
366 return dataType == ImGuiDataType_Float ?
"%.3f"
367 : dataType == ImGuiDataType_Double ?
"%.6f"
368 : hex ?
"%08X" : (unsignedType() ?
"%u" :
"%d");
377 const auto setter = [val, &field](
const FColour4& col )
393 const auto setter = [val, &field](
const FColour3& col )
408 const ImGuiViewport* main_viewport = ImGui::GetMainViewport();
409 const ImVec2 workPos = main_viewport->WorkPos;
410 const ImVec2 workSize = main_viewport->WorkSize;
411 const ImVec2 targetPos = workPos + ImVec2( workSize.x * 0.5f, workSize.y * 0.5f );
413 ImGui::SetNextWindowPos( targetPos, ImGuiCond_Always, ImVec2( 0.5f, 0.5f ) );
419 ImGui::OpenPopup( name, popup_flags );
424 ImGui::PushStyleColor( ImGuiCol_Text, colour );
425 ImGui::TextUnformatted( text.data(), text.data() + text.length());
426 ImGui::PopStyleColor();
431 return ImGuiInputTextFlags_EnterReturnsTrue |
432 ImGuiInputTextFlags_CharsNoBlank |
433 (hex ? ImGuiInputTextFlags_CharsHexadecimal : ImGuiInputTextFlags_CharsDecimal) |
434 (readOnly ? ImGuiInputTextFlags_ReadOnly : 0u);
const char * PushedToolTip()
void PushTooltip(const char *tooltip)
void PushNarrowLabelWidth()
F32 GetLineHeight() noexcept
void PopNarrowLabelWidth()
void OpenCenteredPopup(const char *name, ImGui::ImGuiPopupFlags popup_flags=0)
bool colourInput4(Editor &parent, EditorComponentField &field)
constexpr F32 LabelColumnWidth
void PushButtonStyle(bool bold, ImVec4 buttonColour, ImVec4 buttonColourHovered, ImVec4 buttonColourActive)
ImGuiInputTextFlags GetDefaultFlagsForField(const EditorComponentField &field)
bool colourInput3(Editor &parent, EditorComponentField &field)
void PrintColouredText(const std::string_view text, const ImVec4 &colour)
const char * GetFormat(ImGuiDataType dataType, const char *input, bool hex)
constexpr F32 LabelColumnWidthNarrow
ImGuiInputTextFlags GetDefaultFlagsForSettings(bool readOnly, bool hex)
void BeginPropertyTable(I32 numComponents, const char *label)
static I32 g_lastComponentWidhtPushCount
static bool g_isNarrowLabelWidthPushed
static bool g_isBoldButtonPushed
static const char * g_pushedTooltip
Handle console commands that start with a forward slash.
ImGuiKey DivideKeyToImGuiKey(const Input::KeyCode key) noexcept
bool InputDouble4(const char *label, double v[4], const char *display_format, ImGuiInputTextFlags extra_flags)
bool InputDouble3(const char *label, double v[3], const char *display_format, ImGuiInputTextFlags extra_flags)
bool InputDouble2(const char *label, double v[2], const char *display_format, ImGuiInputTextFlags extra_flags)
bool InputDoubleN(const char *label, double *v, int components, const char *display_format, ImGuiInputTextFlags extra_flags)
void set(const T &dataIn)