浏览代码

Merge pull request #27 from Demizdor/update_scrollpanel_example

Updated the scroll panel example
Ray 6 年之前
父节点
当前提交
027ecb35f1
共有 2 个文件被更改,包括 83 次插入15 次删除
  1. 78 12
      examples/gui_scroll_panel.c
  2. 5 3
      src/raygui.h

+ 78 - 12
examples/gui_scroll_panel.c

@@ -12,6 +12,9 @@
 *   COMPILATION (Windows - MinGW):
 *   COMPILATION (Windows - MinGW):
 *       gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
 *       gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
 *
 *
+*   COMPILATION (Linux - gcc):
+*	gcc -o $(NAME_PART) $(FILE_NAME) -I../../src -lraylib -std=c99
+*
 *   LICENSE: zlib/libpng
 *   LICENSE: zlib/libpng
 *
 *
 *   Copyright (c) 2019 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5)
 *   Copyright (c) 2019 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5)
@@ -23,6 +26,10 @@
 #define RAYGUI_IMPLEMENTATION
 #define RAYGUI_IMPLEMENTATION
 #include "../src/raygui.h"
 #include "../src/raygui.h"
 
 
+bool contentArea = true;
+Rectangle panelContentRec = {0, 0, 340, 340 };
+void ChangeStyleUI(void);
+
 //------------------------------------------------------------------------------------
 //------------------------------------------------------------------------------------
 // Program main entry point
 // Program main entry point
 //------------------------------------------------------------------------------------
 //------------------------------------------------------------------------------------
@@ -30,14 +37,13 @@ int main()
 {
 {
     // Initialization
     // Initialization
     //---------------------------------------------------------------------------------------
     //---------------------------------------------------------------------------------------
-    const int screenWidth = 400;
+    const int screenWidth = 800;
     const int screenHeight = 450;
     const int screenHeight = 450;
 
 
     InitWindow(screenWidth, screenHeight, "raygui - GuiScrollPanel()");
     InitWindow(screenWidth, screenHeight, "raygui - GuiScrollPanel()");
     
     
-    Rectangle panelRec = { 20,40,200,150 };
-    Rectangle panelContentRec = { 0,0,340,340 };
-    Vector2 panelScroll = { 99, -20 };
+    Rectangle panelRec = {20, 40, 200, 150 };
+    Vector2 panelScroll = {99, -20};
     
     
     SetTargetFPS(60);
     SetTargetFPS(60);
     //---------------------------------------------------------------------------------------
     //---------------------------------------------------------------------------------------
@@ -52,21 +58,23 @@ int main()
 
 
         // Draw
         // Draw
         //----------------------------------------------------------------------------------
         //----------------------------------------------------------------------------------
-		BeginDrawing();
+	BeginDrawing();
 		
 		
-		ClearBackground(RAYWHITE);
+	    ClearBackground(RAYWHITE);
         
         
             DrawText(TextFormat("[%f, %f]", panelScroll.x, panelScroll.y), 4, 4, 20, RED);
             DrawText(TextFormat("[%f, %f]", panelScroll.x, panelScroll.y), 4, 4, 20, RED);
-
+            
             Rectangle view = GuiScrollPanel(panelRec, panelContentRec, &panelScroll);
             Rectangle view = GuiScrollPanel(panelRec, panelContentRec, &panelScroll);
-
+            
             BeginScissorMode(view.x, view.y, view.width, view.height);
             BeginScissorMode(view.x, view.y, view.width, view.height);
-                GuiGrid((Rectangle){panelRec.x+panelScroll.x, panelRec.y+panelScroll.y, panelContentRec.width, panelContentRec.height}, 16, 3);
+                GuiGrid((Rectangle){panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height}, 16, 3);
             EndScissorMode();
             EndScissorMode();
             
             
-            DrawRectangle(panelRec.x+panelScroll.x, panelRec.y+panelScroll.y, panelContentRec.width, panelContentRec.height, Fade(RED, 0.1));
-                
-		EndDrawing();
+            if(contentArea)
+            	DrawRectangle(panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height, Fade(RED, 0.1));
+            
+            ChangeStyleUI();
+	EndDrawing();
         //----------------------------------------------------------------------------------
         //----------------------------------------------------------------------------------
     }
     }
 
 
