docking_example.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*******************************************************************************************
  2. *
  3. * raylib-extras [ImGui] example - Docking example
  4. *
  5. * This is an example of using the ImGui docking features that are part of docking branch
  6. * You must replace the default imgui with the code from the docking branch for this to work
  7. * https://github.com/ocornut/imgui/tree/docking
  8. *
  9. * Copyright (c) 2024 Jeffery Myers
  10. *
  11. ********************************************************************************************/
  12. #include "raylib.h"
  13. #include "raymath.h"
  14. #include "imgui.h"
  15. #include "rlImGui.h"
  16. int main(int argc, char* argv[])
  17. {
  18. // Initialization
  19. //--------------------------------------------------------------------------------------
  20. int screenWidth = 1280;
  21. int screenHeight = 800;
  22. SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
  23. InitWindow(screenWidth, screenHeight, "raylib-Extras [ImGui] example - Docking");
  24. SetTargetFPS(144);
  25. rlImGuiSetup(true);
  26. bool run = true;
  27. bool showDemoWindow = true;
  28. // if the linked ImGui has docking, enable it.
  29. // this will only be true if you use the docking branch of ImGui.
  30. #ifdef IMGUI_HAS_DOCK
  31. ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
  32. #endif
  33. // Main game loop
  34. while (!WindowShouldClose() && run) // Detect window close button or ESC key, or a quit from the menu
  35. {
  36. BeginDrawing();
  37. ClearBackground(DARKGRAY);
  38. // start ImGui content
  39. rlImGuiBegin();
  40. // if you want windows to dock to the viewport, call this.
  41. #ifdef IMGUI_HAS_DOCK
  42. ImGui::DockSpaceOverViewport();
  43. #endif
  44. // show a simple menu bar
  45. if (ImGui::BeginMainMenuBar())
  46. {
  47. if (ImGui::BeginMenu("File"))
  48. {
  49. if (ImGui::MenuItem("Quit"))
  50. run = false;
  51. ImGui::EndMenu();
  52. }
  53. if (ImGui::BeginMenu("Window"))
  54. {
  55. if (ImGui::MenuItem("Demo Window", nullptr, showDemoWindow))
  56. showDemoWindow = !showDemoWindow;
  57. ImGui::EndMenu();
  58. }
  59. ImGui::EndMainMenuBar();
  60. }
  61. // show some windows
  62. if (showDemoWindow)
  63. ImGui::ShowDemoWindow(&showDemoWindow);
  64. if (ImGui::Begin("Test Window"))
  65. {
  66. ImGui::TextUnformatted("Another window");
  67. }
  68. ImGui::End();
  69. // end ImGui Content
  70. rlImGuiEnd();
  71. EndDrawing();
  72. //----------------------------------------------------------------------------------
  73. }
  74. rlImGuiShutdown();
  75. // De-Initialization
  76. //--------------------------------------------------------------------------------------
  77. CloseWindow(); // Close window and OpenGL context
  78. //--------------------------------------------------------------------------------------
  79. return 0;
  80. }