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

ImPlotFlags_Crosshairs enables legend after disabling it #266

Open
peterwilson136 opened this issue Jul 10, 2021 · 0 comments
Open

ImPlotFlags_Crosshairs enables legend after disabling it #266

peterwilson136 opened this issue Jul 10, 2021 · 0 comments

Comments

@peterwilson136
Copy link

peterwilson136 commented Jul 10, 2021

In the below code, if you right click the plot and disable the Legend, adding the ImPlotFlags_Crosshairs flag re-enables the Legend icon. I am just wondering if this is a bug or is there a work-around so that I can simply right click to disable the legend and it re-enable in the same way.

#include <GL/glew.h>

#ifndef GLFW_INCLUDE_NONE
#define GLFW_INCLUDE_NONE // GLFW including OpenGL headers causes ambiguity or multiple definition errors.
#endif // GLFW_INCLUDE_NONE

#include <GLFW/glfw3.h>

#include "ImGui/imgui.h"
#include "ImGui/implot.h"
#include "ImGui/implot_internal.h"
#include "ImGui/imgui_impl_glfw.h"
#include "ImGui/imgui_impl_opengl3.h"



int main(int argc, char* argv[])
{
    glfwInit();
    GLFWwindow* window = glfwCreateWindow(1280, 720, "Program", NULL, NULL);
    glfwMakeContextCurrent(window);
    glfwSwapInterval(0); //  vsync

    glewInit();

    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImPlot::CreateContext();

    ImGui::StyleColorsDark();
    ImPlotStyle& ImPlot_Style = ImPlot::GetStyle();
    ImPlot_Style.UseLocalTime = true;

    ImGui_ImplGlfw_InitForOpenGL(window, true);
    ImGui_ImplOpenGL3_Init("#version 460");

    ImPlotFlags flags = ImPlotFlags_None;
    double xs[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    double ys[] = { 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 };


    while (!glfwWindowShouldClose(window))
    {
        glfwPollEvents();

        ImGui_ImplOpenGL3_NewFrame();
        ImGui_ImplGlfw_NewFrame();
        ImGui::NewFrame();

        if (ImPlot::BeginPlot("Plot", nullptr, nullptr, { -1, 0 }, flags)) {
            ImPlot::PlotLine("Line", xs, ys, 10);
            ImPlot::EndPlot();
        }

        if (ImGui::Button("Add crosshair")) {
            flags |= ImPlotFlags_Crosshairs;
        }
        if (ImGui::Button("Remove crosshair")) {
            flags &= ~ImPlotFlags_Crosshairs;
        }
    

        ImGui::Render();
        glClearColor(0.45f, 0.55f, 0.60f, 1.00f);
        glClear(GL_COLOR_BUFFER_BIT);
        ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
        glfwSwapBuffers(window);
    }

    ImGui_ImplOpenGL3_Shutdown();
    ImGui_ImplGlfw_Shutdown();
    ImPlot::DestroyContext();
    ImGui::DestroyContext();

    glfwDestroyWindow(window);
    glfwTerminate();

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant