Skip to content

Add custom right-click context menu#613

Open
moe93 wants to merge 24 commits intoepezent:masterfrom
moe93:custom-context-menu
Open

Add custom right-click context menu#613
moe93 wants to merge 24 commits intoepezent:masterfrom
moe93:custom-context-menu

Conversation

@moe93
Copy link

@moe93 moe93 commented Feb 20, 2025

Closes #530

Usage:

if (ImPlot::BeginPlot("My Plot", ImVec2(-1, 0), ImPlotFlags_NoCentralMenu))
{
    // Plot things before

    if (ImPlot::BeginCustomContext())
    {
        if (ImGui::MenuItem("My Custom Item")) doThing();
        ImPlot::EndCustomContext(true); // true = append standard menu
    }
    ImPlot::EndPlot();

    // Plot things after
}

This is the work of @PapaNaxos. I just packaged it and created the PR.

Pass ImPlotFlags_NoCentralMenu to BeginPlot()

Usage BeginCustomContext(){ ...; EndCustomContext() } within BeginPlot()
@brenocq brenocq self-requested a review November 7, 2025 04:50
@brenocq brenocq added prio:high High priority status:review The task is under review type:feat New feature or request labels Nov 7, 2025
@PapaNaxos
Copy link

PapaNaxos commented Nov 11, 2025

I originally made this comment on the associated issue, but maybe it's better to put here.

I do wonder if ImPlotFlags_NoCentralMenu is the most intuitive flag name or not...

Even though I wrote it, I don't find it particularly obvious that THAT flag is what is required to use a custom context menu 😅

Perhaps
ImPlotFlags_HasCustomContext
ImPlotFlags_UseCustomContext
ImPlotFlags_CustomContext
?

@PapaNaxos
Copy link

Does 'assigned' mean I need to do... something?

@brenocq
Copy link
Collaborator

brenocq commented Dec 21, 2025

Does 'assigned' mean I need to do... something?

Huehuehe if I leave comments while reviewing you might want to do... something :)

Actually, I don't think you can modify the code in this PR, right? Damn GitHub

@brenocq
Copy link
Collaborator

brenocq commented Dec 21, 2025

I'm trying to think on how to make the custom context menus more flexible. Right now, depending on where the user clicks (plot, axis, legend), a different context menu is shown. So I would suggest allowing the user specify which context menu they want to customize. Additionally, we should expose the ShowDefault*ContextMenu to the user so they can keep the default context menu content if wanted. It should look something like this:

if (ImPlot::BeginPlot("My Plot", ImVec2(-1, 0)))
{
    // Plot things before

    if (ImPlot::BeginPlotContextMenu())
    {
        if (ImGui::MenuItem("My Custom Item")) doThing();
        ImGui::Separator();
        ImPlot::ShowDefaultPlotContextMenu();
        ImPlot::EndPlotContextMenu();
    }
    
    if (ImPlot::BeginAxisContextMenu(ImAxis_X1))
    {
        ImGui::Text("Overwritten X Axis Context Menu");
        ImPlot::EndAxisContextMenu();
    }

    if (ImPlot::BeginLegendContextMenu())
    {
        ImGui::Text("My Legend Items:");
        ImPlot::ShowDefaultLegendContextMenu();
        ImPlot::EndLegendContextMenu();
    }
    
    ImPlot::EndPlot();
}

I don't really love that it is a bit verbose, but it makes the behavior quite clear (hopefully). Let me know what you guys think! @moe93 @PapaNaxos

@moe93
Copy link
Author

moe93 commented Dec 21, 2025

I am of the opinion that having context menus appear based on what item is clicked is more practical.
It does make the intent more clear and allows for a more intuitive behavior in terms of the end-user.

For instance, when plotting vibration data, I allow the users to choose whether to display the x-axis in RPMs, Hz, or seconds. Their biggest gripe was that they expected to find those choices when right-clicking the x-axis, and NOT within the custom context menu found by right-clicking the plot area.
I wholeheartedly agree with their sentiment.

@PapaNaxos
Copy link

That's a far better interface I think!

@WhatWhatz
Copy link

WhatWhatz commented Feb 5, 2026

Any updates on when this will be merged/modified?

ocornut and others added 16 commits February 14, 2026 09:33
The MacOS build was failing because CMAKE < 3.5 is no longer supported
…zent#641)

Modifies implot.h DragPoint, DragLineX, DragLineY, DragRect functions held argument to out_held.
The last parameter is called out_held in the implementation cpp file.
This change brings that to the header, provides clearer understanding for the user.

Co-authored-by: Breno Cunha Queiroz <[email protected]>
The default constructors for ImPlotPointError, ImPlotTag, and ImPlotTick were missing.
* Add IMPLOT_API to constructors and functions of ImPlotPoint, ImPlotRange, and ImPlotRect

* fix: missing IMPLOT_API in locator functions

---------

Co-authored-by: Alex Swaim <[email protected]>
Co-authored-by: Breno Cunha Queiroz <[email protected]>
* Add ImPlotLegendFlags_Reverse

This is handy for making the order of legend items match the order of the data in stacked plots.
See epezent#292

---------

Co-authored-by: Breno Cunha Queiroz <[email protected]>
* PlotDigital : Fix Digital plots do not respect axis inversion

epezent#520

* fix: digital plot demo not spanning whole x-axis

* fix: digital plots disappearing on y-axis inversion

---------

Co-authored-by: Breno Cunha Queiroz <[email protected]>
The demo used hardcoded pixel values for several plots which didn't scale
with DPI, causing them to appear too small on high-DPI displays.

Following ImGui's convention, this commit replaces hardcoded pixel values
with ImGui::GetTextLineHeight() multiplied by appropriate factors. This
ensures plots scale correctly with font size and DPI settings.

Affected plots:
- PolitiFact: Who Lies More? (400px -> 25*TextLineHeight)
- Pie charts (250x250px -> 16*TextLineHeight square)
- Heatmaps (225x225px -> 14*TextLineHeight square)
- Scrolling/Rolling plots (150px -> 10*TextLineHeight)
- DragRects/DragPoints plots (150px -> 10*TextLineHeight)
- Drag and Drop plots (195px -> 13*TextLineHeight)

This follows the same pattern used throughout ImGui's demo code for
ensuring DPI-aware sizing.

Co-authored-by: Breno Cunha Queiroz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

prio:high High priority status:review The task is under review type:feat New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add items to context menu