Compare commits

..

3 Commits

View File

@ -1,6 +1,6 @@
/*******************************************************************************************
*
* raygui v4.5-dev - A simple and easy-to-use immediate-mode gui library
* raygui v5.0-dev - A simple and easy-to-use immediate-mode gui library
*
* DESCRIPTION:
* raygui is a tools-dev-focused immediate-mode-gui library based on raylib but also
@ -83,8 +83,8 @@
* used for all controls, when any of those base values is set, it is automatically populated to all
* controls, so, specific control values overwriting generic style should be set after base values
*
* After the first BASE set we have the EXTENDED properties (by default guiStyle[16..23]), those
* properties are actually common to all controls and can not be overwritten individually (like BASE ones)
* After the first BASE properties set, the EXTENDED properties set is defined (by default guiStyle[16..23]),
* those properties are actually common to all controls and can not be overwritten individually (like BASE ones)
* Some of those properties are: TEXT_SIZE, TEXT_SPACING, LINE_COLOR, BACKGROUND_COLOR
*
* Custom control properties can be defined using the EXTENDED properties for each independent control.
@ -141,13 +141,14 @@
* Draw text bounds rectangles for debug
*
* VERSIONS HISTORY:
* 5.0 (xx-Nov-2025) ADDED: Support up to 32 controls (v500)
* 5.0 (xx-Mar-2026) ADDED: Support up to 32 controls (v500)
* ADDED: guiControlExclusiveMode and guiControlExclusiveRec for exclusive modes
* ADDED: GuiValueBoxFloat()
* ADDED: GuiDropdonwBox() properties: DROPDOWN_ARROW_HIDDEN, DROPDOWN_ROLL_UP
* ADDED: GuiListView() property: LIST_ITEMS_BORDER_WIDTH
* ADDED: GuiLoadIconsFromMemory()
* ADDED: Multiple new icons
* ADDED: Macros for inputs customization, raylib decoupling
* REMOVED: GuiSpinner() from controls list, using BUTTON + VALUEBOX properties
* REMOVED: GuiSliderPro(), functionality was redundant
* REVIEWED: Controls using text labels to use LABEL properties
@ -165,6 +166,7 @@
* REVIEWED: GuiTextBox(), multiple improvements: autocursor and more
* REVIEWED: Functions descriptions, removed wrong return value reference
* REDESIGNED: GuiColorPanel(), improved HSV <-> RGBA convertion
* REDESIGNED: WARNING: TEXT_LINE_SPACING does not consider text height, only lines spacing
*
* 4.0 (12-Sep-2023) ADDED: GuiToggleSlider()
* ADDED: GuiColorPickerHSV() and GuiColorPanelHSV()
@ -355,7 +357,7 @@
#elif defined(USE_LIBTYPE_SHARED)
#define RAYGUIAPI __declspec(dllimport) // Using the library as a Win32 shared library (.dll)
#endif
#define _CRT_SECURE_NO_WARNINGS // disable unsafe warnings on scanf functions in MSVC
#define _CRT_SECURE_NO_WARNINGS // Disable unsafe warnings on scanf() functions in MSVC
#endif
// Function specifiers definition
@ -375,6 +377,45 @@
#define RAYGUI_LOG(...)
#endif
// Macros to define required UI inputs, including mapping to gamepad controls
// TODO: Define additionally required macros for missing inputs
#if !defined(GUI_BUTTON_DOWN)
#define GUI_BUTTON_DOWN (IsMouseButtonDown(MOUSE_LEFT_BUTTON) || IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
#endif
#if !defined(GUI_BUTTON_DOWN_ALT)
// Mapping to alternative button down pressed
#define GUI_BUTTON_DOWN_ALT (IsMouseButtonDown(MOUSE_RIGHT_BUTTON) || IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_FACE_RIGHT))
#endif
#if !defined(GUI_BUTTON_PRESSED)
#define GUI_BUTTON_PRESSED (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsGamepadButtonPressed(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
#endif
// TODO: WARNING: GuiTabBar() still requires IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)
#if !defined(GUI_BUTTON_RELEASED)
#define GUI_BUTTON_RELEASED (IsMouseButtonReleased(MOUSE_LEFT_BUTTON) || IsGamepadButtonReleased(0, GAMEPAD_BUTTON_RIGHT_FACE_DOWN))
#endif
#if !defined(GUI_SCROLL_DELTA)
// Mapping to scroll delta changes
// TODO: Review inconsistencies between platforms
#if defined(PLATFORM_WEB)
// NOTE: Gamepad axis triggers not detected on web platform
#define GUI_SCROLL_DELTA ((float)IsGamepadButtonDown(0, GAMEPAD_BUTTON_RIGHT_TRIGGER_2) - (float)IsGamepadButtonDown(0, GAMEPAD_BUTTON_LEFT_TRIGGER_2))
#else
#define GUI_SCROLL_DELTA (GetMouseWheelMove() + (GetGamepadAxisMovement(0, GAMEPAD_AXIS_RIGHT_TRIGGER) + 1) - (GetGamepadAxisMovement(0, GAMEPAD_AXIS_LEFT_TRIGGER) + 1))
#endif
#endif
#if !defined(GUI_POINTER_POSITION)
#define GUI_POINTER_POSITION GetMousePosition()
#endif
#if !defined(GUI_KEY_DOWN)
#define GUI_KEY_DOWN(key) IsKeyDown(key)
#endif
#if !defined(GUI_KEY_PRESSED)
#define GUI_KEY_PRESSED(key) IsKeyPressed(key)
#endif
#if !defined(GUI_INPUT_KEY)
#define GUI_INPUT_KEY GetCharPressed()
#endif
//----------------------------------------------------------------------------------
// Types and Structures Definition
// NOTE: Some types are required for RAYGUI_STANDALONE usage
@ -568,7 +609,7 @@ typedef enum {
//----------------------------------------------------------------------------------
// DEFAULT extended properties
// NOTE: Those properties are common to all controls or global
// WARNING: We only have 8 slots for those properties by default!!! -> New global control: TEXT?
// WARNING: Only 8 slots vailable for those properties by default
typedef enum {
TEXT_SIZE = 16, // Text size (glyphs max height)
TEXT_SPACING, // Text spacing between glyphs
@ -1451,12 +1492,12 @@ static bool IsMouseButtonReleased(int button);
static bool IsKeyDown(int key);
static bool IsKeyPressed(int key);
static int GetCharPressed(void); // -- GuiTextBox(), GuiValueBox()
static int GetCharPressed(void); // -- GuiTextBox(), GuiValueBox()
//-------------------------------------------------------------------------------
// Drawing required functions
//-------------------------------------------------------------------------------
static void DrawRectangle(int x, int y, int width, int height, Color color); // -- GuiDrawRectangle()
static void DrawRectangle(int x, int y, int width, int height, Color color); // -- GuiDrawRectangle()
static void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4); // -- GuiColorPicker()
//-------------------------------------------------------------------------------
@ -1521,11 +1562,11 @@ static Color GuiFade(Color color, float alpha); // Fade color by an alph
// Gui Setup Functions Definition
//----------------------------------------------------------------------------------
// Enable gui global state
// NOTE: We check for STATE_DISABLED to avoid messing custom global state setups
// NOTE: Checking for STATE_DISABLED to avoid messing custom global state setups
void GuiEnable(void) { if (guiState == STATE_DISABLED) guiState = STATE_NORMAL; }
// Disable gui global state
// NOTE: We check for STATE_NORMAL to avoid messing custom global state setups
// NOTE: Checking for STATE_NORMAL to avoid messing custom global state setups
void GuiDisable(void) { if (guiState == STATE_NORMAL) guiState = STATE_DISABLED; }
// Lock gui global state
@ -1558,9 +1599,8 @@ void GuiSetFont(Font font)
{
if (font.texture.id > 0)
{
// NOTE: If we try to setup a font but default style has not been
// lazily loaded before, it will be overwritten, so we need to force
// default style loading first
// NOTE: If a font is tried to be set but default style has not been lazily loaded first,
// it will be overwritten, so default style loading needs to be forced first
if (!guiStyleLoaded) GuiLoadStyleDefault();
guiFont = font;
@ -1787,7 +1827,7 @@ int GuiTabBar(Rectangle bounds, const char **text, int count, int *active)
}
// Close tab with middle mouse button pressed
if (CheckCollisionPointRec(GetMousePosition(), tabBounds) && IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) result = i;
if (CheckCollisionPointRec(GUI_POINTER_POSITION, tabBounds) && IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) result = i;
GuiSetStyle(TOGGLE, TEXT_PADDING, textPadding);
GuiSetStyle(TOGGLE, TEXT_ALIGNMENT, textAlignment);
@ -1886,37 +1926,37 @@ int GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
// Check button state
if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
if (GUI_BUTTON_DOWN) state = STATE_PRESSED;
else state = STATE_FOCUSED;
#if defined(SUPPORT_SCROLLBAR_KEY_INPUT)
if (hasHorizontalScrollBar)
{
if (IsKeyDown(KEY_RIGHT)) scrollPos.x -= GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
if (IsKeyDown(KEY_LEFT)) scrollPos.x += GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
if (GUI_KEY_DOWN(KEY_RIGHT)) scrollPos.x -= GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
if (GUI_KEY_DOWN(KEY_LEFT)) scrollPos.x += GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
}
if (hasVerticalScrollBar)
{
if (IsKeyDown(KEY_DOWN)) scrollPos.y -= GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
if (IsKeyDown(KEY_UP)) scrollPos.y += GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
if (GUI_KEY_DOWN(KEY_DOWN)) scrollPos.y -= GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
if (GUI_KEY_DOWN(KEY_UP)) scrollPos.y += GuiGetStyle(SCROLLBAR, SCROLL_SPEED);
}
#endif
float wheelMove = GetMouseWheelMove();
float scrollDelta = GUI_SCROLL_DELTA;
// Set scrolling speed with mouse wheel based on ratio between bounds and content
Vector2 mouseWheelSpeed = { content.width/bounds.width, content.height/bounds.height };
if (mouseWheelSpeed.x < RAYGUI_MIN_MOUSE_WHEEL_SPEED) mouseWheelSpeed.x = RAYGUI_MIN_MOUSE_WHEEL_SPEED;
if (mouseWheelSpeed.y < RAYGUI_MIN_MOUSE_WHEEL_SPEED) mouseWheelSpeed.y = RAYGUI_MIN_MOUSE_WHEEL_SPEED;
Vector2 scrollSpeed = { content.width/bounds.width, content.height/bounds.height };
if (scrollSpeed.x < RAYGUI_MIN_MOUSE_WHEEL_SPEED) scrollSpeed.x = RAYGUI_MIN_MOUSE_WHEEL_SPEED;
if (scrollSpeed.y < RAYGUI_MIN_MOUSE_WHEEL_SPEED) scrollSpeed.y = RAYGUI_MIN_MOUSE_WHEEL_SPEED;
// Horizontal and vertical scrolling with mouse wheel
if (hasHorizontalScrollBar && (IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_LEFT_SHIFT))) scrollPos.x += wheelMove*mouseWheelSpeed.x;
else scrollPos.y += wheelMove*mouseWheelSpeed.y; // Vertical scroll
if (hasHorizontalScrollBar && (GUI_KEY_DOWN(KEY_LEFT_CONTROL) || GUI_KEY_DOWN(KEY_LEFT_SHIFT))) scrollPos.x += scrollDelta*scrollSpeed.x;
else scrollPos.y += scrollDelta*scrollSpeed.y; // Vertical scroll
}
}
@ -2002,15 +2042,15 @@ int GuiButton(Rectangle bounds, const char *text)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
// Check button state
if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
if (GUI_BUTTON_DOWN) state = STATE_PRESSED;
else state = STATE_FOCUSED;
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) result = 1;
if (GUI_BUTTON_RELEASED) result = 1;
}
}
//--------------------------------------------------------------------
@ -2032,7 +2072,7 @@ int GuiLabelButton(Rectangle bounds, const char *text)
GuiState state = guiState;
bool pressed = false;
// NOTE: We force bounds.width to be all text
// NOTE: Force bounds.width to be all text
float textWidth = (float)GuiGetTextWidth(text);
if ((bounds.width - 2*GuiGetStyle(LABEL, BORDER_WIDTH) - 2*GuiGetStyle(LABEL, TEXT_PADDING)) < textWidth) bounds.width = textWidth + 2*GuiGetStyle(LABEL, BORDER_WIDTH) + 2*GuiGetStyle(LABEL, TEXT_PADDING) + 2;
@ -2040,15 +2080,15 @@ int GuiLabelButton(Rectangle bounds, const char *text)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
// Check checkbox state
if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
if (GUI_BUTTON_DOWN) state = STATE_PRESSED;
else state = STATE_FOCUSED;
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) pressed = true;
if (GUI_BUTTON_RELEASED) pressed = true;
}
}
//--------------------------------------------------------------------
@ -2074,13 +2114,13 @@ int GuiToggle(Rectangle bounds, const char *text, bool *active)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
// Check toggle button state
if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_DOWN) state = STATE_PRESSED;
else if (GUI_BUTTON_RELEASED)
{
state = STATE_NORMAL;
*active = !(*active);
@ -2185,12 +2225,12 @@ int GuiToggleSlider(Rectangle bounds, const char *text, int *active)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_DOWN) state = STATE_PRESSED;
else if (GUI_BUTTON_RELEASED)
{
state = STATE_PRESSED;
(*active)++;
@ -2256,7 +2296,7 @@ int GuiCheckBox(Rectangle bounds, const char *text, bool *checked)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
Rectangle totalBounds = {
(GuiGetStyle(CHECKBOX, TEXT_ALIGNMENT) == TEXT_ALIGN_LEFT)? textBounds.x : bounds.x,
@ -2268,10 +2308,10 @@ int GuiCheckBox(Rectangle bounds, const char *text, bool *checked)
// Check checkbox state
if (CheckCollisionPointRec(mousePoint, totalBounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
if (GUI_BUTTON_DOWN) state = STATE_PRESSED;
else state = STATE_FOCUSED;
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_RELEASED)
{
*checked = !(*checked);
result = 1;
@ -2324,18 +2364,18 @@ int GuiComboBox(Rectangle bounds, const char *text, int *active)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && (itemCount > 1) && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
if (CheckCollisionPointRec(mousePoint, bounds) ||
CheckCollisionPointRec(mousePoint, selector))
{
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_PRESSED)
{
*active += 1;
if (*active >= itemCount) *active = 0; // Cyclic combobox
}
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
if (GUI_BUTTON_DOWN) state = STATE_PRESSED;
else state = STATE_FOCUSED;
}
}
@ -2393,7 +2433,7 @@ int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMod
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && (editMode || !guiLocked) && (itemCount > 1) && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
if (editMode)
{
@ -2402,11 +2442,11 @@ int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMod
// Check if mouse has been pressed or released outside limits
if (!CheckCollisionPointRec(mousePoint, boundsOpen))
{
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) result = 1;
if (GUI_BUTTON_PRESSED || GUI_BUTTON_RELEASED) result = 1;
}
// Check if already selected item has been pressed again
if (CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) result = 1;
if (CheckCollisionPointRec(mousePoint, bounds) && GUI_BUTTON_PRESSED) result = 1;
// Check focused and selected item
for (int i = 0; i < itemCount; i++)
@ -2418,7 +2458,7 @@ int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMod
if (CheckCollisionPointRec(mousePoint, itemBounds))
{
itemFocused = i;
if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_RELEASED)
{
itemSelected = i;
result = 1; // Item selected
@ -2433,7 +2473,7 @@ int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMod
{
if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_PRESSED)
{
result = 1;
state = STATE_PRESSED;
@ -2548,13 +2588,13 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
!guiControlExclusiveMode && // No gui slider on dragging
(wrapMode == TEXT_WRAP_NONE)) // No wrap mode
{
Vector2 mousePosition = GetMousePosition();
Vector2 mousePosition = GUI_POINTER_POSITION;
if (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++;
if (GUI_KEY_DOWN(KEY_LEFT) || GUI_KEY_DOWN(KEY_RIGHT) || GUI_KEY_DOWN(KEY_UP) || GUI_KEY_DOWN(KEY_DOWN) || GUI_KEY_DOWN(KEY_BACKSPACE) || GUI_KEY_DOWN(KEY_DELETE)) autoCursorCounter++;
else autoCursorCounter = 0;
bool autoCursorShouldTrigger = (autoCursorCounter > RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN) && ((autoCursorCounter % RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0);
@ -2564,7 +2604,7 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
if (textBoxCursorIndex > textLength) textBoxCursorIndex = textLength;
// If text does not fit in the textbox and current cursor position is out of bounds,
// we add an index offset to text for drawing only what requires depending on cursor
// adding an index offset to text for drawing only what requires depending on cursor
while (textWidth >= textBounds.width)
{
int nextCodepointSize = 0;
@ -2575,15 +2615,15 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
textWidth = GuiGetTextWidth(text + textIndexOffset) - GuiGetTextWidth(text + textBoxCursorIndex);
}
int codepoint = GetCharPressed(); // Get Unicode codepoint
if (multiline && IsKeyPressed(KEY_ENTER)) codepoint = (int)'\n';
int codepoint = GUI_INPUT_KEY; // Get Unicode codepoint
if (multiline && GUI_KEY_PRESSED(KEY_ENTER)) codepoint = (int)'\n';
// Encode codepoint as UTF-8
int codepointSize = 0;
const char *charEncoded = CodepointToUTF8(codepoint, &codepointSize);
// Handle text paste action
if (IsKeyPressed(KEY_V) && (IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL)))
if (GUI_KEY_PRESSED(KEY_V) && (GUI_KEY_DOWN(KEY_LEFT_CONTROL) || GUI_KEY_DOWN(KEY_RIGHT_CONTROL)))
{
const char *pasteText = GetClipboardText();
if (pasteText != NULL)
@ -2633,13 +2673,13 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
}
// Move cursor to start
if ((textLength > 0) && IsKeyPressed(KEY_HOME)) textBoxCursorIndex = 0;
if ((textLength > 0) && GUI_KEY_PRESSED(KEY_HOME)) textBoxCursorIndex = 0;
// Move cursor to end
if ((textLength > textBoxCursorIndex) && IsKeyPressed(KEY_END)) textBoxCursorIndex = textLength;
if ((textLength > textBoxCursorIndex) && GUI_KEY_PRESSED(KEY_END)) textBoxCursorIndex = textLength;
// Delete related codepoints from text, after current cursor position
if ((textLength > textBoxCursorIndex) && IsKeyPressed(KEY_DELETE) && (IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL)))
if ((textLength > textBoxCursorIndex) && GUI_KEY_PRESSED(KEY_DELETE) && (GUI_KEY_DOWN(KEY_LEFT_CONTROL) || GUI_KEY_DOWN(KEY_RIGHT_CONTROL)))
{
int offset = textBoxCursorIndex;
int accCodepointSize = 0;
@ -2675,7 +2715,7 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
textLength -= accCodepointSize;
}
else if ((textLength > textBoxCursorIndex) && (IsKeyPressed(KEY_DELETE) || (IsKeyDown(KEY_DELETE) && autoCursorShouldTrigger)))
else if ((textLength > textBoxCursorIndex) && (GUI_KEY_PRESSED(KEY_DELETE) || (GUI_KEY_DOWN(KEY_DELETE) && autoCursorShouldTrigger)))
{
// Delete single codepoint from text, after current cursor position
@ -2689,7 +2729,7 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
}
// Delete related codepoints from text, before current cursor position
if ((textBoxCursorIndex > 0) && IsKeyPressed(KEY_BACKSPACE) && (IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL)))
if ((textBoxCursorIndex > 0) && GUI_KEY_PRESSED(KEY_BACKSPACE) && (GUI_KEY_DOWN(KEY_LEFT_CONTROL) || GUI_KEY_DOWN(KEY_RIGHT_CONTROL)))
{
int offset = textBoxCursorIndex;
int accCodepointSize = 0;
@ -2725,7 +2765,7 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
textBoxCursorIndex -= accCodepointSize;
}
else if ((textBoxCursorIndex > 0) && (IsKeyPressed(KEY_BACKSPACE) || (IsKeyDown(KEY_BACKSPACE) && autoCursorShouldTrigger)))
else if ((textBoxCursorIndex > 0) && (GUI_KEY_PRESSED(KEY_BACKSPACE) || (GUI_KEY_DOWN(KEY_BACKSPACE) && autoCursorShouldTrigger)))
{
// Delete single codepoint from text, before current cursor position
@ -2741,7 +2781,7 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
}
// Move cursor position with keys
if ((textBoxCursorIndex > 0) && IsKeyPressed(KEY_LEFT) && (IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL)))
if ((textBoxCursorIndex > 0) && GUI_KEY_PRESSED(KEY_LEFT) && (GUI_KEY_DOWN(KEY_LEFT_CONTROL) || GUI_KEY_DOWN(KEY_RIGHT_CONTROL)))
{
int offset = textBoxCursorIndex;
//int accCodepointSize = 0;
@ -2772,14 +2812,14 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
textBoxCursorIndex = offset;
}
else if ((textBoxCursorIndex > 0) && (IsKeyPressed(KEY_LEFT) || (IsKeyDown(KEY_LEFT) && autoCursorShouldTrigger)))
else if ((textBoxCursorIndex > 0) && (GUI_KEY_PRESSED(KEY_LEFT) || (GUI_KEY_DOWN(KEY_LEFT) && autoCursorShouldTrigger)))
{
int prevCodepointSize = 0;
GetCodepointPrevious(text + textBoxCursorIndex, &prevCodepointSize);
textBoxCursorIndex -= prevCodepointSize;
}
else if ((textLength > textBoxCursorIndex) && IsKeyPressed(KEY_RIGHT) && (IsKeyDown(KEY_LEFT_CONTROL) || IsKeyDown(KEY_RIGHT_CONTROL)))
else if ((textLength > textBoxCursorIndex) && GUI_KEY_PRESSED(KEY_RIGHT) && (GUI_KEY_DOWN(KEY_LEFT_CONTROL) || GUI_KEY_DOWN(KEY_RIGHT_CONTROL)))
{
int offset = textBoxCursorIndex;
//int accCodepointSize = 0;
@ -2811,7 +2851,7 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
textBoxCursorIndex = offset;
}
else if ((textLength > textBoxCursorIndex) && (IsKeyPressed(KEY_RIGHT) || (IsKeyDown(KEY_RIGHT) && autoCursorShouldTrigger)))
else if ((textLength > textBoxCursorIndex) && (GUI_KEY_PRESSED(KEY_RIGHT) || (GUI_KEY_DOWN(KEY_RIGHT) && autoCursorShouldTrigger)))
{
int nextCodepointSize = 0;
GetCodepointNext(text + textBoxCursorIndex, &nextCodepointSize);
@ -2848,14 +2888,14 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
// Check if mouse cursor is at the last position
int textEndWidth = GuiGetTextWidth(text + textIndexOffset);
if (GetMousePosition().x >= (textBounds.x + textEndWidth - glyphWidth/2))
if (GUI_POINTER_POSITION.x >= (textBounds.x + textEndWidth - glyphWidth/2))
{
mouseCursor.x = textBounds.x + textEndWidth;
mouseCursorIndex = textLength;
}
// Place cursor at required index on mouse click
if ((mouseCursor.x >= 0) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if ((mouseCursor.x >= 0) && GUI_BUTTON_PRESSED)
{
cursor.x = mouseCursor.x;
textBoxCursorIndex = mouseCursorIndex;
@ -2868,8 +2908,8 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
//if (multiline) cursor.y = GetTextLines()
// Finish text editing on ENTER or mouse click outside bounds
if ((!multiline && IsKeyPressed(KEY_ENTER)) ||
(!CheckCollisionPointRec(mousePosition, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
if ((!multiline && GUI_KEY_PRESSED(KEY_ENTER)) ||
(!CheckCollisionPointRec(mousePosition, bounds) && GUI_BUTTON_PRESSED))
{
textBoxCursorIndex = 0; // GLOBAL: Reset the shared cursor index
autoCursorCounter = 0; // GLOBAL: Reset counter for repeated keystrokes
@ -2882,7 +2922,7 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
{
state = STATE_FOCUSED;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_PRESSED)
{
textBoxCursorIndex = textLength; // GLOBAL: Place cursor index to the end of current text
autoCursorCounter = 0; // GLOBAL: Reset counter for repeated keystrokes
@ -2976,12 +3016,12 @@ int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
// Check spinner state
if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
if (GUI_BUTTON_DOWN) state = STATE_PRESSED;
else state = STATE_FOCUSED;
}
}
@ -3051,7 +3091,7 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
bool valueHasChanged = false;
if (editMode)
@ -3061,7 +3101,7 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
int keyCount = (int)strlen(textValue);
// Add or remove minus symbol
if (IsKeyPressed(KEY_MINUS))
if (GUI_KEY_PRESSED(KEY_MINUS))
{
if (textValue[0] == '-')
{
@ -3090,7 +3130,7 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
// Add new digit to text value
if ((keyCount >= 0) && (keyCount < RAYGUI_VALUEBOX_MAX_CHARS) && (GuiGetTextWidth(textValue) < bounds.width))
{
int key = GetCharPressed();
int key = GUI_INPUT_KEY;
// Only allow keys in range [48..57]
if ((key >= 48) && (key <= 57))
@ -3102,7 +3142,7 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
}
// Delete text
if ((keyCount > 0) && IsKeyPressed(KEY_BACKSPACE))
if ((keyCount > 0) && GUI_KEY_PRESSED(KEY_BACKSPACE))
{
keyCount--;
textValue[keyCount] = '\0';
@ -3111,11 +3151,11 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
if (valueHasChanged) *value = TextToInteger(textValue);
// NOTE: We are not clamp values until user input finishes
// NOTE: Values are not clamped until user input finishes
//if (*value > maxValue) *value = maxValue;
//else if (*value < minValue) *value = minValue;
if ((IsKeyPressed(KEY_ENTER) || IsKeyPressed(KEY_KP_ENTER)) || (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
if ((GUI_KEY_PRESSED(KEY_ENTER) || GUI_KEY_PRESSED(KEY_KP_ENTER)) || (!CheckCollisionPointRec(mousePoint, bounds) && GUI_BUTTON_PRESSED))
{
if (*value > maxValue) *value = maxValue;
else if (*value < minValue) *value = minValue;
@ -3131,7 +3171,7 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
if (CheckCollisionPointRec(mousePoint, bounds))
{
state = STATE_FOCUSED;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) result = 1;
if (GUI_BUTTON_PRESSED) result = 1;
}
}
}
@ -3192,7 +3232,7 @@ int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
bool valueHasChanged = false;
@ -3203,7 +3243,7 @@ int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float
int keyCount = (int)strlen(textValue);
// Add or remove minus symbol
if (IsKeyPressed(KEY_MINUS))
if (GUI_KEY_PRESSED(KEY_MINUS))
{
if (textValue[0] == '-')
{
@ -3234,7 +3274,7 @@ int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float
{
if (GuiGetTextWidth(textValue) < bounds.width)
{
int key = GetCharPressed();
int key = GUI_INPUT_KEY;
if (((key >= 48) && (key <= 57)) ||
(key == '.') ||
((keyCount == 0) && (key == '+')) || // NOTE: Sign can only be in first position
@ -3249,7 +3289,7 @@ int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float
}
// Pressed backspace
if (IsKeyPressed(KEY_BACKSPACE))
if (GUI_KEY_PRESSED(KEY_BACKSPACE))
{
if (keyCount > 0)
{
@ -3261,14 +3301,14 @@ int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float
if (valueHasChanged) *value = TextToFloat(textValue);
if ((IsKeyPressed(KEY_ENTER) || IsKeyPressed(KEY_KP_ENTER)) || (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) result = 1;
if ((GUI_KEY_PRESSED(KEY_ENTER) || GUI_KEY_PRESSED(KEY_KP_ENTER)) || (!CheckCollisionPointRec(mousePoint, bounds) && GUI_BUTTON_PRESSED)) result = 1;
}
else
{
if (CheckCollisionPointRec(mousePoint, bounds))
{
state = STATE_FOCUSED;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) result = 1;
if (GUI_BUTTON_PRESSED) result = 1;
}
}
}
@ -3322,11 +3362,11 @@ int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, flo
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
if (guiControlExclusiveMode) // Allows to keep dragging outside of bounds
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_DOWN)
{
if (CHECK_BOUNDS_ID(bounds, guiControlExclusiveRec))
{
@ -3343,7 +3383,7 @@ int GuiSlider(Rectangle bounds, const char *textLeft, const char *textRight, flo
}
else if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_DOWN)
{
state = STATE_PRESSED;
guiControlExclusiveMode = true;
@ -3536,12 +3576,12 @@ int GuiDummyRec(Rectangle bounds, const char *text)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
// Check button state
if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
if (GUI_BUTTON_DOWN) state = STATE_PRESSED;
else state = STATE_FOCUSED;
}
}
@ -3579,7 +3619,7 @@ int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollInd
int itemFocused = (focus == NULL)? -1 : *focus;
int itemSelected = (active == NULL)? -1 : *active;
// Check if we need a scroll bar
// Check if scroll bar is needed
bool useScrollBar = false;
if ((GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING))*count > bounds.height) useScrollBar = true;
@ -3603,7 +3643,7 @@ int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollInd
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
// Check mouse inside list view
if (CheckCollisionPointRec(mousePoint, bounds))
@ -3616,7 +3656,7 @@ int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollInd
if (CheckCollisionPointRec(mousePoint, itemBounds))
{
itemFocused = startIndex + i;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_PRESSED)
{
if (itemSelected == (startIndex + i)) itemSelected = -1;
else itemSelected = startIndex + i;
@ -3630,8 +3670,8 @@ int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollInd
if (useScrollBar)
{
int wheelMove = (int)GetMouseWheelMove();
startIndex -= wheelMove;
float scrollDelta = GUI_SCROLL_DELTA;
startIndex -= (int)scrollDelta;
if (startIndex < 0) startIndex = 0;
else if (startIndex > (count - visibleItems)) startIndex = count - visibleItems;
@ -3670,7 +3710,7 @@ int GuiListViewEx(Rectangle bounds, const char **text, int count, int *scrollInd
GuiDrawRectangle(itemBounds, GuiGetStyle(LISTVIEW, LIST_ITEMS_BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_PRESSED)), GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_PRESSED)));
GuiDrawText(text[startIndex + i], GetTextBounds(DEFAULT, itemBounds), GuiGetStyle(LISTVIEW, TEXT_ALIGNMENT), GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_PRESSED)));
}
else if (((startIndex + i) == itemFocused)) // && (focus != NULL)) // NOTE: We want items focused, despite not returned!
else if (((startIndex + i) == itemFocused)) // && (focus != NULL)) // NOTE: Items focused, despite not returned
{
// Draw item focused
GuiDrawRectangle(itemBounds, GuiGetStyle(LISTVIEW, LIST_ITEMS_BORDER_WIDTH), GetColor(GuiGetStyle(LISTVIEW, BORDER_COLOR_FOCUSED)), GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_FOCUSED)));
@ -3766,11 +3806,11 @@ int GuiColorBarAlpha(Rectangle bounds, const char *text, float *alpha)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
if (guiControlExclusiveMode) // Allows to keep dragging outside of bounds
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_DOWN)
{
if (CHECK_BOUNDS_ID(bounds, guiControlExclusiveRec))
{
@ -3789,7 +3829,7 @@ int GuiColorBarAlpha(Rectangle bounds, const char *text, float *alpha)
}
else if (CheckCollisionPointRec(mousePoint, bounds) || CheckCollisionPointRec(mousePoint, selector))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_DOWN)
{
state = STATE_PRESSED;
guiControlExclusiveMode = true;
@ -3851,11 +3891,11 @@ int GuiColorBarHue(Rectangle bounds, const char *text, float *hue)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
if (guiControlExclusiveMode) // Allows to keep dragging outside of bounds
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_DOWN)
{
if (CHECK_BOUNDS_ID(bounds, guiControlExclusiveRec))
{
@ -3874,7 +3914,7 @@ int GuiColorBarHue(Rectangle bounds, const char *text, float *hue)
}
else if (CheckCollisionPointRec(mousePoint, bounds) || CheckCollisionPointRec(mousePoint, selector))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_DOWN)
{
state = STATE_PRESSED;
guiControlExclusiveMode = true;
@ -3887,12 +3927,12 @@ int GuiColorBarHue(Rectangle bounds, const char *text, float *hue)
}
else state = STATE_FOCUSED;
/*if (IsKeyDown(KEY_UP))
/*if (GUI_KEY_DOWN(KEY_UP))
{
hue -= 2.0f;
if (hue <= 0.0f) hue = 0.0f;
}
else if (IsKeyDown(KEY_DOWN))
else if (GUI_KEY_DOWN(KEY_DOWN))
{
hue += 2.0f;
if (hue >= 360.0f) hue = 360.0f;
@ -4009,11 +4049,11 @@ int GuiColorPanelHSV(Rectangle bounds, const char *text, Vector3 *colorHsv)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
if (guiControlExclusiveMode) // Allows to keep dragging outside of bounds
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_DOWN)
{
if (CHECK_BOUNDS_ID(bounds, guiControlExclusiveRec))
{
@ -4043,7 +4083,7 @@ int GuiColorPanelHSV(Rectangle bounds, const char *text, Vector3 *colorHsv)
}
else if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_DOWN)
{
state = STATE_PRESSED;
guiControlExclusiveMode = true;
@ -4248,7 +4288,7 @@ int GuiGrid(Rectangle bounds, const char *text, float spacing, int subdivs, Vect
int result = 0;
GuiState state = guiState;
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
Vector2 currentMouseCell = { -1, -1 };
float spaceWidth = spacing/(float)subdivs;
@ -4416,11 +4456,14 @@ void GuiLoadStyle(const char *fileName)
if (fileDataSize > 0)
{
unsigned char *fileData = (unsigned char *)RAYGUI_CALLOC(fileDataSize, sizeof(unsigned char));
fread(fileData, sizeof(unsigned char), fileDataSize, rgsFile);
if (fileData != NULL)
{
fread(fileData, sizeof(unsigned char), fileDataSize, rgsFile);
GuiLoadStyleFromMemory(fileData, fileDataSize);
GuiLoadStyleFromMemory(fileData, fileDataSize);
RAYGUI_FREE(fileData);
RAYGUI_FREE(fileData);
}
}
fclose(rgsFile);
@ -4431,7 +4474,7 @@ void GuiLoadStyle(const char *fileName)
// Load style default over global style
void GuiLoadStyleDefault(void)
{
// We set this variable first to avoid cyclic function calls
// Setting this flag first to avoid cyclic function calls
// when calling GuiSetStyle() and GuiGetStyle()
guiStyleLoaded = true;
@ -4460,7 +4503,7 @@ void GuiLoadStyleDefault(void)
GuiSetStyle(DEFAULT, TEXT_SPACING, 1); // DEFAULT, shared by all controls
GuiSetStyle(DEFAULT, LINE_COLOR, 0x90abb5ff); // DEFAULT specific property
GuiSetStyle(DEFAULT, BACKGROUND_COLOR, 0xf5f5f5ff); // DEFAULT specific property
GuiSetStyle(DEFAULT, TEXT_LINE_SPACING, 15); // DEFAULT, 15 pixels between lines
GuiSetStyle(DEFAULT, TEXT_LINE_SPACING, 5); // DEFAULT, pixels between lines, from bottom of first line to top of second
GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_MIDDLE); // DEFAULT, text aligned vertically to middle of text-bounds
// Initialize control-specific property values
@ -4526,7 +4569,7 @@ void GuiLoadStyleDefault(void)
// NOTE: Default raylib font character 95 is a white square
Rectangle whiteChar = guiFont.recs[95];
// NOTE: We set up a 1px padding on char rectangle to avoid pixel bleeding on MSAA filtering
// NOTE: Setting up a 1px padding on char rectangle to avoid pixel bleeding on MSAA filtering
SetShapesTexture(guiFont.texture, RAYGUI_CLITERAL(Rectangle){ whiteChar.x + 1, whiteChar.y + 1, whiteChar.width - 2, whiteChar.height - 2 });
}
}
@ -5043,14 +5086,14 @@ static Rectangle GetTextBounds(int control, Rectangle bounds)
}
// Get text icon if provided and move text cursor
// NOTE: We support up to 999 values for iconId
// NOTE: Up to #999# values supported for iconId
static const char *GetTextIcon(const char *text, int *iconId)
{
#if !defined(RAYGUI_NO_ICONS)
*iconId = -1;
if (text[0] == '#') // Maybe we have an icon!
if (text[0] == '#') // Maybe it is stars with an icon, ending # must be found
{
char iconValue[4] = { 0 }; // Maximum length for icon value: 3 digits + '\0'
char iconValue[4] = { 0 }; // Maximum length for icon value: 3 digits + '\0'
int pos = 1;
while ((pos < 4) && (text[pos] >= '0') && (text[pos] <= '9'))
@ -5147,7 +5190,7 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
// - For every line, wordwrap mode is checked (useful for GuitextBox(), read-only)
// Get text lines (using '\n' as delimiter) to be processed individually
// WARNING: We can't use GuiTextSplit() function because it can be already used
// WARNING: GuiTextSplit() function can't be used now because it can have already been used
// before the GuiDrawText() call and its buffer is static, it would be overriden :(
int lineCount = 0;
const char **lines = GetTextLines(text, &lineCount);
@ -5158,7 +5201,7 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
int wrapMode = GuiGetStyle(DEFAULT, TEXT_WRAP_MODE); // Wrap-mode only available in read-only mode, no for text editing
// TODO: WARNING: This totalHeight is not valid for vertical alignment in case of word-wrap
float totalHeight = (float)(lineCount*GuiGetStyle(DEFAULT, TEXT_SIZE) + (lineCount - 1)*GuiGetStyle(DEFAULT, TEXT_SIZE)/2);
float totalHeight = (float)(lineCount*GuiGetStyle(DEFAULT, TEXT_SIZE) + (lineCount - 1)*GuiGetStyle(DEFAULT, TEXT_LINE_SPACING));
float posOffsetY = 0.0f;
for (int i = 0; i < lineCount; i++)
@ -5171,7 +5214,7 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
Vector2 textBoundsPosition = { textBounds.x, textBounds.y };
float textBoundsWidthOffset = 0.0f;
// NOTE: We get text size after icon has been processed
// NOTE: Get text size after icon has been processed
// WARNING: GuiGetTextWidth() also processes text icon to get width! -> Really needed?
int textSizeX = GuiGetTextWidth(lines[i]);
@ -5206,8 +5249,8 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
default: break;
}
// NOTE: Make sure we get pixel-perfect coordinates,
// In case of decimals we got weird text positioning
// NOTE: Make sure getting pixel-perfect coordinates,
// In case of decimals, it could result in text positioning artifacts
textBoundsPosition.x = (float)((int)textBoundsPosition.x);
textBoundsPosition.y = (float)((int)textBoundsPosition.y);
//---------------------------------------------------------------------------------
@ -5217,7 +5260,7 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
#if !defined(RAYGUI_NO_ICONS)
if (iconId >= 0)
{
// NOTE: We consider icon height, probably different than text size
// NOTE: Considering icon height, probably different than text size
GuiDrawIcon(iconId, (int)textBoundsPosition.x, (int)(textBounds.y + textBounds.height/2 - RAYGUI_ICON_SIZE*guiIconScale/2 + TEXT_VALIGN_PIXEL_OFFSET(textBounds.height)), guiIconScale, tint);
textBoundsPosition.x += (float)(RAYGUI_ICON_SIZE*guiIconScale + ICON_TEXT_PADDING);
textBoundsWidthOffset = (float)(RAYGUI_ICON_SIZE*guiIconScale + ICON_TEXT_PADDING);
@ -5243,8 +5286,8 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
int codepoint = GetCodepointNext(&lines[i][c], &codepointSize);
int index = GetGlyphIndex(guiFont, codepoint);
// NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
// but we need to draw all of the bad bytes using the '?' symbol moving one byte
// NOTE: Normally, exiting the decoding sequence as soon as a bad byte is found (and return 0x3f)
// but all of the bad bytes need to be drawn using the '?' symbol, moving one byte
if (codepoint == 0x3f) codepointSize = 1; // TODO: Review not recognized codepoints size
// Get glyph width to check if it goes out of bounds
@ -5259,7 +5302,7 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
if ((textOffsetX + glyphWidth) > textBounds.width - textBoundsWidthOffset)
{
textOffsetX = 0.0f;
textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
textOffsetY += (GuiGetStyle(DEFAULT, TEXT_SIZE) + GuiGetStyle(DEFAULT, TEXT_LINE_SPACING));
if (tempWrapCharMode) // Wrap at char level when too long words
{
@ -5288,7 +5331,7 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
else if ((textOffsetX + nextSpaceWidth) > textBounds.width - textBoundsWidthOffset)
{
textOffsetX = 0.0f;
textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
textOffsetY += (GuiGetStyle(DEFAULT, TEXT_SIZE) + GuiGetStyle(DEFAULT, TEXT_LINE_SPACING));
}
}
@ -5338,7 +5381,7 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
}
}
if (wrapMode == TEXT_WRAP_NONE) posOffsetY += (float)GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
if (wrapMode == TEXT_WRAP_NONE) posOffsetY += (float)(GuiGetStyle(DEFAULT, TEXT_SIZE) + GuiGetStyle(DEFAULT, TEXT_LINE_SPACING));
else if ((wrapMode == TEXT_WRAP_CHAR) || (wrapMode == TEXT_WRAP_WORD)) posOffsetY += (textOffsetY + (float)GuiGetStyle(DEFAULT, TEXT_LINE_SPACING));
//---------------------------------------------------------------------------------
}
@ -5422,7 +5465,7 @@ static const char **GuiTextSplit(const char *text, char delimiter, int *count, i
if (textRow != NULL) textRow[0] = 0;
// Count how many substrings we have on text and point to every one
// Count how many substrings text contains and point to every one of them
for (int i = 0; i < RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE; i++)
{
buffer[i] = text[i];
@ -5643,11 +5686,11 @@ static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue)
//--------------------------------------------------------------------
if ((state != STATE_DISABLED) && !guiLocked)
{
Vector2 mousePoint = GetMousePosition();
Vector2 mousePoint = GUI_POINTER_POSITION;
if (guiControlExclusiveMode) // Allows to keep dragging outside of bounds
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON) &&
if (GUI_BUTTON_DOWN &&
!CheckCollisionPointRec(mousePoint, arrowUpLeft) &&
!CheckCollisionPointRec(mousePoint, arrowDownRight))
{
@ -5670,11 +5713,11 @@ static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue)
state = STATE_FOCUSED;
// Handle mouse wheel
int wheel = (int)GetMouseWheelMove();
if (wheel != 0) value += wheel;
float scrollDelta = GUI_SCROLL_DELTA;
if (scrollDelta != 0) value += (int)scrollDelta;
// Handle mouse button down
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
if (GUI_BUTTON_PRESSED)
{
guiControlExclusiveMode = true;
guiControlExclusiveRec = bounds; // Store bounds as an identifier when dragging starts
@ -5696,13 +5739,13 @@ static int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue)
/*
if (isVertical)
{
if (IsKeyDown(KEY_DOWN)) value += 5;
else if (IsKeyDown(KEY_UP)) value -= 5;
if (GUI_KEY_DOWN(KEY_DOWN)) value += 5;
else if (GUI_KEY_DOWN(KEY_UP)) value -= 5;
}
else
{
if (IsKeyDown(KEY_RIGHT)) value += 5;
else if (IsKeyDown(KEY_LEFT)) value -= 5;
if (GUI_KEY_DOWN(KEY_RIGHT)) value += 5;
else if (GUI_KEY_DOWN(KEY_LEFT)) value -= 5;
}
*/
}
@ -5839,7 +5882,7 @@ const char **TextSplit(const char *text, char delimiter, int *count)
{
counter = 1;
// Count how many substrings we have on text and point to every one
// Count how many substrings text contains and point to every one of them
for (int i = 0; i < RAYGUI_TEXTSPLIT_MAX_TEXT_SIZE; i++)
{
buffer[i] = text[i];
@ -5947,9 +5990,9 @@ static const char *CodepointToUTF8(int codepoint, int *byteSize)
}
// Get next codepoint in a UTF-8 encoded text, scanning until '\0' is found
// When a invalid UTF-8 byte is encountered we exit as soon as possible and a '?'(0x3f) codepoint is returned
// When a invalid UTF-8 byte is encountered, exiting as soon as possible and returning a '?'(0x3f) codepoint
// Total number of bytes processed are returned as a parameter
// NOTE: the standard says U+FFFD should be returned in case of errors
// NOTE: The standard says U+FFFD should be returned in case of errors
// but that character is not supported by the default font in raylib
static int GetCodepointNext(const char *text, int *codepointSize)
{