Update raylib/raygui to latest master (#231)

This commit is contained in:
Nikolas 2025-03-23 20:01:13 +01:00
parent dfe22275cf
commit e072ff119b
Failed to generate hash of commit
5 changed files with 45 additions and 41 deletions

52
lib/raygui.h vendored
View file

@ -160,6 +160,8 @@
* REVIEWED: GuiIconText(), increase buffer size and reviewed padding
* REVIEWED: GuiDrawText(), improved wrap mode drawing
* REVIEWED: GuiScrollBar(), minor tweaks
* REVIEWED: GuiProgressBar(), improved borders computing
* REVIEWED: GuiTextBox(), multiple improvements: autocursor and more
* REVIEWED: Functions descriptions, removed wrong return value reference
* REDESIGNED: GuiColorPanel(), improved HSV <-> RGBA convertion
*
@ -752,6 +754,7 @@ RAYGUIAPI int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textVal
RAYGUIAPI int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control, updates input text
RAYGUIAPI int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Slider control
RAYGUIAPI int GuiSliderPro(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue, int sliderWidth); // Slider control with extended parameters
RAYGUIAPI int GuiSliderBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Slider Bar control
RAYGUIAPI int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight, float *value, float minValue, float maxValue); // Progress Bar control
RAYGUIAPI int GuiStatusBar(Rectangle bounds, const char *text); // Status Bar control, shows info text
@ -1723,8 +1726,8 @@ int GuiPanel(Rectangle bounds, const char *text)
//--------------------------------------------------------------------
if (text != NULL) GuiStatusBar(statusBar, text); // Draw panel header as status bar
GuiDrawRectangle(bounds, RAYGUI_PANEL_BORDER_WIDTH, GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? (int)BORDER_COLOR_DISABLED: (int)LINE_COLOR)),
GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? BASE_COLOR_DISABLED : BACKGROUND_COLOR)));
GuiDrawRectangle(bounds, RAYGUI_PANEL_BORDER_WIDTH, GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? (int)BORDER_COLOR_DISABLED : (int)LINE_COLOR)),
GetColor(GuiGetStyle(DEFAULT, (state == STATE_DISABLED)? (int)BASE_COLOR_DISABLED : (int)BACKGROUND_COLOR)));
//--------------------------------------------------------------------
return result;
@ -2501,7 +2504,7 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
int wrapMode = GuiGetStyle(DEFAULT, TEXT_WRAP_MODE);
Rectangle textBounds = GetTextBounds(TEXTBOX, bounds);
int textLength = (int)strlen(text); // Get current text length
int textLength = (text != NULL)? (int)strlen(text) : 0; // Get current text length
int thisCursorIndex = textBoxCursorIndex;
if (thisCursorIndex > textLength) thisCursorIndex = textLength;
int textWidth = GetTextWidth(text) - GetTextWidth(text + thisCursorIndex);
@ -2545,10 +2548,8 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
// GLOBAL: Auto-cursor movement logic
// NOTE: Keystrokes are handled repeatedly when button is held down for some time
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_UP) || IsKeyDown(KEY_DOWN) || IsKeyDown(KEY_BACKSPACE) || IsKeyDown(KEY_DELETE)) autoCursorCounter++;
else
{
autoCursorCounter = 0;
}
else autoCursorCounter = 0;
bool autoCursorShouldTrigger = (autoCursorCounter > RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN) && ((autoCursorCounter % RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0);
state = STATE_PRESSED;
@ -2686,8 +2687,8 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
while (offset > 0)
{
prevCodepoint = GetCodepointPrevious(text + offset, &prevCodepointSize);
if (!isspace(prevCodepoint & 0xFF))
break;
if (!isspace(prevCodepoint & 0xFF)) break;
offset -= prevCodepointSize;
accCodepointSize += prevCodepointSize;
}
@ -2697,8 +2698,8 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
while (offset > 0)
{
prevCodepoint = GetCodepointPrevious(text + offset, &prevCodepointSize);
if ((puctuation && !ispunct(prevCodepoint & 0xFF)) || (!puctuation && (isspace(prevCodepoint & 0xFF) || ispunct(prevCodepoint & 0xFF))))
break;
if ((puctuation && !ispunct(prevCodepoint & 0xFF)) || (!puctuation && (isspace(prevCodepoint & 0xFF) || ispunct(prevCodepoint & 0xFF)))) break;
offset -= prevCodepointSize;
accCodepointSize += prevCodepointSize;
}
@ -2735,19 +2736,20 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
while (offset > 0)
{
prevCodepoint = GetCodepointPrevious(text + offset, &prevCodepointSize);
if (!isspace(prevCodepoint & 0xFF))
break;
if (!isspace(prevCodepoint & 0xFF)) break;
offset -= prevCodepointSize;
accCodepointSize += prevCodepointSize;
}
// Check characters of the same type to skip (either ASCII punctuation or anything non-whitespace)
// Not using isalnum() since it only works on ASCII characters
bool puctuation = ispunct(prevCodepoint & 0xFF);
while (offset > 0)
{
prevCodepoint = GetCodepointPrevious(text + offset, &prevCodepointSize);
if ((puctuation && !ispunct(prevCodepoint & 0xFF)) || (!puctuation && (isspace(prevCodepoint & 0xFF) || ispunct(prevCodepoint & 0xFF))))
break;
if ((puctuation && !ispunct(prevCodepoint & 0xFF)) || (!puctuation && (isspace(prevCodepoint & 0xFF) || ispunct(prevCodepoint & 0xFF)))) break;
offset -= prevCodepointSize;
accCodepointSize += prevCodepointSize;
}
@ -2767,23 +2769,25 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
int accCodepointSize = 0;
int nextCodepointSize;
int nextCodepoint;
// Check characters of the same type to skip (either ASCII punctuation or anything non-whitespace)
// Not using isalnum() since it only works on ASCII characters
nextCodepoint = GetCodepointNext(text + offset, &nextCodepointSize);
bool puctuation = ispunct(nextCodepoint & 0xFF);
while (offset < textLength)
{
if ((puctuation && !ispunct(nextCodepoint & 0xFF)) || (!puctuation && (isspace(nextCodepoint & 0xFF) || ispunct(nextCodepoint & 0xFF))))
break;
if ((puctuation && !ispunct(nextCodepoint & 0xFF)) || (!puctuation && (isspace(nextCodepoint & 0xFF) || ispunct(nextCodepoint & 0xFF)))) break;
offset += nextCodepointSize;
accCodepointSize += nextCodepointSize;
nextCodepoint = GetCodepointNext(text + offset, &nextCodepointSize);
}
// Check whitespace to skip (ASCII only)
while (offset < textLength)
{
if (!isspace(nextCodepoint & 0xFF))
break;
if (!isspace(nextCodepoint & 0xFF)) break;
offset += nextCodepointSize;
accCodepointSize += nextCodepointSize;
nextCodepoint = GetCodepointNext(text + offset, &nextCodepointSize);
@ -3371,7 +3375,7 @@ int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight
if (value == NULL) value = &temp;
// Progress bar
Rectangle progress = { bounds.x + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) + GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING),
Rectangle progress = { bounds.x + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH),
bounds.y + GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) + GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING), 0,
bounds.height - GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) - 2*GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING) -1 };
@ -3380,7 +3384,7 @@ int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight
if (*value > maxValue) *value = maxValue;
// WARNING: Working with floats could lead to rounding issues
if ((state != STATE_DISABLED)) progress.width = ((float)*value / (maxValue - minValue)) * (bounds.width - 2 * GuiGetStyle(PROGRESSBAR, BORDER_WIDTH));
if ((state != STATE_DISABLED)) progress.width = ((float)*value/(maxValue - minValue))*(bounds.width - 2*GuiGetStyle(PROGRESSBAR, BORDER_WIDTH));
//--------------------------------------------------------------------
// Draw control
@ -3408,8 +3412,8 @@ int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight
GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + (int)progress.width + (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.y + bounds.height - 1, bounds.width - (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) - (int)progress.width - 1, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_NORMAL)));
GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + bounds.width - (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.y, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.height+GuiGetStyle(PROGRESSBAR, BORDER_WIDTH)-1 }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_NORMAL)));
}
// Draw slider internal progress bar (depends on state)
progress.width -= 2*GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING);
GuiDrawRectangle(progress, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BASE_COLOR_PRESSED)));
}
@ -4568,7 +4572,7 @@ char **GuiLoadIcons(const char *fileName, bool loadIconsName)
// Load icons from memory
// WARNING: Binary files only
char **GuiLoadIconsFromMemory(const unsigned char *fileData, size_t dataSize, bool loadIconsName)
char **GuiLoadIconsFromMemory(const unsigned char *fileData, int dataSize, bool loadIconsName)
{
unsigned char *fileDataPtr = (unsigned char *)fileData;
char **guiIconsName = NULL;
@ -4999,7 +5003,7 @@ static const char *GetTextIcon(const char *text, int *iconId)
}
// Get text divided into lines (by line-breaks '\n')
const char **GetTextLines(const char *text, int *count)
static const char **GetTextLines(const char *text, int *count)
{
#define RAYGUI_MAX_TEXT_LINES 128