@@ -76,4 +84,62 @@ int main()
     //--------------------------------------------------------------------------------------
     //--------------------------------------------------------------------------------------
 
 
     return 0;
     return 0;
+}
+
+void ChangeStyleUI()
+{
+    GuiGroupBox((Rectangle){550,170,220,205}, "SCROLLBAR STYLE");
+    
+    int style = GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER);
+    GuiLabel((Rectangle){555,195,110,10}, "SCROLLBAR_BORDER");
+    GuiSpinner((Rectangle){670,190,90,20}, &style, 0, 6, false);
+    GuiSetStyle(SCROLLBAR, SCROLLBAR_BORDER, style);
+    
+    style = GuiGetStyle(SCROLLBAR, SCROLLBAR_ARROWS_SIZE);
+    GuiLabel((Rectangle){555,220,110,10}, "ARROWS_SIZE");
+    GuiSpinner((Rectangle){670,215,90,20}, &style, 4, 14, false);
+    GuiSetStyle(SCROLLBAR, SCROLLBAR_ARROWS_SIZE, style);
+    
+    style = GuiGetStyle(SCROLLBAR, SCROLLBAR_PADDING);
+    GuiLabel((Rectangle){555,245,110,10}, "SCROLLBAR_PADDING");
+    GuiSpinner((Rectangle){670,240,90,20}, &style, 0, 14, false);
+    GuiSetStyle(SCROLLBAR, SCROLLBAR_PADDING, style);
+    
+    style = GuiCheckBox((Rectangle){565,280,20,20}, "SHOW_SPINNER_BUTTONS", GuiGetStyle(SCROLLBAR, SCROLLBAR_SHOW_SPINNER_BUTTONS));
+    GuiSetStyle(SCROLLBAR, SCROLLBAR_SHOW_SPINNER_BUTTONS, style);
+    
+    style = GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_PADDING);
+    GuiLabel((Rectangle){555,325,110,10}, "SLIDER_PADDING");
+    GuiSpinner((Rectangle){670,320,90,20}, &style, 0, 14, false);
+    GuiSetStyle(SCROLLBAR, SCROLLBAR_SLIDER_PADDING, style);
+    
+    style = GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_SIZE);
+    GuiLabel((Rectangle){555,350,110,10}, "SLIDER_SIZE");
+    GuiSpinner((Rectangle){670,345,90,20}, &style, 2, 100, false);
+    GuiSetStyle(SCROLLBAR, SCROLLBAR_SLIDER_SIZE, style);
+
+    //----------------------------------------------------------
+        
+    GuiGroupBox((Rectangle){550,20,220,135}, "SCROLLPANEL STYLE");
+    
+    style = GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH);
+    GuiLabel((Rectangle){555,35,110,10}, "SCROLLBAR_WIDTH");
+    GuiSpinner((Rectangle){670,30,90,20}, &style, 6, 30, false);
+    GuiSetStyle(LISTVIEW, SCROLLBAR_WIDTH, style);
+    
+    style = GuiGetStyle(DEFAULT, BORDER_WIDTH);
+    GuiLabel((Rectangle){555,60,110,10}, "BORDER_WIDTH");
+    GuiSpinner((Rectangle){670,55,90,20}, &style, 0, 20, false);
+    GuiSetStyle(DEFAULT, BORDER_WIDTH, style);
+    
+    contentArea = GuiCheckBox((Rectangle){565,80,20,20}, "SHOW CONTENT AREA", contentArea);
+    
+    const char* text = GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE ? "SCROLLBAR: LEFT" : "SCROLLBAR: RIGHT";
+    style = GuiToggle((Rectangle){560,110,200,35}, text, GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE));
+    GuiSetStyle(LISTVIEW, SCROLLBAR_SIDE, style);
+    
+    //----------------------------------------------------------
+    
+    panelContentRec.width = GuiSliderBar((Rectangle){590,385,145,15}, "WIDTH", panelContentRec.width, 1, 600, true);
+    panelContentRec.height = GuiSliderBar((Rectangle){590,410,145,15}, "HEIGHT", panelContentRec.height, 1, 400, true);
 }
 }

