controls_test_suite.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*******************************************************************************************
  2. *
  3. * raygui - controls test suite
  4. *
  5. * TEST CONTROLS:
  6. * - GuiDropdownBox()
  7. * - GuiValueBox()
  8. * - GuiSpinner()
  9. * - GuiTextBox()
  10. * - GuiTextBoxMulti()
  11. * - GuiListView()
  12. *
  13. * DEPENDENCIES:
  14. * raylib 2.1 - Windowing/input management and drawing.
  15. * raygui 2.0 - Immediate-mode GUI controls.
  16. *
  17. * COMPILATION (Windows - MinGW):
  18. * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
  19. *
  20. * LICENSE: zlib/libpng
  21. *
  22. * Copyright (c) 2018 raylib technologies (@raylibtech)
  23. *
  24. **********************************************************************************************/
  25. #include "raylib.h"
  26. #define RAYGUI_IMPLEMENTATION
  27. #include "../../src/raygui.h"
  28. //------------------------------------------------------------------------------------
  29. // Program main entry point
  30. //------------------------------------------------------------------------------------
  31. int main()
  32. {
  33. // Initialization
  34. //---------------------------------------------------------------------------------------
  35. int screenWidth = 600;
  36. int screenHeight = 600;
  37. InitWindow(screenWidth, screenHeight, "raygui - controls test suite");
  38. // GUI controls initialization
  39. //----------------------------------------------------------------------------------
  40. int dropdownBox000Active = 0;
  41. const char *dropdownBox000TextList[3] = { "ONE", "TWO", "THREE" };
  42. bool dropDown000EditMode = false;
  43. int dropdownBox001Active = 0;
  44. const char *dropdownBox001TextList[5] = { "ONE", "TWO", "THREE", "FOUR", "FIVE" };
  45. bool dropDown001EditMode = false;
  46. int spinner001Value = 0;
  47. bool spinnerEditMode = false;
  48. int valueBox002Value = 0;
  49. bool valueBoxEditMode = false;
  50. char textBoxText[64] = "Text box";
  51. bool textBoxEditMode = false;
  52. int listViewScrollIndex = 0;
  53. int listViewActive = -1;
  54. const char *listViewList[6] = { "Charmander", "Bulbasaur", "Squirtel", "Pikachu", "Eevee", "Pidgey" };
  55. bool listViewEditMode = false;
  56. int listViewExScrollIndex = 0;
  57. int listViewExActive = -1;
  58. int listViewExFocus = -1;
  59. const char *listViewExList[8] = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" };
  60. int listViewExElementsEnable[8] = {1, 0, 1, 1, 0, 0, 1};
  61. bool listViewExEditMode = false;
  62. char multiTextBoxText[141] = "Multi text box";
  63. bool multiTextBoxEditMode = false;
  64. Color colorPickerValue = RED;
  65. int sliderValue = 50;
  66. int sliderBarValue = 60;
  67. float progressValue = 0.4f;
  68. bool forceSquaredChecked = false;
  69. int comboBoxActive = 1;
  70. int toggleGroupActive = 0;
  71. //----------------------------------------------------------------------------------
  72. // Custom GUI font loading
  73. //Font font = LoadFontEx("fonts/rainyhearts16.ttf", 12, 0, 0);
  74. //GuiFont(font);
  75. SetTargetFPS(60);
  76. //--------------------------------------------------------------------------------------
  77. // Main game loop
  78. while (!WindowShouldClose()) // Detect window close button or ESC key
  79. {
  80. // Update
  81. //----------------------------------------------------------------------------------
  82. // TODO: Implement required update logic
  83. //----------------------------------------------------------------------------------
  84. // Draw
  85. //----------------------------------------------------------------------------------
  86. BeginDrawing();
  87. ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
  88. // raygui: controls drawing
  89. //----------------------------------------------------------------------------------
  90. if (dropDown000EditMode || dropDown001EditMode) GuiLock();
  91. //GuiDisable();
  92. // First GUI column
  93. forceSquaredChecked = GuiCheckBoxEx((Rectangle){ 25, 108, 15, 15 }, forceSquaredChecked, "Force Square");
  94. if (GuiSpinner((Rectangle){ 25, 135, 125, 30 }, &spinner001Value, 0, 100, 25, spinnerEditMode)) spinnerEditMode = !spinnerEditMode;
  95. if (GuiValueBox((Rectangle){ 25, 175, 125, 30 }, &valueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode;
  96. if (GuiTextBox((Rectangle){ 25, 215, 125, 30 }, textBoxText, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;
  97. if (GuiButton((Rectangle){ 25, 255, 125, 30 }, "SAMPLE TEXT")) { }
  98. GuiGroupBox((Rectangle){ 25, 310, 125, 150 }, "CONTROL STATES");
  99. GuiLock();
  100. GuiState(GUI_STATE_NORMAL); if (GuiButton((Rectangle){ 30, 320, 115, 30 }, "NORMAL")) { }
  101. GuiState(GUI_STATE_FOCUSED); if (GuiButton((Rectangle){ 30, 355, 115, 30 }, "FOCUSED")) { }
  102. GuiState(GUI_STATE_PRESSED); if (GuiButton((Rectangle){ 30, 390, 115, 30 }, "PRESSED")) { }
  103. GuiState(GUI_STATE_DISABLED); if (GuiButton((Rectangle){ 30, 425, 115, 30 }, "DISABLED")) { }
  104. GuiState(GUI_STATE_NORMAL);
  105. GuiUnlock();
  106. comboBoxActive = GuiComboBox((Rectangle){ 25, 470, 125, 30 }, dropdownBox001TextList, 5, comboBoxActive);
  107. // NOTE: GuiDropdownBox must draw after any other control that can be covered on unfolding
  108. if (GuiDropdownBox((Rectangle){ 25, 65, 125, 30 }, dropdownBox001TextList, 5, &dropdownBox001Active, dropDown001EditMode)) dropDown001EditMode = !dropDown001EditMode;
  109. if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, dropdownBox000TextList, 3, &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode;
  110. // Second GUI column
  111. if (GuiListView((Rectangle){ 165, 25, 140, 140 }, listViewList, 6, &listViewScrollIndex, &listViewActive, listViewEditMode)) listViewEditMode = !listViewEditMode;
  112. if (GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, listViewExElementsEnable, 8, &listViewExScrollIndex, &listViewExActive, &listViewExFocus, listViewExEditMode)) listViewExEditMode = !listViewExEditMode;
  113. if (listViewExFocus >= 0 && listViewExFocus < 8) DrawText(FormatText("FOCUS: %s", listViewExList[listViewExFocus]), 165, 390, 10, listViewExElementsEnable[listViewExFocus] ? LIME : MAROON);
  114. toggleGroupActive = GuiToggleGroupPro((Rectangle){ 165, 400, 140, 25 }, dropdownBox001TextList, 4, toggleGroupActive, 4, 1);
  115. // Third GUI column
  116. if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
  117. colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, colorPickerValue);
  118. sliderValue = GuiSliderEx((Rectangle){ 320, 400, 200, 20 }, sliderValue, -50, 100, " ", true);
  119. sliderBarValue = GuiSliderBarEx((Rectangle){ 320, 430, 200, 20 }, sliderBarValue, 0, 100, " ", true);
  120. progressValue = GuiProgressBarEx((Rectangle){ 320, 460, 200, 20 }, progressValue, 0, 1, true);
  121. //GuiEnable();
  122. GuiUnlock();
  123. //----------------------------------------------------------------------------------
  124. EndDrawing();
  125. //----------------------------------------------------------------------------------
  126. }
  127. // De-Initialization
  128. //--------------------------------------------------------------------------------------
  129. CloseWindow(); // Close window and OpenGL context
  130. //--------------------------------------------------------------------------------------
  131. return 0;
  132. }