int _main(lp3::core::PlatformLoop & loop) { core::LogSystem log; sdl::SDL2 sdl2(SDL_INIT_VIDEO); LP3_LOG_DEBUG("Initializing Window"); gfx::Window window("Lp3 ImGui Demo", glm::vec2{ 1280, 720 }); //// TODO: Could these move to after the window is created? //SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); //SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); //SDL_DisplayMode current; //SDL_GetCurrentDisplayMode(0, ¤t); /*sdl::GLContext gl_context = SDL_GL_CreateContext(window); if (SDL_GL_MakeCurrent(window, gl_context) < 0) { LP3_LOG_ERROR("Error creating GL %s", SDL_GetError()); } lp3::gl::initialize();*/ LP3_LOG_DEBUG("Initializing ImGuiApp"); lp3::imgui::ImGuiApp imgui(window); bool g_show_test_window = true; bool g_show_another_window = false; return loop.run([&]() { const ImVec4 g_clear_color = ImColor(114, 144, 154); bool g_done = false; SDL_Event event; while (SDL_PollEvent(&event)) { imgui.process_event(event); if (event.type == SDL_QUIT) g_done = true; } imgui.new_frame(window); // 1. Show a simple window // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" { static float f = 0.0f; ImGui::Text("Hello, world!"); ImGui::SliderFloat("float", &f, 0.0f, 1.0f); ImGui::ColorEdit3("clear color", (float*)&g_clear_color); if (ImGui::Button("Test Window")) g_show_test_window ^= 1; if (ImGui::Button("Another Window")) g_show_another_window ^= 1; ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); } // 2. Show another simple window, this time using an explicit Begin/End pair if (g_show_another_window) { ImGui::SetNextWindowSize(ImVec2(200,100), ImGuiSetCond_FirstUseEver); ImGui::Begin("Another Window", &g_show_another_window); ImGui::Text("Hello"); ImGui::End(); } // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() if (g_show_test_window) { ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver); ImGui::ShowDemoWindow(&g_show_test_window); } // Rendering glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y); glClearColor(g_clear_color.x, g_clear_color.y, g_clear_color.z, g_clear_color.w); glClear(GL_COLOR_BUFFER_BIT); window.render([](const glm::mat4 &) { ImGui::Render(); }); return !g_done; }); }
void imgui( ParamList& plist, float cursorPos ) { static bool opendemo=true; std::string id = plist.getPath() + "_ID"; ImGui::PushID(id.c_str()); //ImGui::BeginChild(id.c_str()); //"content"); float cposyPrev = ImGui::GetCursorPosY(); bool vis; if (plist.hasOption("hidden")) vis = ImGui::CollapsingHeader(plist.getName().c_str(), ImGuiTreeNodeFlags_AllowItemOverlap); //, NULL, true, true); else vis = ImGui::CollapsingHeader(plist.getName().c_str(), ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_DefaultOpen); //, NULL, true, true); float cposyNext = ImGui::GetCursorPosY(); //ImGUi::SetCursorPosY(cposyPrev); //SameLine(); //ImGui::PushItemWidth(-10); // in cm_imgui_app if (!plist.hasOption("child")) { extern ImFont * iconFont; ImGui::PushFont(iconFont); ImGui::PushID("btns"); ImGui::SameLine(ImGui::GetWindowWidth()-100); if(ImGui::ButtonEx("l", ImVec2(0,0), ImGuiButtonFlags_PressedOnClick)) // Hack default onRelease with Button does not seem to work { std::string path; if(openFileDialog(path,"xml")) plist.loadXml(path.c_str()); } //ImGui::NextColumn(); ImGui::SameLine(); if(ImGui::ButtonEx("s",ImVec2(0,0), ImGuiButtonFlags_PressedOnClick))//, ImVec2(100,20))) { std::string path; if(saveFileDialog(path,"xml")) plist.saveXml(path.c_str()); } ImGui::PopID(); ImGui::PopFont(); } //ImGui::PopItemWidth(); if(!vis) { //ImGui::EndChild(); ImGui::PopID(); return; } //if(!) //ImGui::OpenNextNode(true); //if(!ImGui::TreeNode(plist.getName().c_str())) for( int i = 0; i < plist.getNumParams(); i++ ) { Param * p = plist.getParam(i); if(p->hasOption("h")) continue; if(p->hasOption("sameline")) ImGui::SameLine(); imgui(p); } for( int i = 0; i < plist.getNumChildren(); i++ ) { ImGui::Indent(); imgui(*plist.getChild(i), cursorPos+10.0 ); ImGui::Unindent(); } //ImGui::TreePop(); ImGui::PopID(); //ImGui::EndChild(); }