scroll_panel.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*******************************************************************************************
  2. *
  3. * raygui - Controls test
  4. *
  5. * TEST CONTROLS:
  6. * - GuiScrollPanel()
  7. *
  8. * DEPENDENCIES:
  9. * raylib 4.0 - Windowing/input management and drawing.
  10. * raygui 3.0 - Immediate-mode GUI controls.
  11. *
  12. * COMPILATION (Windows - MinGW):
  13. * gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
  14. *
  15. * COMPILATION (Linux - gcc):
  16. * gcc -o $(NAME_PART) $(FILE_NAME) -I../../src -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -std=c99
  17. *
  18. * LICENSE: zlib/libpng
  19. *
  20. * Copyright (c) 2019-2024 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5)
  21. *
  22. **********************************************************************************************/
  23. #include "raylib.h"
  24. #define RAYGUI_IMPLEMENTATION
  25. #include "../../src/raygui.h"
  26. static void DrawStyleEditControls(void); // Draw and process scroll bar style edition controls
  27. //------------------------------------------------------------------------------------
  28. // Program main entry point
  29. //------------------------------------------------------------------------------------
  30. int main()
  31. {
  32. // Initialization
  33. //---------------------------------------------------------------------------------------
  34. const int screenWidth = 800;
  35. const int screenHeight = 450;
  36. InitWindow(screenWidth, screenHeight, "raygui - GuiScrollPanel()");
  37. Rectangle panelRec = { 20, 40, 200, 150 };
  38. Rectangle panelContentRec = {0, 0, 340, 340 };
  39. Rectangle panelView = { 0 };
  40. Vector2 panelScroll = { 99, -20 };
  41. bool showContentArea = true;
  42. SetTargetFPS(60);
  43. //---------------------------------------------------------------------------------------
  44. // Main game loop
  45. while (!WindowShouldClose()) // Detect window close button or ESC key
  46. {
  47. // Update
  48. //----------------------------------------------------------------------------------
  49. // TODO: Implement required update logic
  50. //----------------------------------------------------------------------------------
  51. // Draw
  52. //----------------------------------------------------------------------------------
  53. BeginDrawing();
  54. ClearBackground(RAYWHITE);
  55. DrawText(TextFormat("[%f, %f]", panelScroll.x, panelScroll.y), 4, 4, 20, RED);
  56. GuiScrollPanel(panelRec, NULL, panelContentRec, &panelScroll, &panelView);
  57. BeginScissorMode(panelView.x, panelView.y, panelView.width, panelView.height);
  58. GuiGrid((Rectangle){panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height}, NULL, 16, 3, NULL);
  59. EndScissorMode();
  60. if (showContentArea) DrawRectangle(panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height, Fade(RED, 0.1));
  61. DrawStyleEditControls();
  62. GuiCheckBox((Rectangle){ 565, 80, 20, 20 }, "SHOW CONTENT AREA", &showContentArea);
  63. GuiSliderBar((Rectangle){ 590, 385, 145, 15}, "WIDTH", TextFormat("%i", (int)panelContentRec.width), &panelContentRec.width, 1, 600);
  64. GuiSliderBar((Rectangle){ 590, 410, 145, 15 }, "HEIGHT", TextFormat("%i", (int)panelContentRec.height), &panelContentRec.height, 1, 400);
  65. EndDrawing();
  66. //----------------------------------------------------------------------------------
  67. }
  68. // De-Initialization
  69. //--------------------------------------------------------------------------------------
  70. CloseWindow(); // Close window and OpenGL context
  71. //--------------------------------------------------------------------------------------
  72. return 0;
  73. }
  74. // Draw and process scroll bar style edition controls
  75. static void DrawStyleEditControls(void)
  76. {
  77. // ScrollPanel style controls
  78. //----------------------------------------------------------
  79. GuiGroupBox((Rectangle){ 550, 170, 220, 205 }, "SCROLLBAR STYLE");
  80. int style = GuiGetStyle(SCROLLBAR, BORDER_WIDTH);
  81. GuiLabel((Rectangle){ 555, 195, 110, 10 }, "BORDER_WIDTH");
  82. GuiSpinner((Rectangle){ 670, 190, 90, 20 }, NULL, &style, 0, 6, false);
  83. GuiSetStyle(SCROLLBAR, BORDER_WIDTH, style);
  84. style = GuiGetStyle(SCROLLBAR, ARROWS_SIZE);
  85. GuiLabel((Rectangle){ 555, 220, 110, 10 }, "ARROWS_SIZE");
  86. GuiSpinner((Rectangle){ 670, 215, 90, 20 }, NULL, &style, 4, 14, false);
  87. GuiSetStyle(SCROLLBAR, ARROWS_SIZE, style);
  88. style = GuiGetStyle(SCROLLBAR, SLIDER_PADDING);
  89. GuiLabel((Rectangle){ 555, 245, 110, 10 }, "SLIDER_PADDING");
  90. GuiSpinner((Rectangle){ 670, 240, 90, 20 }, NULL, &style, 0, 14, false);
  91. GuiSetStyle(SCROLLBAR, SLIDER_PADDING, style);
  92. bool scrollBarArrows = GuiGetStyle(SCROLLBAR, ARROWS_VISIBLE);
  93. GuiCheckBox((Rectangle){ 565, 280, 20, 20 }, "ARROWS_VISIBLE", &scrollBarArrows);
  94. GuiSetStyle(SCROLLBAR, ARROWS_VISIBLE, scrollBarArrows);
  95. style = GuiGetStyle(SCROLLBAR, SLIDER_PADDING);
  96. GuiLabel((Rectangle){ 555, 325, 110, 10 }, "SLIDER_PADDING");
  97. GuiSpinner((Rectangle){ 670, 320, 90, 20 }, NULL, &style, 0, 14, false);
  98. GuiSetStyle(SCROLLBAR, SLIDER_PADDING, style);
  99. style = GuiGetStyle(SCROLLBAR, SLIDER_WIDTH);
  100. GuiLabel((Rectangle){ 555, 350, 110, 10 }, "SLIDER_WIDTH");
  101. GuiSpinner((Rectangle){ 670, 345, 90, 20 }, NULL, &style, 2, 100, false);
  102. GuiSetStyle(SCROLLBAR, SLIDER_WIDTH, style);
  103. const char *text = GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE? "SCROLLBAR: LEFT" : "SCROLLBAR: RIGHT";
  104. bool toggleScrollBarSide = GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE);
  105. GuiToggle((Rectangle){ 560, 110, 200, 35 }, text, &toggleScrollBarSide);
  106. GuiSetStyle(LISTVIEW, SCROLLBAR_SIDE, toggleScrollBarSide);
  107. //----------------------------------------------------------
  108. // ScrollBar style controls
  109. //----------------------------------------------------------
  110. GuiGroupBox((Rectangle){ 550, 20, 220, 135 }, "SCROLLPANEL STYLE");
  111. style = GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH);
  112. GuiLabel((Rectangle){ 555, 35, 110, 10 }, "SCROLLBAR_WIDTH");
  113. GuiSpinner((Rectangle){ 670, 30, 90, 20 }, NULL, &style, 6, 30, false);
  114. GuiSetStyle(LISTVIEW, SCROLLBAR_WIDTH, style);
  115. style = GuiGetStyle(DEFAULT, BORDER_WIDTH);
  116. GuiLabel((Rectangle){ 555, 60, 110, 10 }, "BORDER_WIDTH");
  117. GuiSpinner((Rectangle){ 670, 55, 90, 20 }, NULL, &style, 0, 20, false);
  118. GuiSetStyle(DEFAULT, BORDER_WIDTH, style);
  119. //----------------------------------------------------------
  120. }