diff --git a/implot.cpp b/implot.cpp index f2f7f40c..6c474db8 100644 --- a/implot.cpp +++ b/implot.cpp @@ -3236,7 +3236,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); @@ -5890,6 +5891,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 87825ed2..79e56103 100644 --- a/implot.h +++ b/implot.h @@ -43,6 +43,7 @@ // [SECTION] Input Mapping // [SECTION] Miscellaneous // [SECTION] Demo +// [SECTION] Context Menu // OdehM 2025-02-20 // [SECTION] Obsolete API #pragma once @@ -162,6 +163,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 }; @@ -1274,7 +1276,7 @@ IMPLOT_API void BustColorCache(const char* plot_title_id = nullptr); //----------------------------------------------------------------------------- // [SECTION] Input Mapping //----------------------------------------------------------------------------- - + // Provides access to input mapping structure for permanent modifications to controls for pan, select, etc. IMPLOT_API ImPlotInputMap& GetInputMap(); @@ -1319,6 +1321,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 //----------------------------------------------------------------------------- diff --git a/implot_items.cpp b/implot_items.cpp index 1af0cd2c..50ed5c62 100644 --- a/implot_items.cpp +++ b/implot_items.cpp @@ -3015,6 +3015,7 @@ void PlotDigitalEx(const char* label_id, Getter getter, const ImPlotSpec& spec) // do not extend plot outside plot range pMin.x = ImClamp(pMin.x, !x_axis.IsInverted() ? x_axis.PixelMin : x_axis.PixelMax, !x_axis.IsInverted() ? x_axis.PixelMax - 1 : x_axis.PixelMin - 1); pMax.x = ImClamp(pMax.x, !x_axis.IsInverted() ? x_axis.PixelMin : x_axis.PixelMax, !x_axis.IsInverted() ? x_axis.PixelMax - 1 : x_axis.PixelMin - 1); + //plot a rectangle that extends up to x2 with y1 height if ((gp.CurrentPlot->PlotRect.Contains(pMin) || gp.CurrentPlot->PlotRect.Contains(pMax))) { // ImVec4 colAlpha = item->Color;