+ 5 - 3
src/raygui.h

@@ -1994,7 +1994,7 @@ RAYGUIDEF int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxVal
     if (value < minValue) value = minValue;
     if (value < minValue) value = minValue;
     
     
     const int range = maxValue - minValue;
     const int range = maxValue - minValue;
-    
+    int sliderSize = GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_SIZE);
     // Calculate rectangles for all of the components
     // Calculate rectangles for all of the components
     spinnerUpLeft = (Rectangle){ bounds.x + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), bounds.y + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), spinnerSize, spinnerSize };
     spinnerUpLeft = (Rectangle){ bounds.x + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), bounds.y + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), spinnerSize, spinnerSize };
     
     
@@ -2002,13 +2002,15 @@ RAYGUIDEF int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxVal
     {
     {
         spinnerDownRight = (Rectangle){ bounds.x + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), bounds.y + bounds.height - spinnerSize - GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), spinnerSize, spinnerSize};
         spinnerDownRight = (Rectangle){ bounds.x + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), bounds.y + bounds.height - spinnerSize - GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), spinnerSize, spinnerSize};
         scrollbar = (Rectangle){ bounds.x + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_PADDING), spinnerUpLeft.y + spinnerUpLeft.height, bounds.width - 2*(GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_PADDING)), bounds.height - spinnerUpLeft.height - spinnerDownRight.height - 2*GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) };
         scrollbar = (Rectangle){ bounds.x + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_PADDING), spinnerUpLeft.y + spinnerUpLeft.height, bounds.width - 2*(GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_PADDING)), bounds.height - spinnerUpLeft.height - spinnerDownRight.height - 2*GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) };
-        slider = (Rectangle){ bounds.x + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_PADDING),scrollbar.y + (int)(((float)(value - minValue)/range)*(scrollbar.height - GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_SIZE))),bounds.width - 2*(GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_PADDING)), GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_SIZE) };
+        sliderSize = sliderSize >= scrollbar.height ? scrollbar.height - 2 : sliderSize; // Make sure the slider won't get outside of the scrollbar
+        slider = (Rectangle){ bounds.x + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_PADDING),scrollbar.y + (int)(((float)(value - minValue)/range)*(scrollbar.height - sliderSize)),bounds.width - 2*(GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_PADDING)), sliderSize };
     } 
     } 
     else 
     else 
     {
     {
         spinnerDownRight = (Rectangle){ bounds.x + bounds.width - spinnerSize - GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), bounds.y + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), spinnerSize, spinnerSize};
         spinnerDownRight = (Rectangle){ bounds.x + bounds.width - spinnerSize - GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), bounds.y + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), spinnerSize, spinnerSize};
         scrollbar = (Rectangle){ spinnerUpLeft.x + spinnerUpLeft.width, bounds.y + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_PADDING), bounds.width - spinnerUpLeft.width - spinnerDownRight.width - 2*GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), bounds.height - 2*(GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_PADDING))};
         scrollbar = (Rectangle){ spinnerUpLeft.x + spinnerUpLeft.width, bounds.y + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_PADDING), bounds.width - spinnerUpLeft.width - spinnerDownRight.width - 2*GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER), bounds.height - 2*(GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_PADDING))};
-        slider = (Rectangle){ scrollbar.x + (int)(((float)(value - minValue)/range)*(scrollbar.width - GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_SIZE))), bounds.y + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_PADDING), GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_SIZE), bounds.height - 2*(GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_PADDING)) };
+        sliderSize = sliderSize >= scrollbar.width ? scrollbar.width - 2 : sliderSize; // Make sure the slider won't get outside of the scrollbar
+        slider = (Rectangle){ scrollbar.x + (int)(((float)(value - minValue)/range)*(scrollbar.width - sliderSize)), bounds.y + GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_PADDING), sliderSize, bounds.height - 2*(GuiGetStyle(SCROLLBAR, SCROLLBAR_BORDER) + GuiGetStyle(SCROLLBAR, SCROLLBAR_SLIDER_PADDING)) };
     }
     }
     
     
     // Update control
     // Update control