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,8 +170,8 @@ 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");
}
else btnExport = false;

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,9 +91,9 @@ 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))
if (GuiTextBoxIsActive(textbox[i].bounds))
{
textboxActive = i;
break;
@ -105,33 +102,39 @@ 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
if(showMenu && IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !CheckCollisionPointRec(mouse, menuRect)) showMenu = false;
// HANDLE DROPPED FONT FILES, IF ANY
if(IsFileDropped())
// Menu hidding logic
if (showMenu && IsMouseButtonPressed(MOUSE_LEFT_BUTTON) && !CheckCollisionPointRec(mouse, menuRect)) showMenu = false;
// Fonts drag & drop logic
if (IsFileDropped())
{
int count = 0;
char** files = GetDroppedFiles(&count);
if(IsFileExtension(files[0], ".ttf") || IsFileExtension(files[0], ".fnt"))
char **files = GetDroppedFiles(&count);
if (IsFileExtension(files[0], ".ttf") ||
IsFileExtension(files[0], ".otf") ||
IsFileExtension(files[0], ".fnt"))
{
Font fnt = LoadFont(files[0]);
if(fnt.texture.id != 0)
if (fnt.texture.id != 0)
{
// Font was loaded, only change font on success
GuiFont(fnt);
fontSize = fnt.baseSize;
// Remove old font
if(font.texture.id != 0) UnloadFont(font);
if (font.texture.id != 0) UnloadFont(font);
font = fnt;
}
}
ClearDroppedFiles();
}
}
@ -141,7 +144,7 @@ void DrawGUI()
{
// DRAW TEXTBOXES TO TEST
// Set custom style for textboxes
if(font.texture.id != 0) GuiFont(font); // Use our custom font if valid
if (font.texture.id != 0) GuiFont(font); // Use our custom font if valid
GuiSetStyle(DEFAULT, TEXT_SIZE, fontSize);
GuiSetStyle(DEFAULT, TEXT_SPACING, fontSpacing);
GuiSetStyle(TEXTBOX, INNER_PADDING, padding);
@ -165,13 +168,13 @@ void DrawGUI()
char hex[(((textboxActive == 1) ? SIZEOF(text1) : SIZEOF(text0)) +1)*3 + 1];
char* text = (textboxActive == 1) ? text1 : text0;
int maxSize = (textboxActive == 1) ? SIZEOF(text1) : SIZEOF(text0);
for(int i=0, j=0; i < maxSize; ++i, j+=3)
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;
if(textboxActive < 2)
if (textboxActive < 2)
{
Vector2 sel = GuiTextBoxGetSelection();
startIdx = GuiTextBoxGetByteIndex(text, 0, 0, sel.x);
@ -182,15 +185,15 @@ void DrawGUI()
// DISPLAY A MENU ON RIGHT CLICKING A TEXTBOX
// draw the menu and handle clicked item
if(showMenu)
if (showMenu)
{
GuiSetStyle(LISTVIEW, ELEMENTS_HEIGHT, 24); // make items look a little bigger
const char* menuItems[] = { "#17# Cut", "#16# Copy", "#18# Paste", "#101# SelectAll" };
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);
if(active != -1)
active = GuiListViewEx(menuRect, menuItems, SIZEOF(menuItems), &focus, &scroll, active);
if (active != -1)
{
showMenu = false;
char* text = (textboxActive == 1) ? text1 : text0;
@ -226,20 +229,20 @@ void DrawGUI()
int width = textbox[textboxActive].bounds.width, height = textbox[textboxActive].bounds.height;
GuiGroupBox((Rectangle){430,320,175,100}, GuiIconText(RICON_CURSOR_SCALE, "SCALE"));
GuiLabel((Rectangle){435,340,55,20}, "Width");
if(GuiSpinner((Rectangle){495,340,100,20}, &width, 30, textbox[textboxActive].maxWidth, true)) changed = true;
if (GuiSpinner((Rectangle){495,340,100,20}, &width, 30, textbox[textboxActive].maxWidth, true)) changed = true;
GuiLabel((Rectangle){435,380,55,20}, "Height");
if(GuiSpinner((Rectangle){495,380,100,20}, &height, 12, TEXTBOX_MAX_HEIGHT, true)) changed = true;
if (GuiSpinner((Rectangle){495,380,100,20}, &height, 12, TEXTBOX_MAX_HEIGHT, true)) changed = true;
GuiSetStyle(LABEL, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER);
GuiLabel((Rectangle){30,290,740,10}, GuiIconText(RICON_TEXT_T, " DRAG A FONT FILE (*.TTF, *.FNT) ANYWHERE TO CHANGE THE DEFAULT FONT!"));
GuiSetStyle(LABEL, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT);
textbox[textboxActive].bounds.y = 85 - height;
textbox[textboxActive].bounds.height = height;
textbox[textboxActive].bounds.width = width;
if(changed) GuiTextBoxSetActive(textbox[textboxActive].bounds);
if (changed) GuiTextBoxSetActive(textbox[textboxActive].bounds);
// UI for selecting the selected text background and foreground color
if(ColorButton((Rectangle){625,320,30,30}, colorFG)) colorSelected = &colorFG;
if(ColorButton((Rectangle){625,389,30,30}, colorBG)) colorSelected = &colorBG;
if (ColorButton((Rectangle){625,320,30,30}, colorFG)) colorSelected = &colorFG;
if (ColorButton((Rectangle){625,389,30,30}, colorBG)) colorSelected = &colorBG;
*colorSelected = GuiColorPicker((Rectangle){660,320,90,85}, *colorSelected);
float alpha = colorSelected->a;
GuiSetStyle(SLIDER, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_LEFT); // Slider for the selected color alpha value
@ -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);