1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-23 02:38:53 -05:00

add legend ctx menu, rev up to 0.9

This commit is contained in:
epezent 2020-11-10 08:27:28 -06:00
parent ad29c9a046
commit 48c0d6fe38
5 changed files with 49 additions and 31 deletions

View File

@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// ImPlot v0.8 WIP // ImPlot v0.9 WIP
/* /*
@ -2010,21 +2010,39 @@ void ShowPlotContextMenu(ImPlotPlot& plot) {
ImGui::Separator(); ImGui::Separator();
if ((ImGui::BeginMenu("Settings"))) { if ((ImGui::BeginMenu("Settings"))) {
if (ImGui::MenuItem("Box Select",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoBoxSelect))) { if (ImGui::MenuItem("Title",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoTitle)))
ImFlipFlag(plot.Flags, ImPlotFlags_NoBoxSelect); ImFlipFlag(plot.Flags, ImPlotFlags_NoTitle);
if ((ImGui::BeginMenu("Legend"))) {
const float s = ImGui::GetFrameHeight();
if (ImGui::RadioButton("H", plot.LegendOrientation == ImPlotOrientation_Horizontal))
plot.LegendOrientation = ImPlotOrientation_Horizontal;
ImGui::SameLine();
if (ImGui::RadioButton("V", plot.LegendOrientation == ImPlotOrientation_Vertical))
plot.LegendOrientation = ImPlotOrientation_Vertical;
ImGui::Checkbox("Outside", &plot.LegendOutside);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(1,1));
if (ImGui::Button("##NW",ImVec2(1.5f*s,s))) plot.LegendLocation = ImPlotLocation_NorthWest; ImGui::SameLine();
if (ImGui::Button("##N", ImVec2(1.5f*s,s))) plot.LegendLocation = ImPlotLocation_North; ImGui::SameLine();
if (ImGui::Button("##NE",ImVec2(1.5f*s,s))) plot.LegendLocation = ImPlotLocation_NorthEast;
if (ImGui::Button("##W", ImVec2(1.5f*s,s))) plot.LegendLocation = ImPlotLocation_West; ImGui::SameLine();
if (ImGui::Button("##C", ImVec2(1.5f*s,s))) plot.LegendLocation = ImPlotLocation_Center; ImGui::SameLine();
if (ImGui::Button("##E", ImVec2(1.5f*s,s))) plot.LegendLocation = ImPlotLocation_East;
if (ImGui::Button("##SW",ImVec2(1.5f*s,s))) plot.LegendLocation = ImPlotLocation_SouthWest; ImGui::SameLine();
if (ImGui::Button("##S", ImVec2(1.5f*s,s))) plot.LegendLocation = ImPlotLocation_South; ImGui::SameLine();
if (ImGui::Button("##SE",ImVec2(1.5f*s,s))) plot.LegendLocation = ImPlotLocation_SouthEast;
ImGui::PopStyleVar();
ImGui::EndMenu();
} }
if (ImGui::MenuItem("Query",NULL,ImHasFlag(plot.Flags, ImPlotFlags_Query))) { if (ImGui::MenuItem("Mouse Position",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoMousePos)))
ImFlipFlag(plot.Flags, ImPlotFlags_Query);
}
if (ImGui::MenuItem("Crosshairs",NULL,ImHasFlag(plot.Flags, ImPlotFlags_Crosshairs))) {
ImFlipFlag(plot.Flags, ImPlotFlags_Crosshairs);
}
if (ImGui::MenuItem("Mouse Position",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoMousePos))) {
ImFlipFlag(plot.Flags, ImPlotFlags_NoMousePos); ImFlipFlag(plot.Flags, ImPlotFlags_NoMousePos);
} if (ImGui::MenuItem("Crosshairs",NULL,ImHasFlag(plot.Flags, ImPlotFlags_Crosshairs)))
if (ImGui::MenuItem("Anti-Aliased Lines",NULL,ImHasFlag(plot.Flags, ImPlotFlags_AntiAliased))) { ImFlipFlag(plot.Flags, ImPlotFlags_Crosshairs);
if (ImGui::MenuItem("Box Select",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoBoxSelect)))
ImFlipFlag(plot.Flags, ImPlotFlags_NoBoxSelect);
if (ImGui::MenuItem("Query",NULL,ImHasFlag(plot.Flags, ImPlotFlags_Query)))
ImFlipFlag(plot.Flags, ImPlotFlags_Query);
if (ImGui::MenuItem("Anti-Aliased Lines",NULL,ImHasFlag(plot.Flags, ImPlotFlags_AntiAliased)))
ImFlipFlag(plot.Flags, ImPlotFlags_AntiAliased); ImFlipFlag(plot.Flags, ImPlotFlags_AntiAliased);
}
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::MenuItem("Legend",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoLegend))) { if (ImGui::MenuItem("Legend",NULL,!ImHasFlag(plot.Flags, ImPlotFlags_NoLegend))) {

View File

@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// ImPlot v0.8 WIP // ImPlot v0.9 WIP
#pragma once #pragma once
#include "imgui.h" #include "imgui.h"
@ -38,7 +38,7 @@
#endif #endif
// ImPlot version string // ImPlot version string
#define IMPLOT_VERSION "0.8 WIP" #define IMPLOT_VERSION "0.9 WIP"
// Indicates variable should deduced automatically. // Indicates variable should deduced automatically.
#define IMPLOT_AUTO -1 #define IMPLOT_AUTO -1
// Special color used to indicate that a color should be deduced automatically. // Special color used to indicate that a color should be deduced automatically.
@ -65,19 +65,19 @@ typedef int ImPlotYAxis; // -> enum ImPlotYAxis_;
// Options for plots. // Options for plots.
enum ImPlotFlags_ { enum ImPlotFlags_ {
ImPlotFlags_None = 0, // default ImPlotFlags_None = 0, // default
ImPlotFlags_NoLegend = 1 << 0, // the top-left legend will not be displayed ImPlotFlags_NoTitle = 1 << 0, // the plot title will not be displayed (titles are also hidden if preceeded by double hashes, e.g. "##MyPlot")
ImPlotFlags_NoMenus = 1 << 1, // the user will not be able to open context menus with double-right click ImPlotFlags_NoLegend = 1 << 1, // the legend will not be displayed
ImPlotFlags_NoBoxSelect = 1 << 2, // the user will not be able to box-select with right-mouse ImPlotFlags_NoMenus = 1 << 2, // the user will not be able to open context menus with double-right click
ImPlotFlags_NoMousePos = 1 << 3, // the mouse position, in plot coordinates, will not be displayed inside of the plot ImPlotFlags_NoBoxSelect = 1 << 3, // the user will not be able to box-select with right-mouse
ImPlotFlags_NoHighlight = 1 << 4, // plot items will not be highlighted when their legend entry is hovered ImPlotFlags_NoMousePos = 1 << 4, // the mouse position, in plot coordinates, will not be displayed inside of the plot
ImPlotFlags_NoChild = 1 << 5, // a child window region will not be used to capture mouse scroll (can boost performance for single ImGui window applications) ImPlotFlags_NoHighlight = 1 << 5, // plot items will not be highlighted when their legend entry is hovered
ImPlotFlags_YAxis2 = 1 << 6, // enable a 2nd y-axis on the right side ImPlotFlags_NoChild = 1 << 6, // a child window region will not be used to capture mouse scroll (can boost performance for single ImGui window applications)
ImPlotFlags_YAxis3 = 1 << 7, // enable a 3rd y-axis on the right side ImPlotFlags_YAxis2 = 1 << 7, // enable a 2nd y-axis on the right side
ImPlotFlags_Query = 1 << 8, // the user will be able to draw query rects with middle-mouse ImPlotFlags_YAxis3 = 1 << 8, // enable a 3rd y-axis on the right side
ImPlotFlags_Crosshairs = 1 << 9, // the default mouse cursor will be replaced with a crosshair when hovered ImPlotFlags_Query = 1 << 9, // the user will be able to draw query rects with middle-mouse
ImPlotFlags_AntiAliased = 1 << 10, // plot lines will be software anti-aliased (not recommended for density plots, prefer MSAA) ImPlotFlags_Crosshairs = 1 << 10, // the default mouse cursor will be replaced with a crosshair when hovered
ImPlotFlags_NoTitle = 1 << 11, // Removes the title from the plot ImPlotFlags_AntiAliased = 1 << 11, // plot lines will be software anti-aliased (not recommended for density plots, prefer MSAA)
ImPlotFlags_CanvasOnly = ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMousePos ImPlotFlags_CanvasOnly = ImPlotFlags_NoTitle | ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMousePos
}; };
// Options for plot axes (X and Y). // Options for plot axes (X and Y).

View File

@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// ImPlot v0.8 WIP // ImPlot v0.9 WIP
#include "implot.h" #include "implot.h"
#include <math.h> #include <math.h>

View File

@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// ImPlot v0.8 WIP // ImPlot v0.9 WIP
// You may use this file to debug, understand or extend ImPlot features but we // You may use this file to debug, understand or extend ImPlot features but we
// don't provide any guarantee of forward compatibility! // don't provide any guarantee of forward compatibility!

View File

@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
// ImPlot v0.8 WIP // ImPlot v0.9 WIP
#include "implot.h" #include "implot.h"
#include "implot_internal.h" #include "implot_internal.h"