diff --git a/implot.cpp b/implot.cpp index d9260281..597b043b 100644 --- a/implot.cpp +++ b/implot.cpp @@ -31,7 +31,7 @@ Below is a change-log of API breaking changes only. If you are using one of the When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all implot files. You can read releases logs https://github.com/epezent/implot/releases for more details. -- 2023/08/20 (0.17) - ImPlotFlags_NoChild was removed as child windows are no longer needed to capture scroll. You can safely remove this flag if you were using it. +- 2023/08/20 (0.17) - ImPlotFlags_NoChild was removed as child windows are no longer needed to capture scroll. You can safely remove this flag if you were using it. - 2023/06/26 (0.15) - Various build fixes related to updates in Dear ImGui internals. - 2022/11/25 (0.15) - Make PlotText honor ImPlotItemFlags_NoFit. - 2022/06/19 (0.14) - The signature of ColormapScale has changed to accommodate a new ImPlotColormapScaleFlags parameter @@ -604,10 +604,10 @@ bool ClampLegendRect(ImRect& legend_rect, const ImRect& outer_rect, const ImVec2 if (legend_rect.Max.y > outer_rect_pad.Max.y) { legend_rect.Max.y = outer_rect_pad.Max.y; clamped = true; - } + } return clamped; } - + int LegendSortingComp(const void* _a, const void* _b) { ImPlotItemGroup* items = GImPlot->SortItems; const int a = *(const int*)_a; @@ -1982,9 +1982,9 @@ bool UpdateInput(ImPlotPlot& plot) { if (any_hov && ImHasFlag(IO.KeyMods, gp.InputMap.ZoomMod)) { float zoom_rate = gp.InputMap.ZoomRate; - if (IO.MouseWheel == 0.0f) - zoom_rate = 0; - else if (IO.MouseWheel > 0) + if (IO.MouseWheel == 0.0f) + zoom_rate = 0; + else if (IO.MouseWheel > 0) zoom_rate = (-zoom_rate) / (1.0f + (2.0f * zoom_rate)); ImVec2 rect_size = plot.PlotRect.GetSize(); float tx = ImRemap(IO.MousePos.x, plot.PlotRect.Min.x, plot.PlotRect.Max.x, 0.0f, 1.0f); @@ -2451,7 +2451,7 @@ bool BeginPlot(const char* title_id, const ImVec2& size, ImPlotFlags flags) { ResetCtxForNextPlot(GImPlot); return false; } - + // setup items (or dont) if (gp.CurrentItems == nullptr) gp.CurrentItems = &plot.Items; @@ -3047,7 +3047,7 @@ void EndPlot() { const bool legend_scrollable = ClampLegendRect(legend.RectClamped, legend_out ? plot.FrameRect : plot.PlotRect, legend_out ? gp.Style.PlotPadding : gp.Style.LegendPadding - ); + ); const ImGuiButtonFlags legend_button_flags = ImGuiButtonFlags_AllowOverlap | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick @@ -3058,7 +3058,7 @@ void EndPlot() { ImGui::KeepAliveID(plot.Items.ID); ImGui::ButtonBehavior(legend.RectClamped, plot.Items.ID, &legend.Hovered, &legend.Held, legend_button_flags); legend.Hovered = legend.Hovered || (ImGui::IsWindowHovered() && legend.RectClamped.Contains(IO.MousePos)); - + if (legend_scrollable) { if (legend.Hovered) { ImGui::SetKeyOwner(ImGuiKey_MouseWheelY, plot.Items.ID); @@ -3069,10 +3069,10 @@ void EndPlot() { legend.Scroll.x += scroll_step * IO.MouseWheel; legend.Scroll.y += scroll_step * IO.MouseWheel; } - } + } const ImVec2 min_scroll_offset = legend.RectClamped.GetSize() - legend.Rect.GetSize(); legend.Scroll.x = ImClamp(legend.Scroll.x, min_scroll_offset.x, 0.0f); - legend.Scroll.y = ImClamp(legend.Scroll.y, min_scroll_offset.y, 0.0f); + legend.Scroll.y = ImClamp(legend.Scroll.y, min_scroll_offset.y, 0.0f); const ImVec2 scroll_offset = legend_horz ? ImVec2(legend.Scroll.x, 0) : ImVec2(0, legend.Scroll.y); ImVec2 legend_offset = legend.RectClamped.Min - legend.Rect.Min + scroll_offset; legend.Rect.Min += legend_offset; @@ -3082,18 +3082,18 @@ void EndPlot() { } const ImU32 col_bg = GetStyleColorU32(ImPlotCol_LegendBg); - const ImU32 col_bd = GetStyleColorU32(ImPlotCol_LegendBorder); - ImGui::PushClipRect(legend.RectClamped.Min, legend.RectClamped.Max, true); - DrawList.AddRectFilled(legend.RectClamped.Min, legend.RectClamped.Max, col_bg); + const ImU32 col_bd = GetStyleColorU32(ImPlotCol_LegendBorder); + ImGui::PushClipRect(legend.RectClamped.Min, legend.RectClamped.Max, true); + DrawList.AddRectFilled(legend.RectClamped.Min, legend.RectClamped.Max, col_bg); bool legend_contextable = ShowLegendEntries(plot.Items, legend.Rect, legend.Hovered, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, !legend_horz, DrawList) - && !ImHasFlag(legend.Flags, ImPlotLegendFlags_NoMenus); + && !ImHasFlag(legend.Flags, ImPlotLegendFlags_NoMenus); DrawList.AddRect(legend.RectClamped.Min, legend.RectClamped.Max, col_bd); ImGui::PopClipRect(); // main ctx menu if (gp.OpenContextThisFrame && legend_contextable && !ImHasFlag(plot.Flags, ImPlotFlags_NoMenus)) - ImGui::OpenPopup("##LegendContext"); - + ImGui::OpenPopup("##LegendContext"); + if (ImGui::BeginPopup("##LegendContext")) { ImGui::Text("Legend"); ImGui::Separator(); if (ShowLegendContextMenu(legend, !ImHasFlag(plot.Flags, ImPlotFlags_NoLegend))) @@ -3566,7 +3566,7 @@ void EndSubplots() { const ImVec2 legend_pos = GetLocationPos(subplot.FrameRect, legend_size, legend.Location, gp.Style.PlotPadding); legend.Rect = ImRect(legend_pos, legend_pos + legend_size); legend.RectClamped = legend.Rect; - const bool legend_scrollable = ClampLegendRect(legend.RectClamped,subplot.FrameRect, gp.Style.PlotPadding); + const bool legend_scrollable = ClampLegendRect(legend.RectClamped,subplot.FrameRect, gp.Style.PlotPadding); const ImGuiButtonFlags legend_button_flags = ImGuiButtonFlags_AllowOverlap | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnDoubleClick @@ -3577,7 +3577,7 @@ void EndSubplots() { ImGui::KeepAliveID(subplot.Items.ID); ImGui::ButtonBehavior(legend.RectClamped, subplot.Items.ID, &legend.Hovered, &legend.Held, legend_button_flags); legend.Hovered = legend.Hovered || (subplot.FrameHovered && legend.RectClamped.Contains(ImGui::GetIO().MousePos)); - + if (legend_scrollable) { if (legend.Hovered) { ImGui::SetKeyOwner(ImGuiKey_MouseWheelY, subplot.Items.ID); @@ -3588,10 +3588,10 @@ void EndSubplots() { legend.Scroll.x += scroll_step * IO.MouseWheel; legend.Scroll.y += scroll_step * IO.MouseWheel; } - } + } const ImVec2 min_scroll_offset = legend.RectClamped.GetSize() - legend.Rect.GetSize(); legend.Scroll.x = ImClamp(legend.Scroll.x, min_scroll_offset.x, 0.0f); - legend.Scroll.y = ImClamp(legend.Scroll.y, min_scroll_offset.y, 0.0f); + legend.Scroll.y = ImClamp(legend.Scroll.y, min_scroll_offset.y, 0.0f); const ImVec2 scroll_offset = legend_horz ? ImVec2(legend.Scroll.x, 0) : ImVec2(0, legend.Scroll.y); ImVec2 legend_offset = legend.RectClamped.Min - legend.Rect.Min + scroll_offset; legend.Rect.Min += legend_offset; @@ -3602,13 +3602,13 @@ void EndSubplots() { const ImU32 col_bg = GetStyleColorU32(ImPlotCol_LegendBg); const ImU32 col_bd = GetStyleColorU32(ImPlotCol_LegendBorder); - ImGui::PushClipRect(legend.RectClamped.Min, legend.RectClamped.Max, true); - DrawList.AddRectFilled(legend.RectClamped.Min, legend.RectClamped.Max, col_bg); + ImGui::PushClipRect(legend.RectClamped.Min, legend.RectClamped.Max, true); + DrawList.AddRectFilled(legend.RectClamped.Min, legend.RectClamped.Max, col_bg); bool legend_contextable = ShowLegendEntries(subplot.Items, legend.Rect, legend.Hovered, gp.Style.LegendInnerPadding, gp.Style.LegendSpacing, !legend_horz, DrawList) && !ImHasFlag(legend.Flags, ImPlotLegendFlags_NoMenus); DrawList.AddRect(legend.RectClamped.Min, legend.RectClamped.Max, col_bd); ImGui::PopClipRect(); - + if (legend_contextable && !ImHasFlag(subplot.Flags, ImPlotSubplotFlags_NoMenus) && ImGui::GetIO().MouseReleased[gp.InputMap.Menu]) ImGui::OpenPopup("##LegendContext"); if (ImGui::BeginPopup("##LegendContext")) { diff --git a/implot_demo.cpp b/implot_demo.cpp index 79064fdf..c72ffd04 100644 --- a/implot_demo.cpp +++ b/implot_demo.cpp @@ -1386,7 +1386,7 @@ void Demo_LegendOptions() { static int num_dummy_items = 25; ImGui::SliderInt("Num Dummy Items (Demo Scrolling)", &num_dummy_items, 0, 100); - + if (ImPlot::BeginPlot("##Legend",ImVec2(-1,0))) { ImPlot::SetupLegend(loc, flags); static MyImPlot::WaveData data1(0.001, 0.2, 4, 0.2); @@ -1405,11 +1405,11 @@ void Demo_LegendOptions() { char label[16]; snprintf(label, sizeof(label), "Item %03d", i+4); ImPlot::PlotDummy(label); - } + } ImPlot::EndPlot(); } -} - +} + //----------------------------------------------------------------------------- void Demo_DragPoints() { diff --git a/implot_internal.h b/implot_internal.h index 8c1650ef..cd05478f 100644 --- a/implot_internal.h +++ b/implot_internal.h @@ -1417,7 +1417,7 @@ IMPLOT_API ImVec2 GetLocationPos(const ImRect& outer_rect, const ImVec2& inner_s // Calculates the bounding box size of a legend _before_ clipping. IMPLOT_API ImVec2 CalcLegendSize(ImPlotItemGroup& items, const ImVec2& pad, const ImVec2& spacing, bool vertical); // Clips calculated legend size -IMPLOT_API bool ClampLegendRect(ImRect& legend_rect, const ImRect& outer_rect, const ImVec2& pad); +IMPLOT_API bool ClampLegendRect(ImRect& legend_rect, const ImRect& outer_rect, const ImVec2& pad); // Renders legend entries into a bounding box IMPLOT_API bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool interactable, const ImVec2& pad, const ImVec2& spacing, bool vertical, ImDrawList& DrawList); // Shows an alternate legend for the plot identified by #title_id, outside of the plot frame (can be called before or after of Begin/EndPlot but must occur in the same ImGui window! This is not thoroughly tested nor scrollable!). diff --git a/implot_items.cpp b/implot_items.cpp index 91c71d82..1871d15c 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -2243,11 +2243,11 @@ double PieChartSum(const T* values, int count, bool ignore_hidden) { template void PlotPieChartEx(const char* const label_ids[], const T* values, int count, ImPlotPoint center, double radius, double angle0, ImPlotPieChartFlags flags) { ImDrawList& draw_list = *GetPlotDrawList(); - + const bool ignore_hidden = ImHasFlag(flags, ImPlotPieChartFlags_IgnoreHidden); const double sum = PieChartSum(values, count, ignore_hidden); const bool normalize = ImHasFlag(flags, ImPlotPieChartFlags_Normalize) || sum > 1.0; - + double a0 = angle0 * 2 * IM_PI / 360.0; double a1 = angle0 * 2 * IM_PI / 360.0; ImPlotPoint Pmin = ImPlotPoint(center.x - radius, center.y - radius);