1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-10-09 23:57:26 -04:00

add per axis context menus

This commit is contained in:
epezent 2020-08-19 01:18:05 -05:00
parent 53c867f414
commit b409aecd30

View File

@ -1133,7 +1133,7 @@ inline void EndDisabledControls(bool cond) {
} }
} }
inline void AxisMenu(ImPlotAxisState& state) { inline void ShowAxisContextMenu(ImPlotAxisState& state) {
ImGui::PushItemWidth(75); ImGui::PushItemWidth(75);
bool total_lock = state.HasRange && state.RangeCond == ImGuiCond_Always; bool total_lock = state.HasRange && state.RangeCond == ImGuiCond_Always;
bool logscale = ImHasFlag(state.Axis->Flags, ImPlotAxisFlags_LogScale); bool logscale = ImHasFlag(state.Axis->Flags, ImPlotAxisFlags_LogScale);
@ -1177,11 +1177,11 @@ inline void AxisMenu(ImPlotAxisState& state) {
} }
void PlotContextMenu(ImPlotState& plot) { void ShowPlotContextMenu(ImPlotState& plot) {
ImPlotContext& gp = *GImPlot; ImPlotContext& gp = *GImPlot;
if (ImGui::BeginMenu("X-Axis")) { if (ImGui::BeginMenu("X-Axis")) {
ImGui::PushID("X"); ImGui::PushID("X");
AxisMenu(gp.X); ShowAxisContextMenu(gp.X);
ImGui::PopID(); ImGui::PopID();
ImGui::EndMenu(); ImGui::EndMenu();
} }
@ -1200,7 +1200,7 @@ void PlotContextMenu(ImPlotState& plot) {
} }
if (ImGui::BeginMenu(buf)) { if (ImGui::BeginMenu(buf)) {
ImGui::PushID(i); ImGui::PushID(i);
AxisMenu(gp.Y[i]); ShowAxisContextMenu(gp.Y[i]);
ImGui::PopID(); ImGui::PopID();
ImGui::EndMenu(); ImGui::EndMenu();
} }
@ -1486,14 +1486,40 @@ void EndPlot() {
} }
} }
// CONTEXT MENU ----------------------------------------------------------- // CONTEXT MENUS -----------------------------------------------------------
if (ImHasFlag(plot.Flags, ImPlotFlags_ContextMenu) && gp.Hov_Frame && gp.Hov_Plot && IO.MouseDoubleClicked[gp.InputMap.ContextMenuButton] && !hov_legend) if (ImHasFlag(plot.Flags, ImPlotFlags_ContextMenu) && gp.Hov_Frame && gp.Hov_Plot && IO.MouseDoubleClicked[gp.InputMap.ContextMenuButton] && !hov_legend)
ImGui::OpenPopup("##Context"); ImGui::OpenPopup("##PlotContext");
if (ImGui::BeginPopup("##Context")) { if (ImGui::BeginPopup("##PlotContext")) {
PlotContextMenu(plot); ShowPlotContextMenu(plot);
ImGui::EndPopup(); ImGui::EndPopup();
} }
if (ImHasFlag(plot.Flags, ImPlotFlags_ContextMenu) && gp.Hov_Frame && IsPlotXAxisHovered() && IO.MouseDoubleClicked[gp.InputMap.ContextMenuButton] && !hov_legend)
ImGui::OpenPopup("##XContext");
if (ImGui::BeginPopup("##XContext")) {
ImGui::Text("X-Axis"); ImGui::Separator();
ShowAxisContextMenu(gp.X);
ImGui::EndPopup();
}
for (int i = 0; i < IMPLOT_Y_AXES; ++i) {
ImGui::PushID(i);
if (ImHasFlag(plot.Flags, ImPlotFlags_ContextMenu) && gp.Hov_Frame && IsPlotYAxisHovered(i) && IO.MouseDoubleClicked[gp.InputMap.ContextMenuButton] && !hov_legend)
ImGui::OpenPopup("##YContext");
if (ImGui::BeginPopup("##YContext")) {
if (i == 0) {
ImGui::Text("Y-Axis"); ImGui::Separator();
}
else {
ImGui::Text("Y-Axis %d", i + 1); ImGui::Separator();
}
ShowAxisContextMenu(gp.Y[i]);
ImGui::EndPopup();
}
ImGui::PopID();
}
// CLEANUP ---------------------------------------------------------------- // CLEANUP ----------------------------------------------------------------
// reset the plot items for the next frame // reset the plot items for the next frame