2019-02-11 09:28:05 +01:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
|
|
|
* raygui - Controls test
|
|
|
|
*
|
|
|
|
* TEST CONTROLS:
|
|
|
|
* - GuiScrollPanel()
|
|
|
|
*
|
|
|
|
* DEPENDENCIES:
|
|
|
|
* raylib 2.4 - Windowing/input management and drawing.
|
|
|
|
* raygui 2.0 - Immediate-mode GUI controls.
|
|
|
|
*
|
|
|
|
* COMPILATION (Windows - MinGW):
|
|
|
|
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
|
|
|
|
*
|
2019-02-12 18:38:47 +02:00
|
|
|
* COMPILATION (Linux - gcc):
|
2021-07-28 12:55:58 +02:00
|
|
|
* gcc -o $(NAME_PART) $(FILE_NAME) -I../../src -lraylib -std=c99
|
2019-02-12 18:38:47 +02:00
|
|
|
*
|
2019-02-11 09:28:05 +01:00
|
|
|
* LICENSE: zlib/libpng
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5)
|
|
|
|
*
|
|
|
|
**********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
|
|
|
|
#define RAYGUI_IMPLEMENTATION
|
2019-08-16 16:07:07 +02:00
|
|
|
#include "../../src/raygui.h"
|
2019-02-11 09:28:05 +01:00
|
|
|
|
2019-04-30 18:46:44 +02:00
|
|
|
|
|
|
|
static void DrawStyleEditControls(void); // Draw and process scroll bar style edition controls
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2019-02-11 09:28:05 +01:00
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Program main entry point
|
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//---------------------------------------------------------------------------------------
|
2019-02-12 18:38:47 +02:00
|
|
|
const int screenWidth = 800;
|
2019-02-11 09:28:05 +01:00
|
|
|
const int screenHeight = 450;
|
|
|
|
|
|
|
|
InitWindow(screenWidth, screenHeight, "raygui - GuiScrollPanel()");
|
|
|
|
|
2019-04-30 18:46:44 +02:00
|
|
|
Rectangle panelRec = { 20, 40, 200, 150 };
|
|
|
|
Rectangle panelContentRec = {0, 0, 340, 340 };
|
|
|
|
Vector2 panelScroll = { 99, -20 };
|
|
|
|
|
|
|
|
bool showContentArea = true;
|
2019-02-11 09:28:05 +01:00
|
|
|
|
|
|
|
SetTargetFPS(60);
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Main game loop
|
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// TODO: Implement required update logic
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
2019-04-30 18:46:44 +02:00
|
|
|
BeginDrawing();
|
|
|
|
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
|
2019-02-11 09:28:05 +01:00
|
|
|
DrawText(TextFormat("[%f, %f]", panelScroll.x, panelScroll.y), 4, 4, 20, RED);
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2019-02-11 09:28:05 +01:00
|
|
|
Rectangle view = GuiScrollPanel(panelRec, panelContentRec, &panelScroll);
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2019-02-11 09:28:05 +01:00
|
|
|
BeginScissorMode(view.x, view.y, view.width, view.height);
|
2019-02-12 18:38:47 +02:00
|
|
|
GuiGrid((Rectangle){panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height}, 16, 3);
|
2019-02-11 09:28:05 +01:00
|
|
|
EndScissorMode();
|
|
|
|
|
2019-04-30 18:46:44 +02:00
|
|
|
if (showContentArea) DrawRectangle(panelRec.x + panelScroll.x, panelRec.y + panelScroll.y, panelContentRec.width, panelContentRec.height, Fade(RED, 0.1));
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2019-04-30 18:46:44 +02:00
|
|
|
DrawStyleEditControls();
|
|
|
|
|
|
|
|
showContentArea = GuiCheckBox((Rectangle){ 565, 80, 20, 20 }, "SHOW CONTENT AREA", showContentArea);
|
|
|
|
|
2021-02-24 09:28:21 +01:00
|
|
|
panelContentRec.width = GuiSliderBar((Rectangle){ 590, 385, 145, 15}, "WIDTH", TextFormat("%i", (int)panelContentRec.width), panelContentRec.width, 1, 600);
|
|
|
|
panelContentRec.height = GuiSliderBar((Rectangle){ 590, 410, 145, 15 }, "HEIGHT", TextFormat("%i", (int)panelContentRec.height), panelContentRec.height, 1, 400);
|
2019-04-30 18:46:44 +02:00
|
|
|
|
|
|
|
EndDrawing();
|
2019-02-11 09:28:05 +01:00
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
CloseWindow(); // Close window and OpenGL context
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
return 0;
|
2019-02-12 18:38:47 +02:00
|
|
|
}
|
|
|
|
|
2019-04-30 18:46:44 +02:00
|
|
|
// Draw and process scroll bar style edition controls
|
|
|
|
static void DrawStyleEditControls(void)
|
2019-02-12 18:38:47 +02:00
|
|
|
{
|
2019-04-30 18:46:44 +02:00
|
|
|
// ScrollPanel style controls
|
|
|
|
//----------------------------------------------------------
|
|
|
|
GuiGroupBox((Rectangle){ 550, 170, 220, 205 }, "SCROLLBAR STYLE");
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2019-04-30 18:33:05 +02:00
|
|
|
int style = GuiGetStyle(SCROLLBAR, BORDER_WIDTH);
|
2019-04-30 18:46:44 +02:00
|
|
|
GuiLabel((Rectangle){ 555, 195, 110, 10 }, "BORDER_WIDTH");
|
2020-02-07 17:13:04 -07:00
|
|
|
GuiSpinner((Rectangle){ 670, 190, 90, 20 }, NULL, &style, 0, 6, false);
|
2019-04-30 18:33:05 +02:00
|
|
|
GuiSetStyle(SCROLLBAR, BORDER_WIDTH, style);
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2019-04-30 18:33:05 +02:00
|
|
|
style = GuiGetStyle(SCROLLBAR, ARROWS_SIZE);
|
2019-04-30 18:46:44 +02:00
|
|
|
GuiLabel((Rectangle){ 555, 220, 110, 10 }, "ARROWS_SIZE");
|
2020-02-07 17:13:04 -07:00
|
|
|
GuiSpinner((Rectangle){ 670, 215, 90, 20 }, NULL, &style, 4, 14, false);
|
2019-04-30 18:33:05 +02:00
|
|
|
GuiSetStyle(SCROLLBAR, ARROWS_SIZE, style);
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2020-02-07 17:13:04 -07:00
|
|
|
style = GuiGetStyle(SCROLLBAR, SLIDER_PADDING);
|
|
|
|
GuiLabel((Rectangle){ 555, 245, 110, 10 }, "SLIDER_PADDING");
|
|
|
|
GuiSpinner((Rectangle){ 670, 240, 90, 20 }, NULL, &style, 0, 14, false);
|
|
|
|
GuiSetStyle(SCROLLBAR, SLIDER_PADDING, style);
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2019-07-05 20:47:15 +02:00
|
|
|
style = GuiCheckBox((Rectangle){ 565, 280, 20, 20 }, "ARROWS_VISIBLE", GuiGetStyle(SCROLLBAR, ARROWS_VISIBLE));
|
|
|
|
GuiSetStyle(SCROLLBAR, ARROWS_VISIBLE, style);
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2019-04-30 18:33:05 +02:00
|
|
|
style = GuiGetStyle(SCROLLBAR, SLIDER_PADDING);
|
2019-04-30 18:46:44 +02:00
|
|
|
GuiLabel((Rectangle){ 555, 325, 110, 10 }, "SLIDER_PADDING");
|
2020-02-07 17:13:04 -07:00
|
|
|
GuiSpinner((Rectangle){ 670, 320, 90, 20 }, NULL, &style, 0, 14, false);
|
2019-04-30 18:33:05 +02:00
|
|
|
GuiSetStyle(SCROLLBAR, SLIDER_PADDING, style);
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2020-02-07 17:13:04 -07:00
|
|
|
style = GuiGetStyle(SCROLLBAR, SLIDER_WIDTH);
|
|
|
|
GuiLabel((Rectangle){ 555, 350, 110, 10 }, "SLIDER_WIDTH");
|
|
|
|
GuiSpinner((Rectangle){ 670, 345, 90, 20 }, NULL, &style, 2, 100, false);
|
|
|
|
GuiSetStyle(SCROLLBAR, SLIDER_WIDTH, style);
|
2019-04-30 18:46:44 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
//----------------------------------------------------------
|
2019-02-12 18:38:47 +02:00
|
|
|
|
2019-04-30 18:46:44 +02:00
|
|
|
// ScrollBar style controls
|
2019-02-12 18:38:47 +02:00
|
|
|
//----------------------------------------------------------
|
2019-04-30 18:46:44 +02:00
|
|
|
GuiGroupBox((Rectangle){ 550, 20, 220, 135 }, "SCROLLPANEL STYLE");
|
2019-02-12 18:38:47 +02:00
|
|
|
|
|
|
|
style = GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH);
|
2019-04-30 18:46:44 +02:00
|
|
|
GuiLabel((Rectangle){ 555, 35, 110, 10 }, "SCROLLBAR_WIDTH");
|
2020-02-07 17:13:04 -07:00
|
|
|
GuiSpinner((Rectangle){ 670, 30, 90, 20 }, NULL, &style, 6, 30, false);
|
2019-02-12 18:38:47 +02:00
|
|
|
GuiSetStyle(LISTVIEW, SCROLLBAR_WIDTH, style);
|
|
|
|
|
|
|
|
style = GuiGetStyle(DEFAULT, BORDER_WIDTH);
|
2019-04-30 18:46:44 +02:00
|
|
|
GuiLabel((Rectangle){ 555, 60, 110, 10 }, "BORDER_WIDTH");
|
2020-02-07 17:13:04 -07:00
|
|
|
GuiSpinner((Rectangle){ 670, 55, 90, 20 }, NULL, &style, 0, 20, false);
|
2019-02-12 18:38:47 +02:00
|
|
|
GuiSetStyle(DEFAULT, BORDER_WIDTH, style);
|
|
|
|
//----------------------------------------------------------
|
2020-02-07 17:13:04 -07:00
|
|
|
}
|