From d58ded3acb99d20a34c0277f7684f14ec0437d93 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 13 Feb 2015 10:37:03 +0000 Subject: [PATCH] Sliders: value is clipped inside the frame when resizing sliders to be small. --- imgui.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cebe20134..4281c24cc 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4591,8 +4591,9 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c // Draw value using user-provided display format so user can add prefix/suffix/decorations to the value. char value_buf[64]; - ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); - RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf, NULL, true).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf); + char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); + const ImVec2 value_text_size = CalcTextSize(value_buf, value_buf_end, true); + RenderTextClipped(ImVec2(ImMax(frame_bb.Min.x + style.FramePadding.x, slider_bb.GetCenter().x - value_text_size.x*0.5f), frame_bb.Min.y + style.FramePadding.y), value_buf, value_buf_end, &value_text_size, frame_bb.Max); RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label);