10inline void DrawScreenspaceText(
float x,
float y, ImU32 color,
const char* text,
bool centered =
false)
14 const ImVec2 textSize = ImGui::CalcTextSize(text);
15 x -= textSize.x * 0.5f;
18 ImGui::GetForegroundDrawList()->AddText({x, y}, color, text);
21inline void DrawWorldspaceText(
float x,
float y,
float z, ImU32 color,
const char* text,
bool centered =
false,
float offsetY = 0.0f)
30 const ImVec2 textSize = ImGui::CalcTextSize(text);
31 screenX -= textSize.x * 0.5f;
34 ImGui::GetForegroundDrawList()->AddText({screenX, screenY}, color, text);
43 const char* valueFormat =
"%.2f")
46 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
47 ImGui::SliderFloat(
id, value, min, max,
"");
48 ImGui::PopItemWidth();
51 ImVec2 sliderMin = ImGui::GetItemRectMin();
52 ImVec2 sliderMax = ImGui::GetItemRectMax();
53 ImVec2 sliderSize = ImGui::GetItemRectSize();
55 ImDrawList* drawList = ImGui::GetWindowDrawList();
56 ImU32 color = ImGui::GetColorU32(ImGuiCol_Text);
59 constexpr int textPadding = 6;
60 ImVec2 labelSize = ImGui::CalcTextSize(label);
61 float textY = sliderMin.y + (sliderSize.y - labelSize.y) * 0.5f;
62 drawList->AddText(ImVec2(sliderMin.x + textPadding, textY), color, label);
66 snprintf(valueLabel,
sizeof(valueLabel), valueFormat, *value);
67 ImVec2 valueLabelSize = ImGui::CalcTextSize(valueLabel);
68 drawList->AddText(ImVec2(sliderMax.x - valueLabelSize.x - textPadding, textY), color, valueLabel);
71inline void DrawIntSlider(
int* value,
int min,
int max,
const char*
id,
const char* label,
const char* valueFormat =
"%d")
74 ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
75 ImGui::SliderInt(
id, value, min, max,
"");
76 ImGui::PopItemWidth();
79 ImVec2 sliderMin = ImGui::GetItemRectMin();
80 ImVec2 sliderMax = ImGui::GetItemRectMax();
81 ImVec2 sliderSize = ImGui::GetItemRectSize();
83 ImDrawList* drawList = ImGui::GetWindowDrawList();
84 ImU32 color = ImGui::GetColorU32(ImGuiCol_Text);
87 constexpr int textPadding = 6;
88 ImVec2 labelSize = ImGui::CalcTextSize(label);
89 float textY = sliderMin.y + (sliderSize.y - labelSize.y) * 0.5f;
90 drawList->AddText(ImVec2(sliderMin.x + textPadding, textY), color, label);
94 snprintf(valueLabel,
sizeof(valueLabel), valueFormat, *value);
95 ImVec2 valueLabelSize = ImGui::CalcTextSize(valueLabel);
96 drawList->AddText(ImVec2(sliderMax.x - valueLabelSize.x - textPadding, textY), color, valueLabel);
101 static char text[2048];
104 va_start(args, format);
105 vsnprintf(text,
sizeof(text), format, args);
108 float textWidth = ImGui::CalcTextSize(text).x;
109 float parentWidth = ImGui::GetContentRegionAvail().x;
111 ImGui::SetCursorPosX(ImGui::GetCursorPosX() + parentWidth - textWidth);
112 ImGui::Text(
"%s", text);
void DrawIntSlider(int *value, int min, int max, const char *id, const char *label, const char *valueFormat="%d")
Definition imguiHelpers.h:71
void DrawScreenspaceText(float x, float y, ImU32 color, const char *text, bool centered=false)
Definition imguiHelpers.h:10
void DrawWorldspaceText(float x, float y, float z, ImU32 color, const char *text, bool centered=false, float offsetY=0.0f)
Definition imguiHelpers.h:21
void DrawRightAlignedText(const char *format,...)
Definition imguiHelpers.h:99
AppState app
Definition main.cpp:71
void DrawFloatSlider(float *value, float min, float max, const char *id, const char *label, const char *valueFormat="%.2f")
Definition imguiHelpers.h:37
void worldToScreen(float x, float y, float z, float *screenX, float *screenY) const
Definition AppState.cpp:62