Review examples to latest raygui

This commit is contained in:
Ray 2019-08-16 16:07:07 +02:00
parent b51ab5b0e7
commit 4ac6419e7e
7 changed files with 47 additions and 42 deletions

View File

@ -148,9 +148,7 @@ int main()
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER);
//if (GuiButton((Rectangle){ 25, 255, 125, 30 }, "#05#Open File")) { };
if (GuiButton((Rectangle){ 25, 255, 125, 30 }, GuiIconText(RICON_FILE_OPEN, "Open File"))) { };
if (GuiButton((Rectangle){ 25, 255, 125, 30 }, GuiIconText(RICON_FILE_SAVE, "Save File"))) showTextInputBox = true;
GuiGroupBox((Rectangle){ 25, 310, 125, 150 }, "STATES");
GuiLock();
@ -180,7 +178,7 @@ int main()
if (GuiTextBoxMulti((Rectangle){ 320, 25, 225, 140 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
colorPickerValue = GuiColorPicker((Rectangle){ 320, 185, 196, 192 }, colorPickerValue);
sliderValue = GuiSlider((Rectangle){ 370, 400, 200, 20 }, "#49#TEST", sliderValue, -50, 100, true);
sliderValue = GuiSlider((Rectangle){ 370, 400, 200, 20 }, TextFormat("%2.2f", (float)sliderValue), sliderValue, -50, 100, true);
sliderBarValue = GuiSliderBar((Rectangle){ 320, 430, 200, 20 }, NULL, sliderBarValue, 0, 100, true);
progressValue = GuiProgressBar((Rectangle){ 320, 460, 200, 20 }, NULL, progressValue, 0, 1, true);

View File

@ -40,7 +40,6 @@ typedef struct {
bool fileDialogActive;
bool dirBackPressed;
bool dirPathEditMode;
char dirPathText[256];
@ -106,7 +105,7 @@ void GuiFileDialog(GuiFileDialogState *state);
************************************************************************************/
#if defined(GUI_FILE_DIALOG_IMPLEMENTATION)
#include "raygui.h"
#include "../../src/raygui.h"
#include <string.h> // Required for: strcpy()
@ -157,7 +156,6 @@ GuiFileDialogState InitGuiFileDialog(void)
state.position = (Vector2){ GetScreenWidth()/2 - 480/2, GetScreenHeight()/2 - 305/2 };
state.fileDialogActive = false;
state.dirBackPressed = false;
state.dirPathEditMode = false;
state.filesListActive = -1;
@ -303,7 +301,10 @@ void GuiFileDialog(GuiFileDialogState *state)
}
}
}
else strcpy(state->fileNameText, state->fileNameTextCopy);
else
{
strcpy(state->fileNameText, state->fileNameTextCopy);
}
}
state->fileNameEditMode = !state->fileNameEditMode;

View File

