text: //
  // Created by Leo on 5/3/2020.
  //
  
  #include <dali/imgui/layer.h>
  #include <dali/app.h>
  
  #include <examples/imgui_impl_glfw.h>
  #include <examples/imgui_impl_opengl3.h>
  
  #include <imgui.h>
  #include <GLFW/glfw3.h>
  #include <glad/glad.h>
  
  namespace dali {
      ImGuiLayer::ImGuiLayer()
              : Layer("ImGuiLayer") {
  
      }
  
      ImGuiLayer::~ImGuiLayer() {
  
      }
  
      void ImGuiLayer::on_attach() {
          // Setup Dear ImGui context
          IMGUI_CHECKVERSION();
          ImGui::CreateContext();
          ImGuiIO &io = ImGui::GetIO();
          (void) io;
          io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;       // Enable Keyboard Controls
          //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;      // Enable Gamepad Controls
          io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;           // Enable Docking
          io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;         // Enable Multi-Viewport / Platform Windows
          //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
          //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
  
          // Setup Dear ImGui style
          ImGui::StyleColorsDark();
          //ImGui::StyleColorsClassic();
  
          // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
          ImGuiStyle &style = ImGui::GetStyle();
          if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
              style.WindowRounding = 0.0f;
              style.Colors[ImGuiCol_WindowBg].w = 1.0f;
          }
  
          App &app = App::get();
          GLFWwindow *window = static_cast<GLFWwindow *>(app.get_window().get_native_window());
  
          // Setup Platform/Renderer bindings
          ImGui_ImplGlfw_InitForOpenGL(window, true);
          ImGui_ImplOpenGL3_Init("#version 410");
      }
  
      void ImGuiLayer::on_detach() {
          ImGui_ImplOpenGL3_Shutdown();
          ImGui_ImplGlfw_Shutdown();
          ImGui::DestroyContext();
      }
  
      void ImGuiLayer::begin() {
          ImGui_ImplOpenGL3_NewFrame();
          ImGui_ImplGlfw_NewFrame();
          ImGui::NewFrame();
      }
  
      void ImGuiLayer::end() {
          ImGuiIO &io = ImGui::GetIO();
          App &app = App::get();
          io.DisplaySize = ImVec2((float) app.get_window().get_width(), (float) app.get_window().get_height());
  
          // Rendering
          ImGui::Render();
          ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
  
          if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
              GLFWwindow *backup_current_context = glfwGetCurrentContext();
              ImGui::UpdatePlatformWindows();
              ImGui::RenderPlatformWindowsDefault();
              glfwMakeContextCurrent(backup_current_context);
          }
      }
  
      void ImGuiLayer::on_imgui_render() {
          static bool show = true;
          ImGui::ShowDemoWindow(&show);
      }
  }