Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BeginPopupContextLegend and EndPopup #105

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions implot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,25 @@ void EndLegendDragDropSource() {
ImGui::EndDragDropSource();
}

bool BeginPopupContextLegend(const char* label_id, ImGuiMouseButton mouse_button) {
ImPlotContext& gp = *GImPlot;
IM_ASSERT_USER_ERROR(gp.CurrentPlot != NULL, "BeginLegendPopup() needs to be called between BeginPlot() and EndPlot()!");
ImGuiWindow* window = GImGui->CurrentWindow;
if (window->SkipItems)
return false;
ImGuiID id = ImGui::GetID(label_id);
if (ImGui::IsMouseReleased(mouse_button)) {
ImPlotItem* item = gp.CurrentPlot->Items.GetByKey(id);
if (item && item->Highlight)
ImGui::OpenPopupEx(id);
}
return ImGui::BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings);
}

void EndPopup() {
ImGui::EndPopup();
}

//-----------------------------------------------------------------------------
// STYLING
//-----------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions implot.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,11 @@ bool BeginLegendDragDropSource(const char* label_id, ImGuiDragDropFlags flags =
// End legend drag and drop source.
void EndLegendDragDropSource();

// Begin a popup for a legend entry.
bool BeginPopupContextLegend(const char* label_id, ImGuiMouseButton mouse_button = 1);
// End a popup for a legend entry.
void EndPopup();

//-----------------------------------------------------------------------------
// Miscellaneous
//-----------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions implot_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,19 @@ void ShowDemoWindow(bool* p_open) {
ys2[i] = xs2[i] * xs2[i];
}
ImGui::BulletText("Anti-aliasing can be enabled from the plot's context menu (see Help).");
ImGui::BulletText("Right click on a legend item to bring up its context menu");
if (ImPlot::BeginPlot("Line Plot", "x", "f(x)")) {
ImPlot::PlotLine("sin(x)", xs1, ys1, 1001);
ImPlot::SetNextMarkerStyle(ImPlotMarker_Circle);
ImPlot::PlotLine("x^2", xs2, ys2, 11);
if (ImPlot::BeginPopupContextLegend("sin(x)")) {
ImGui::Text("Context menu for sin(x)");
ImPlot::EndPopup();
}
if (ImPlot::BeginPopupContextLegend("x^2")) {
ImGui::Text("Context menu for x^2");
ImPlot::EndPopup();
}
ImPlot::EndPlot();
}
}
Expand Down