@ -18,6 +18,7 @@
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
#define RAYGUI_SUPPORT_RICONS
#include "../../src/raygui.h"
@ -44,6 +45,7 @@ int main(int argc, char *argv[0])
int pixelFormatActive = 0;
const char *pixelFormatTextList[7] = { "GRAYSCALE", "GRAY ALPHA", "R5G6B5", "R8G8B8", "R5G5B5A1", "R4G4B4A4", "R8G8B8A8" };
bool textBoxEditMode = false;
char fileName[32] = "untitled";
//--------------------------------------------------------------------------------------
@ -168,7 +170,7 @@ int main(int argc, char *argv[0])
GuiLabel((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 70, 63, 25 }, "Pixel format:");
pixelFormatActive = GuiComboBox((Rectangle){ windowBoxRec.x + 80, windowBoxRec.y + 70, 130, 25 }, TextJoin(pixelFormatTextList, 7, ";"), pixelFormatActive);
GuiLabel((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 105, 50, 25 }, "File name:");
GuiTextBox((Rectangle){ windowBoxRec.x + 80, windowBoxRec.y + 105, 130, 25 }, fileName, 64, true);
if (GuiTextBox((Rectangle){ windowBoxRec.x + 80, windowBoxRec.y + 105, 130, 25 }, fileName, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;
btnExport = GuiButton((Rectangle){ windowBoxRec.x + 10, windowBoxRec.y + 145, 200, 30 }, "Export Image");
}

View File

@ -18,7 +18,8 @@
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
#define RAYGUI_SUPPORT_RICONS
#include "../../src/raygui.h"
#include <string.h> // Required for: strcpy()
#include <stdlib.h> // Required for: atoi()

View File

@ -18,7 +18,7 @@
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
#include "../../src/raygui.h"
//------------------------------------------------------------------------------------
// Program main entry point

View File

@ -24,7 +24,7 @@
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
#include "../src/raygui.h"
#include "../../src/raygui.h"
static void DrawStyleEditControls(void); // Draw and process scroll bar style edition controls

View File

@ -24,9 +24,9 @@
#include "raylib.h"
#define RAYGUI_IMPLEMENTATION
#define RAYGUI_RICONS_SUPPORT
#define RAYGUI_SUPPORT_RICONS
#define RAYGUI_TEXTBOX_EXTENDED
#include "../src/raygui.h"
#include "../../src/raygui.h"
#include <stdio.h>
#include <limits.h>
@ -57,7 +57,6 @@ struct {
{ .bounds = (Rectangle){680,60,100,25}, .maxWidth = 100 }
};
int fontSize = 10, fontSpacing = 1, padding = 0, border = 0;
Font font = {0};
Color colorBG = {0}, colorFG = {0}, *colorSelected = NULL;
@ -66,8 +65,6 @@ bool showMenu = false;
Rectangle menuRect = {0};
Texture2D pattern = {0};
// -----------------
// FUNCTIONS
// -----------------
@ -94,7 +91,7 @@ bool ColorButton(Rectangle bounds, Color color)
void UpdateGUI()
{
// Check all of the 4 textboxes to get the active textbox
for(int i=0; i<SIZEOF(textbox); ++i)
for (int i = 0; i < SIZEOF(textbox); i++)
{
if (GuiTextBoxIsActive(textbox[i].bounds))
{
@ -105,22 +102,27 @@ void UpdateGUI()
// Show/Hide the textbox menu
Vector2 mouse = GetMousePosition();
if(textboxActive < 2 && !showMenu && CheckCollisionPointRec(mouse, textbox[textboxActive].bounds) && IsMouseButtonPressed(MOUSE_RIGHT_BUTTON))
if ((textboxActive < 2) && !showMenu && CheckCollisionPointRec(mouse, textbox[textboxActive].bounds) && IsMouseButtonPressed(MOUSE_RIGHT_BUTTON))
{
showMenu = true;
menuRect = (Rectangle){mouse.x, mouse.y, 80, 110};
}
// code for hiding the menu
// Menu hidding logic
if (showMenu && IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !CheckCollisionPointRec(mouse, menuRect)) showMenu = false;
// HANDLE DROPPED FONT FILES, IF ANY
// Fonts drag & drop logic
if (IsFileDropped())
{
int count = 0;
char **files = GetDroppedFiles(&count);
if(IsFileExtension(files[0], ".ttf") || IsFileExtension(files[0], ".fnt"))
if (IsFileExtension(files[0], ".ttf") ||
IsFileExtension(files[0], ".otf") ||
IsFileExtension(files[0], ".fnt"))
{
Font fnt = LoadFont(files[0]);
if (fnt.texture.id != 0)
{
// Font was loaded, only change font on success
@ -132,6 +134,7 @@ void UpdateGUI()
font = fnt;
}
}
ClearDroppedFiles();
}
}
@ -167,7 +170,7 @@ void DrawGUI()
int maxSize = (textboxActive == 1) ? SIZEOF(text1) : SIZEOF(text0);
for (int i=0, j=0; i < maxSize; ++i, j+=3)
{
sprintf(&hex[j], "%02hhX ", (char)text[i]);
sprintf(&hex[j], "%02Xh ", (char)text[i]);
}
int startIdx = 0, endIdx = 0;
@ -189,7 +192,7 @@ void DrawGUI()
int enabledItems[] = { textboxActive < 2 ? 1 : 0, textboxActive < 2 ? 1 : 0, GetClipboardText() != NULL, 1 };
int active=-1, focus=0, scroll=0;
GuiSetStyle(DEFAULT, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT); // Fixes visual glitch with other alignments
GuiListViewEx(menuRect, menuItems, SIZEOF(menuItems), enabledItems, &active, &focus, &scroll, true);
active = GuiListViewEx(menuRect, menuItems, SIZEOF(menuItems), &focus, &scroll, active);
if (active != -1)
{
showMenu = false;
@ -265,7 +268,7 @@ int main(int argc, char **argv)
// Load initial style
GuiLoadStyleDefault();
//font = LoadFont("/home/adrian/Descărcări/raylib/examples/text/resources/notoCJK.fnt");
//font = LoadFont("resources/notoCJK.fnt");
//GuiFont(font);
fontSize = GuiGetStyle(DEFAULT, TEXT_SIZE);