diff --git a/implot.cpp b/implot.cpp index fd3690db..5594eac0 100644 --- a/implot.cpp +++ b/implot.cpp @@ -3191,7 +3191,8 @@ void EndPlot() { // main ctx menu - if (can_ctx && plot.Hovered) + // if (can_ctx && plot.Hovered) <-- old line // OdehM 2025-02-20 + if (can_ctx && !ImHasFlag(plot.Flags, ImPlotFlags_NoCentralMenu) && plot.Hovered) // <-- new line // OdehM 2025-02-20 ImGui::OpenPopup("##PlotContext"); if (ImGui::BeginPopup("##PlotContext")) { ShowPlotContextMenu(plot); @@ -5860,6 +5861,37 @@ void StyleColorsLight(ImPlotStyle* dst) { colors[ImPlotCol_Crosshairs] = ImVec4(0.00f, 0.00f, 0.00f, 0.50f); } +//----------------------------------------------------------------------------- +// [SECTION] Context Menu // OdehM 2025-02-20 +//----------------------------------------------------------------------------- + +bool BeginCustomContext() +{ + ImPlotContext& gp = *GImPlot; + + if (gp.CurrentPlot == nullptr) return false; + + ImPlotPlot &plot = *gp.CurrentPlot; + + const bool can_ctx = plot.Hovered && + !plot.Items.Legend.Hovered && + !plot.ContextLocked && // <-- added + ImGui::IsMouseReleased(ImGuiMouseButton_Right); + + // main ctx menu + if (can_ctx) + ImGui::OpenPopup("##CustomPlotContext"); + + return ImGui::BeginPopup("##CustomPlotContext"); +} + +void EndCustomContext(bool include_default) +{ + if (include_default) + ShowPlotContextMenu(*(GImPlot->CurrentPlot)); + ImGui::EndPopup(); +} + //----------------------------------------------------------------------------- // [SECTION] Obsolete Functions/Types //----------------------------------------------------------------------------- diff --git a/implot.h b/implot.h index a7961c4f..f54f3815 100644 --- a/implot.h +++ b/implot.h @@ -42,6 +42,7 @@ // [SECTION] Input Mapping // [SECTION] Miscellaneous // [SECTION] Demo +// [SECTION] Context Menu // OdehM 2025-02-20 // [SECTION] Obsolete API #pragma once @@ -139,6 +140,7 @@ enum ImPlotFlags_ { ImPlotFlags_NoFrame = 1 << 6, // the ImGui frame will not be rendered ImPlotFlags_Equal = 1 << 7, // x and y axes pairs will be constrained to have the same units/pixel ImPlotFlags_Crosshairs = 1 << 8, // the default mouse cursor will be replaced with a crosshair when hovered + ImPlotFlags_NoCentralMenu = 1 << 9, // disable the central menu, but allow other menus (such as legends and axis) // OdehM 2025_02_20 ImPlotFlags_CanvasOnly = ImPlotFlags_NoTitle | ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText }; @@ -1247,6 +1249,15 @@ IMPLOT_API void ShowMetricsWindow(bool* p_popen = nullptr); // Shows the ImPlot demo window (add implot_demo.cpp to your sources!) IMPLOT_API void ShowDemoWindow(bool* p_open = nullptr); +//----------------------------------------------------------------------------- +// [SECTION] Context Menu // OdehM 2025-02-20 +//----------------------------------------------------------------------------- + +// Begin a custom central plot context menu +IMPLOT_API bool BeginCustomContext(); +// End a custom central plot context menu +IMPLOT_API void EndCustomContext(bool include_default = false); // if include_default is true, the normal context menu will be appended + } // namespace ImPlot //-----------------------------------------------------------------------------