diff --git a/opengl/DearImGui.cpp b/opengl/DearImGui.cpp index 3b9ae89..4ce7160 100644 --- a/opengl/DearImGui.cpp +++ b/opengl/DearImGui.cpp @@ -596,3 +596,49 @@ template class ImGuiWidget; // -------------------------------------------------------------------------------------------------------------------- END_NAMESPACE_DGL + +// -------------------------------------------------------------------------------------------------------------------- +// extra ImGui calls + +namespace ImGui { + +// -------------------------------------------------------------------------------------------------------------------- + +void RightAlignedLabelText(const char* label, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + RightAlignedLabelTextV(label, fmt, args); + va_end(args); +} + +void RightAlignedLabelTextV(const char* label, const char* fmt, va_list args) +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + ImGuiContext& g = *GImGui; + const ImGuiStyle& style = g.Style; + const float w = CalcItemWidth(); + + const char* value_text_begin, *value_text_end; + ImFormatStringToTempBufferV(&value_text_begin, &value_text_end, fmt, args); + const ImVec2 value_size = CalcTextSize(value_text_begin, value_text_end, false); + const ImVec2 label_size = CalcTextSize(label, NULL, true); + + const ImVec2 pos = window->DC.CursorPos; + const ImRect value_bb(pos, pos + ImVec2(w, value_size.y + style.FramePadding.y * 2)); + const ImRect total_bb(pos, pos + ImVec2(w + (label_size.x > 0.0f ? style.ItemInnerSpacing.x + label_size.x : 0.0f), ImMax(value_size.y, label_size.y) + style.FramePadding.y * 2)); + ItemSize(total_bb, style.FramePadding.y); + if (!ItemAdd(total_bb, 0)) + return; + + // Render + RenderTextClipped(value_bb.Max - value_size - style.FramePadding, value_bb.Max, value_text_begin, value_text_end, &value_size, ImVec2(0.0f, 0.0f)); + RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y + style.FramePadding.y), label); +} + +// -------------------------------------------------------------------------------------------------------------------- + +} diff --git a/opengl/DearImGui.hpp b/opengl/DearImGui.hpp index ce0aae9..0a0a3cf 100644 --- a/opengl/DearImGui.hpp +++ b/opengl/DearImGui.hpp @@ -121,3 +121,18 @@ typedef ImGuiWidget ImGuiStandaloneWindow; // -------------------------------------------------------------------------------------------------------------------- END_NAMESPACE_DGL + +// -------------------------------------------------------------------------------------------------------------------- +// extra ImGui calls + +namespace ImGui { + +// -------------------------------------------------------------------------------------------------------------------- +// custom ImGui LabelText implementation for right alignment + +void RightAlignedLabelText(const char* label, const char* fmt, ...); +void RightAlignedLabelTextV(const char* label, const char* fmt, va_list args); + +// -------------------------------------------------------------------------------------------------------------------- + +} diff --git a/opengl/LVGL.hpp b/opengl/LVGL.hpp index 77da600..8bf46e2 100644 --- a/opengl/LVGL.hpp +++ b/opengl/LVGL.hpp @@ -98,7 +98,7 @@ START_NAMESPACE_DGL This class exposes the LVGL drawing API inside a DGL Widget. This class will take care of setting up LVGL for drawing, - and also also user input, resizes and everything in between. + and also user input, resizes and everything in between. */ template class LVGLWidget : public BaseWidget,