From e268303c02d7af44e542088a21a4e9fc8b52e530 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 20 Sep 2015 11:37:46 +0200 Subject: [PATCH] PlotLines: fixed rendering issue added in previous commit (#342) --- imgui.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8b3f900e..eac6a26b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6580,16 +6580,15 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true, style.FrameRounding); - int res_w = ImMin((int)graph_size.x, values_count); - if (plot_type == ImGuiPlotType_Lines) - res_w -= 1; + int res_w = ImMin((int)graph_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0); + int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0); // Tooltip on hover int v_hovered = -1; if (IsHovered(inner_bb, 0)) { const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f); - const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0))); + const int v_idx = (int)(t * item_count); IM_ASSERT(v_idx >= 0 && v_idx < values_count); const float v0 = values_getter(data, (v_idx + values_offset) % values_count); @@ -6613,7 +6612,7 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge for (int n = 0; n < res_w; n++) { const float t1 = t0 + t_step; - const int v_idx = (int)(t0 * values_count + 0.5f); + const int v_idx = (int)(t0 * item_count + 0.5f); IM_ASSERT(v_idx >= 0 && v_idx < values_count); const float v1 = values_getter(data, (v_idx + values_offset + 1) % values_count); const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );