Compare commits

4 Commits

Author SHA1 Message Date
Ray
f75dbb9a02 Update raygui.h 2026-06-16 11:57:25 +02:00
Ray
14ea4e738b Update raygui.h 2026-06-16 10:51:22 +02:00
Ray
7205d6e119 ADDED: GuiTabBarProperty with runtime GuiTabBar() customization options #460 2026-06-16 10:47:55 +02:00
Ray
dd93c21d01 REVIEWED: GuiLoadIcons() #552 2026-06-16 10:34:18 +02:00

View File

@ -699,7 +699,11 @@ typedef enum {
} GuiValueBoxProperty;
// TabBar
//typedef enum { } GuiTabBarProperty;
typedef enum {
TAB_ITEMS_WIDTH = 16, // TabBar tab items width
TAB_CLOSE_BUTTON, // TabBar tab close button (0-Not shown, 1-Shown)
TAB_LINE_SIDE, // TabBar tabs side (0-Bottom, 1-Top)
} GuiTabBarProperty;
// ListView
typedef enum {
@ -770,6 +774,7 @@ RAYGUIAPI const char *GuiIconText(int iconId, const char *text); // Get text wit
RAYGUIAPI void GuiSetIconScale(int scale); // Set default icon drawing size
RAYGUIAPI unsigned int *GuiGetIcons(void); // Get raygui icons data pointer
RAYGUIAPI char **GuiLoadIcons(const char *fileName, bool loadIconsName); // Load raygui icons file (.rgi) into internal icons data
RAYGUIAPI char **GuiLoadIconsFromMemory(const unsigned char *fileData, int dataSize, bool loadIconsName); // Load raygui icons file (.rgi) from memory into internal icons data
RAYGUIAPI void GuiDrawIcon(int iconId, int posX, int posY, int pixelSize, Color color); // Draw icon using pixel size at specified position
#endif
@ -1089,7 +1094,7 @@ typedef enum {
} GuiIconName;
#endif
#endif
#endif // RAYGUI_NO_ICONS
#if defined(__cplusplus)
} // Prevents name mangling of functions
@ -1424,7 +1429,7 @@ static unsigned int guiIcons[RAYGUI_ICON_MAX_ICONS*RAYGUI_ICON_DATA_ELEMENTS] =
// NOTE: A pointer to current icons array should be defined
static unsigned int *guiIconsPtr = guiIcons;
#endif // !RAYGUI_NO_ICONS && !RAYGUI_CUSTOM_ICONS
#endif // !RAYGUI_NO_ICONS && !RAYGUI_CUSTOM_ICONS
#ifndef RAYGUI_ICON_SIZE
#define RAYGUI_ICON_SIZE 0
@ -1797,20 +1802,17 @@ int GuiPanel(Rectangle bounds, const char *text)
// NOTE: Using GuiToggle() for the TABS
int GuiTabBar(Rectangle bounds, char **text, int count, int *active)
{
#if !defined(RAYGUI_TABBAR_ITEM_WIDTH)
#define RAYGUI_TABBAR_ITEM_WIDTH 148
#endif
int result = -1;
//GuiState state = guiState;
Rectangle tabBounds = { bounds.x, bounds.y, RAYGUI_TABBAR_ITEM_WIDTH, bounds.height };
int tabItemsWidth = GuiGetStyle(TABBAR, TAB_ITEMS_WIDTH);
Rectangle tabBounds = { bounds.x, bounds.y, tabItemsWidth, bounds.height };
if (*active < 0) *active = 0;
else if (*active > count - 1) *active = count - 1;
int offsetX = 0; // Required in case tabs go out of screen
offsetX = (*active*RAYGUI_TABBAR_ITEM_WIDTH) - GetScreenWidth();
offsetX = (*active*tabItemsWidth) - GetScreenWidth();
if (offsetX < 0) offsetX = 0;
bool toggle = false; // Required for individual toggles
@ -1819,7 +1821,7 @@ int GuiTabBar(Rectangle bounds, char **text, int count, int *active)
//--------------------------------------------------------------------
for (int i = 0; i < count; i++)
{
tabBounds.x = bounds.x + (RAYGUI_TABBAR_ITEM_WIDTH + 4)*i + offsetX;
tabBounds.x = bounds.x + (tabItemsWidth + 4)*i + offsetX;
if (tabBounds.x < GetScreenWidth())
{
@ -1847,19 +1849,23 @@ int GuiTabBar(Rectangle bounds, char **text, int count, int *active)
GuiSetStyle(TOGGLE, TEXT_PADDING, textPadding);
GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, textAlignment);
// Draw tab close button
// NOTE: Only draw close button for current tab: if (CheckCollisionPointRec(mousePosition, tabBounds))
int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
int tempTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
GuiSetStyle(BUTTON, BORDER_WIDTH, 1);
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
#if defined(RAYGUI_NO_ICONS)
if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, "x")) result = i;
#else
if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, GuiIconText(ICON_CROSS_SMALL, NULL))) result = i;
#endif
GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment);
if (GuiGetStyle(TABBAR, TAB_CLOSE_BUTTON))
{
// Draw tab close button
// NOTE: Only draw close button for current tab: if (CheckCollisionPointRec(mousePosition, tabBounds))
int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
int tempTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
GuiSetStyle(BUTTON, BORDER_WIDTH, 1);
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
#if defined(RAYGUI_NO_ICONS)
if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 }, "x")) result = i;
#else
if (GuiButton(RAYGUI_CLITERAL(Rectangle){ tabBounds.x + tabBounds.width - 14 - 5, tabBounds.y + 5, 14, 14 },
GuiIconText(ICON_CROSS_SMALL, NULL))) result = i;
#endif
GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlignment);
}
}
}
@ -4803,6 +4809,7 @@ void GuiLoadStyleDefault(void)
GuiSetStyle(VALUEBOX, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
GuiSetStyle(STATUSBAR, TEXT_PADDING, 8);
GuiSetStyle(STATUSBAR, TEXT_ALIGNMENT, TEXT_ALIGN_LEFT);
GuiSetStyle(TABBAR, TAB_ITEMS_WIDTH, 160);
// Initialize extended property values
// NOTE: By default, extended property values are initialized to 0
@ -4893,8 +4900,6 @@ const char *GuiIconText(int iconId, const char *text)
unsigned int *GuiGetIcons(void) { return guiIconsPtr; }
// Load raygui icons file (.rgi)
// NOTE: In case nameIds are required, they can be requested with loadIconsName,
// they are returned as a guiIconsName[iconCount][RAYGUI_ICON_MAX_NAME_LENGTH],
// WARNING: guiIconsName[]][] memory should be manually freed!
char **GuiLoadIcons(const char *fileName, bool loadIconsName)
{
@ -4903,11 +4908,11 @@ char **GuiLoadIcons(const char *fileName, bool loadIconsName)
// Offset | Size | Type | Description
// ------------------------------------------------------
// 0 | 4 | char | Signature: "rGI "
// 4 | 2 | short | Version: 100
// 4 | 2 | short | Version: 100, 500 (raygui 5.0)
// 6 | 2 | short | reserved
// 8 | 2 | short | Num icons (N)
// 10 | 2 | short | Icons size (Options: 16, 32, 64) (S)
// 10 | 2 | short | Icons Size (Options: 16, 32, 64)
// Icons name id (32 bytes per name id)
// foreach (icon)
@ -4916,50 +4921,33 @@ char **GuiLoadIcons(const char *fileName, bool loadIconsName)
// }
// Icons data: One bit per pixel, stored as unsigned int array (depends on icon size)
// S*S pixels/32bit per unsigned int = K unsigned int per icon
// Size*Size pixels/32bit per unsigned int = K unsigned int per icon
// foreach (icon)
// {
// ... | K | unsigned int | Icon Data
// }
FILE *rgiFile = fopen(fileName, "rb");
char **guiIconsName = NULL;
if (rgiFile != NULL)
{
char signature[5] = { 0 };
short version = 0;
short reserved = 0;
short iconCount = 0;
short iconSize = 0;
unsigned char *fileData = NULL;
int dataSize = 0;
fseek(rgiFile, 0, SEEK_END);
int size = (int)ftell(rgiFile);
fseek(rgiFile, 0, SEEK_SET);
fread(signature, 1, 4, rgiFile);
fread(&version, sizeof(short), 1, rgiFile);
fread(&reserved, sizeof(short), 1, rgiFile);
fread(&iconCount, sizeof(short), 1, rgiFile);
fread(&iconSize, sizeof(short), 1, rgiFile);
if ((signature[0] == 'r') &&
(signature[1] == 'G') &&
(signature[2] == 'I') &&
(signature[3] == ' '))
if (size > 0)
{
if (loadIconsName)
{
guiIconsName = (char **)RAYGUI_CALLOC(iconCount, sizeof(char *));
for (int i = 0; i < iconCount; i++)
{
guiIconsName[i] = (char *)RAYGUI_CALLOC(RAYGUI_ICON_MAX_NAME_LENGTH, sizeof(char));
fread(guiIconsName[i], 1, RAYGUI_ICON_MAX_NAME_LENGTH, rgiFile);
}
}
else fseek(rgiFile, iconCount*RAYGUI_ICON_MAX_NAME_LENGTH, SEEK_CUR);
// Read icons data directly over internal icons array
fread(guiIconsPtr, sizeof(unsigned int), (int)iconCount*((int)iconSize*(int)iconSize/32), rgiFile);
fileData = (unsigned char *)RL_CALLOC(size, sizeof(unsigned char));
// WARNING: File can be partially loaded but ignoring it for simplicity
dataSize = fread(fileData, sizeof(unsigned char), size, rgiFile);
guiIconsName = GuiLoadIconsFromMemory(fileData, dataSize, loadIconsName);
}
fclose(rgiFile);
}
@ -4967,7 +4955,7 @@ char **GuiLoadIcons(const char *fileName, bool loadIconsName)
}
// Load icons from memory
// WARNING: Binary files only
// GLOBAL: Updates global variable: guiIconsPtr
char **GuiLoadIconsFromMemory(const unsigned char *fileData, int dataSize, bool loadIconsName)
{
unsigned char *fileDataPtr = (unsigned char *)fileData;
@ -4993,7 +4981,8 @@ char **GuiLoadIconsFromMemory(const unsigned char *fileData, int dataSize, bool
{
if (loadIconsName)
{
guiIconsName = (char **)RAYGUI_CALLOC(iconCount, sizeof(char *));
// NOTE: Always allocating RAYGUI_ICON_MAX_ICONS names slots
guiIconsName = (char **)RAYGUI_CALLOC(RAYGUI_ICON_MAX_ICONS, sizeof(char *));
for (int i = 0; i < iconCount; i++)
{
guiIconsName[i] = (char *)RAYGUI_CALLOC(RAYGUI_ICON_MAX_NAME_LENGTH, sizeof(char));