Guest User

ImGui Buttons Example

a guest
Jan 17th, 2023
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | Source Code | 0 0
  1. #include "raylib.h"
  2.  
  3. #include "imgui/imgui.h"
  4. #include "imgui/imgui_internal.h"
  5. #include "rlImGui.h"
  6.  
  7. #include <iostream>
  8. #include <string>
  9. #include <vector>
  10.  
  11.  
  12.  
  13.  
  14. // Variables
  15. int listViewExScrollIndex = 0;
  16. int listViewExActive = 0;
  17. int listViewExFocus = 0;
  18. std::vector<char*> listViewExList;
  19. bool canAddEntity = false;
  20.  
  21.  
  22. std::vector<std::string> entityNames;
  23.  
  24.  
  25.  
  26. int ImGuiListViewEx(std::vector<std::string>& items, int& focus, int& scroll, int& active) {
  27.     ImGui::SetNextWindowSize(ImVec2(400, 200)); // set the container size
  28.  
  29.     ImVec2 screen = ImGui::GetIO().DisplaySize;
  30.     ImVec2 childSize = ImVec2(.2 * screen.x, .7 * screen.y);
  31.     ImGui::BeginChild("Entities List", childSize, true, ImGuiWindowFlags_HorizontalScrollbar);
  32.  
  33.     for (int i = 0; i < 3; i++) {
  34.         if (ImGui::Button("Hello World Button", ImVec2(120,40))) {
  35.             std::cout << "Button Selected is at index: " << i << std::endl;
  36.             focus = i;
  37.             active = i;
  38.         }
  39.     }
  40.  
  41.     ImGui::EndChild();
  42.     return active;
  43. }
  44.  
  45. void EntitiesList()
  46. {
  47.     // Translate the rectangles coordinates to ImGui coordinates
  48.     ImVec2 pos = ImGui::GetCursorScreenPos();
  49.     ImVec2 size = ImGui::GetContentRegionAvail();
  50.     Rectangle rec = { pos.x, pos.y, size.x, size.y };
  51.  
  52.     listViewExActive = ImGuiListViewEx(entityNames, listViewExFocus, listViewExScrollIndex, listViewExActive);      
  53. }
  54.  
  55.  
  56. int main(int argc, char* argv[])
  57. {
  58.     int screenWidth1 = 1900;
  59.     int screenHeight1 = 900;
  60.  
  61.     SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE);
  62.     InitWindow(screenWidth1, screenHeight1, "raylib [ImGui] example - ImGui Demo");
  63.     SetTargetFPS(144);
  64.     rlImGuiSetup(true);
  65.  
  66.  
  67.  
  68.  
  69.     // Init Docking
  70.     ImGui::CreateContext();
  71.     ImGuiIO& io = ImGui::GetIO(); (void)io;
  72.  
  73.     io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;      // Enable Docking
  74.  
  75.     // Main game loop
  76.     while (!WindowShouldClose())
  77.     {
  78.  
  79.         BeginDrawing();
  80.         ClearBackground(DARKGRAY);
  81.  
  82.         // start the GUI
  83.         rlImGuiBegin();
  84.  
  85.  
  86.  
  87.         ImGuiIO& io = ImGui::GetIO();
  88.  
  89.  
  90.         // Entities List
  91.         ImGui::Begin("Entities List Window", NULL);
  92.         EntitiesList();
  93.         ImGui::End();
  94.  
  95.  
  96.  
  97.         // end ImGui
  98.         rlImGuiEnd();
  99.  
  100.         DrawFPS(screenWidth1*.9, screenHeight1*.1);
  101.         // Finish drawing
  102.         EndDrawing();
  103.     }
  104.  
  105.  
  106.  
  107.     rlImGuiShutdown();
  108.     CloseWindow();
  109.  
  110.     return 0;
  111. }
Tags: imgui
Advertisement
Add Comment
Please, Sign In to add comment