Reviewed examples for latest raygui/raylib

This commit is contained in:
raysan5
2021-10-05 14:10:35 +02:00
parent 0ed765cd8b
commit 7c63e389b8
11 changed files with 73 additions and 52 deletions

View File

@ -1,24 +1,23 @@
/*******************************************************************************************
*
* raygui - a custom property list control
* raygui - custom property list control
*
* DEPENDENCIES:
* raylib 3.0
* raygui 2.7
* raylib 4.0 - Windowing/input management and drawing.
* raygui 3.0 - Immediate-mode GUI controls.
*
* COMPILATION (Windows - MinGW):
* gcc -o $(NAME_PART).exe $(FILE_NAME) -I../../src -lraylib -lopengl32 -lgdi32 -std=c99
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2020 Vlad Adrian (@Demizdor - https://github.com/Demizdor)
* Copyright (c) 2020-2021 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5)
*
**********************************************************************************************/
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
#define RAYGUI_SUPPORT_RICONS
#include "../../src/raygui.h"
#undef RAYGUI_IMPLEMENTATION // Avoid including raygui implementation again
@ -26,8 +25,6 @@
#define GUI_PROPERTY_LIST_IMPLEMENTATION
#include "dm_property_list.h"
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 450
#define SIZEOF(A) (sizeof(A)/sizeof(A[0]))
//------------------------------------------------------------------------------------
@ -37,7 +34,11 @@ int main()
{
// Initialization
//---------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raygui - property list");
GuiDMProperty prop[] = {
PBOOL("Bool", 0, true),
PSECTION("#102#SECTION", 0, 2),
@ -52,17 +53,17 @@ int main()
PVEC4("Vec4", 0, 12, 13, 14, 15),
PCOLOR("Color", 0, 0, 255, 0, 255),
};
int focus = 0, scroll = 0; // needed by GuiDMPropertyList()
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "raygui - property list");
SetTargetFPS(60);
int focus = 0, scroll = 0; // Needed by GuiDMPropertyList()
GuiLoadStyleDefault();
// adjust the default raygui style a bit
// Tweak the default raygui style a bit
GuiSetStyle(LISTVIEW, LIST_ITEMS_HEIGHT, 24);
GuiSetStyle(LISTVIEW, SCROLLBAR_WIDTH, 12);
//--------------------------------------------------------------------------------------
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
@ -70,11 +71,12 @@ int main()
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
GuiGrid((Rectangle){0,0,SCREEN_WIDTH,SCREEN_HEIGHT},20.0f, 2); // draw a fancy grid
GuiGrid((Rectangle){0, 0, screenWidth, screenHeight},20.0f, 2); // Draw a fancy grid
GuiDMPropertyList((Rectangle){(SCREEN_WIDTH - 180)/2, (SCREEN_HEIGHT - 280)/2, 180, 280}, prop, SIZEOF(prop), &focus, &scroll);
GuiDMPropertyList((Rectangle){(screenWidth - 180)/2, (screenHeight - 280)/2, 180, 280}, prop, SIZEOF(prop), &focus, &scroll);
if (prop[0].value.vbool >= 1)
{
@ -84,9 +86,13 @@ int main()
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
GuiDMSaveProperties("test.props", prop, SIZEOF(prop)); // Save properties to `test.props` file at exit
CloseWindow(); // Close window and OpenGL context
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}