comparison third_party/raylib/include/raygui.h @ 112:d6d578b49a19

[PostDog] Got CRUD working.
author June Park <parkjune1995@gmail.com>
date Sun, 04 Jan 2026 11:38:44 -0800
parents 48f260576059
children e2a73e64e8e6
comparison
equal deleted inserted replaced
111:48f260576059 112:d6d578b49a19
736 // Basic controls set 736 // Basic controls set
737 RAYGUIAPI int GuiLabel(Rectangle bounds, const char *text); // Label control 737 RAYGUIAPI int GuiLabel(Rectangle bounds, const char *text); // Label control
738 RAYGUIAPI int GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked 738 RAYGUIAPI int GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked
739 RAYGUIAPI int GuiLabelButton(Rectangle bounds, const char *text); // Label button control, returns true when clicked 739 RAYGUIAPI int GuiLabelButton(Rectangle bounds, const char *text); // Label button control, returns true when clicked
740 RAYGUIAPI int GuiToggle(Rectangle bounds, const char *text, bool *active); // Toggle Button control 740 RAYGUIAPI int GuiToggle(Rectangle bounds, const char *text, bool *active); // Toggle Button control
741 RAYGUIAPI void JUNE_DrawRectangleLinesNoBottom(Rectangle rect, float thickness, Color color);
741 RAYGUIAPI int GuiToggleGroup(Rectangle bounds, const char *text, int *active); // Toggle Group control 742 RAYGUIAPI int GuiToggleGroup(Rectangle bounds, const char *text, int *active); // Toggle Group control
742 RAYGUIAPI int GuiToggleSlider(Rectangle bounds, const char *text, int *active); // Toggle Slider control 743 RAYGUIAPI int GuiToggleSlider(Rectangle bounds, const char *text, int *active); // Toggle Slider control
743 RAYGUIAPI int GuiCheckBox(Rectangle bounds, const char *text, bool *checked); // Check Box control, returns true when active 744 RAYGUIAPI int GuiCheckBox(Rectangle bounds, const char *text, bool *checked); // Check Box control, returns true when active
744 RAYGUIAPI int GuiComboBox(Rectangle bounds, const char *text, int *active); // Combo Box control 745 RAYGUIAPI int GuiComboBox(Rectangle bounds, const char *text, int *active); // Combo Box control
745 746
2091 2092
2092 // Draw control 2093 // Draw control
2093 //-------------------------------------------------------------------- 2094 //--------------------------------------------------------------------
2094 if (state == STATE_NORMAL) 2095 if (state == STATE_NORMAL)
2095 { 2096 {
2096 GuiDrawRectangle(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), GetColor(GuiGetStyle(TOGGLE, ((*active)? BORDER_COLOR_PRESSED : (BORDER + state*3)))), GetColor(GuiGetStyle(TOGGLE, ((*active)? BASE_COLOR_PRESSED : (BASE + state*3))))); 2097 if (*active)
2098 {
2099 Rectangle tmp = bounds;
2100 tmp.height += GuiGetStyle(TOGGLE, BORDER_WIDTH);
2101 GuiDrawRectangle(
2102 tmp,
2103 0,
2104 GetColor(GuiGetStyle(TOGGLE, ((*active)? BORDER_COLOR_PRESSED : (BORDER + state*3)))),
2105 GetColor(GuiGetStyle(TOGGLE, ((*active)? BASE_COLOR_PRESSED : (BASE + state*3))))
2106 );
2107 JUNE_DrawRectangleLinesNoBottom(
2108 bounds,
2109 GuiGetStyle(TOGGLE, BORDER_WIDTH),
2110 GetColor(GuiGetStyle(TOGGLE, BORDER_COLOR_PRESSED))
2111 );
2112 }
2113 else
2114 {
2115 GuiDrawRectangle(
2116 bounds,
2117 GuiGetStyle(TOGGLE, BORDER_WIDTH),
2118 GetColor(GuiGetStyle(TOGGLE, ((*active)? BORDER_COLOR_PRESSED : (BORDER + state*3)))),
2119 GetColor(GuiGetStyle(TOGGLE, ((*active)? BASE_COLOR_PRESSED : (BASE + state*3))))
2120 );
2121 }
2097 GuiDrawText(text, GetTextBounds(TOGGLE, bounds), GuiGetStyle(TOGGLE, TEXT_ALIGNMENT), GetColor(GuiGetStyle(TOGGLE, ((*active)? TEXT_COLOR_PRESSED : (TEXT + state*3))))); 2122 GuiDrawText(text, GetTextBounds(TOGGLE, bounds), GuiGetStyle(TOGGLE, TEXT_ALIGNMENT), GetColor(GuiGetStyle(TOGGLE, ((*active)? TEXT_COLOR_PRESSED : (TEXT + state*3)))));
2098 } 2123 }
2099 else 2124 else
2100 { 2125 {
2101 GuiDrawRectangle(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), GetColor(GuiGetStyle(TOGGLE, BORDER + state*3)), GetColor(GuiGetStyle(TOGGLE, BASE + state*3))); 2126 GuiDrawRectangle(bounds, GuiGetStyle(TOGGLE, BORDER_WIDTH), GetColor(GuiGetStyle(TOGGLE, BORDER + state*3)), GetColor(GuiGetStyle(TOGGLE, BASE + state*3)));
2102 GuiDrawText(text, GetTextBounds(TOGGLE, bounds), GuiGetStyle(TOGGLE, TEXT_ALIGNMENT), GetColor(GuiGetStyle(TOGGLE, TEXT + state*3))); 2127 GuiDrawText(text, GetTextBounds(TOGGLE, bounds), GuiGetStyle(TOGGLE, TEXT_ALIGNMENT), GetColor(GuiGetStyle(TOGGLE, TEXT + state*3)));
2103 } 2128 }
2104 2129
2105 if (state == STATE_FOCUSED) GuiTooltip(bounds); 2130 if (state == STATE_FOCUSED) {
2131 GuiTooltip(bounds);
2132 }
2106 //-------------------------------------------------------------------- 2133 //--------------------------------------------------------------------
2107 2134
2108 return result; 2135 return result;
2109 } 2136 }
2110 2137
2921 //-------------------------------------------------------------------- 2948 //--------------------------------------------------------------------
2922 2949
2923 return result; // Mouse button pressed: result = 1 2950 return result; // Mouse button pressed: result = 1
2924 } 2951 }
2925 2952
2926 /*
2927 // Text Box control with multiple lines and word-wrap 2953 // Text Box control with multiple lines and word-wrap
2928 // NOTE: This text-box is readonly, no editing supported by default 2954 // NOTE: This text-box is readonly, no editing supported by default
2929 bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode) 2955 bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode)
2930 { 2956 {
2931 bool pressed = false; 2957 bool pressed = false;
2941 GuiSetStyle(DEFAULT, TEXT_WRAP_MODE, TEXT_WRAP_NONE); 2967 GuiSetStyle(DEFAULT, TEXT_WRAP_MODE, TEXT_WRAP_NONE);
2942 GuiSetStyle(TEXTBOX, TEXT_READONLY, 0); 2968 GuiSetStyle(TEXTBOX, TEXT_READONLY, 0);
2943 2969
2944 return pressed; 2970 return pressed;
2945 } 2971 }
2946 */
2947 2972
2948 // Spinner control, returns selected value 2973 // Spinner control, returns selected value
2949 int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) 2974 int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode)
2950 { 2975 {
2951 int result = 1; 2976 int result = 1;
6029 #endif 6054 #endif
6030 6055
6031 int result = 0; 6056 int result = 0;
6032 GuiState state = guiState; 6057 GuiState state = guiState;
6033 6058
6034 bool multiline = true; 6059 bool multiline = true; // TODO: Consider multiline text input
6035 int wrapMode = GuiGetStyle(DEFAULT, TEXT_WRAP_MODE); 6060 int wrapMode = GuiGetStyle(DEFAULT, TEXT_WRAP_MODE);
6036 6061
6037 Rectangle textBounds = GetTextBounds(TEXTBOX, bounds); 6062 Rectangle textBounds = GetTextBounds(TEXTBOX, bounds);
6038 int textLength = (text != NULL)? (int)strlen(text) : 0; // Get current text length 6063 int textLength = (text != NULL)? (int)strlen(text) : 0; // Get current text length
6039 int thisCursorIndex = textBoxCursorIndex; 6064 int thisCursorIndex = textBoxCursorIndex;
6040 if (thisCursorIndex > textLength) thisCursorIndex = textLength; 6065 if (thisCursorIndex > textLength) thisCursorIndex = textLength;
6041 int textWidth = GuiGetTextWidth(text) - GuiGetTextWidth(text + thisCursorIndex); 6066
6067 // Calculate cursor position for multiline
6068 int cursorLine = 0; // Current line number (0-based)
6069 int lineStart = 0; // Start index of current line
6070
6071 if (multiline)
6072 {
6073 for (int i = 0; i < thisCursorIndex; i++)
6074 {
6075 if (text[i] == '\n')
6076 {
6077 cursorLine++;
6078 lineStart = i + 1;
6079 }
6080 }
6081 }
6082
6083 // Calculate horizontal position within current line
6084 char lineText[1024] = { 0 };
6085 int lineTextLen = 0;
6086 if (multiline)
6087 {
6088 // Extract current line text up to cursor
6089 int i = lineStart;
6090 while (i < thisCursorIndex && text[i] != '\n' && lineTextLen < 1023)
6091 {
6092 lineText[lineTextLen++] = text[i++];
6093 }
6094 lineText[lineTextLen] = '\0';
6095 }
6096
6097 int textWidth = multiline ? GuiGetTextWidth(lineText) : (GuiGetTextWidth(text) - GuiGetTextWidth(text + thisCursorIndex));
6042 int textIndexOffset = 0; // Text index offset to start drawing in the box 6098 int textIndexOffset = 0; // Text index offset to start drawing in the box
6043 6099
6100 // Line height for multiline (matches GuiDrawText line spacing)
6101 int lineHeight = GuiGetStyle(DEFAULT, TEXT_SIZE);
6102
6044 // Cursor rectangle 6103 // Cursor rectangle
6045 // NOTE: Position X value should be updated 6104 // NOTE: Position X and Y values updated for multiline support
6046 Rectangle cursor = { 6105 Rectangle cursor = {
6047 textBounds.x + textWidth + GuiGetStyle(DEFAULT, TEXT_SPACING), 6106 textBounds.x + textWidth + GuiGetStyle(DEFAULT, TEXT_SPACING),
6048 textBounds.y + GuiGetStyle(DEFAULT, TEXT_SIZE), 6107 multiline ? (textBounds.y + cursorLine * lineHeight) : (textBounds.y + textBounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE)),
6049 2, 6108 2,
6050 (float)GuiGetStyle(DEFAULT, TEXT_SIZE) 6109 (float)GuiGetStyle(DEFAULT, TEXT_SIZE)
6051 }; 6110 };
6052 6111
6053 if (cursor.height >= bounds.height) cursor.height = bounds.height - GuiGetStyle(TEXTBOX, BORDER_WIDTH)*2; 6112 if (cursor.height >= bounds.height) cursor.height = bounds.height - GuiGetStyle(TEXTBOX, BORDER_WIDTH)*2;
6341 GetCodepointNext(text + textBoxCursorIndex, &nextCodepointSize); 6400 GetCodepointNext(text + textBoxCursorIndex, &nextCodepointSize);
6342 6401
6343 textBoxCursorIndex += nextCodepointSize; 6402 textBoxCursorIndex += nextCodepointSize;
6344 } 6403 }
6345 6404
6405 // Vertical cursor movement for multiline
6406 if (multiline && (IsKeyPressed(KEY_UP) || (IsKeyDown(KEY_UP) && autoCursorShouldTrigger)))
6407 {
6408 // Find start of current line
6409 int currentLineStart = textBoxCursorIndex;
6410 while (currentLineStart > 0 && text[currentLineStart - 1] != '\n') currentLineStart--;
6411
6412 // Calculate horizontal position in current line
6413 int horizontalPos = textBoxCursorIndex - currentLineStart;
6414
6415 // Find start of previous line
6416 if (currentLineStart > 0)
6417 {
6418 int prevLineEnd = currentLineStart - 1; // Skip the newline
6419 int prevLineStart = prevLineEnd;
6420 while (prevLineStart > 0 && text[prevLineStart - 1] != '\n') prevLineStart--;
6421
6422 // Move to same horizontal position on previous line (or end of line if shorter)
6423 int prevLineLength = prevLineEnd - prevLineStart;
6424 int targetPos = (horizontalPos < prevLineLength) ? horizontalPos : prevLineLength;
6425 textBoxCursorIndex = prevLineStart + targetPos;
6426 }
6427 else
6428 {
6429 // Already on first line, move to start
6430 textBoxCursorIndex = 0;
6431 }
6432 }
6433 else if (multiline && (IsKeyPressed(KEY_DOWN) || (IsKeyDown(KEY_DOWN) && autoCursorShouldTrigger)))
6434 {
6435 // Find start of current line
6436 int currentLineStart = textBoxCursorIndex;
6437 while (currentLineStart > 0 && text[currentLineStart - 1] != '\n') currentLineStart--;
6438
6439 // Calculate horizontal position in current line
6440 int horizontalPos = textBoxCursorIndex - currentLineStart;
6441
6442 // Find end of current line
6443 int currentLineEnd = textBoxCursorIndex;
6444 while (currentLineEnd < textLength && text[currentLineEnd] != '\n') currentLineEnd++;
6445
6446 // Find next line
6447 if (currentLineEnd < textLength)
6448 {
6449 int nextLineStart = currentLineEnd + 1; // Skip the newline
6450 int nextLineEnd = nextLineStart;
6451 while (nextLineEnd < textLength && text[nextLineEnd] != '\n') nextLineEnd++;
6452
6453 // Move to same horizontal position on next line (or end of line if shorter)
6454 int nextLineLength = nextLineEnd - nextLineStart;
6455 int targetPos = (horizontalPos < nextLineLength) ? horizontalPos : nextLineLength;
6456 textBoxCursorIndex = nextLineStart + targetPos;
6457 }
6458 else
6459 {
6460 // Already on last line, move to end
6461 textBoxCursorIndex = textLength;
6462 }
6463 }
6464
6346 // Move cursor position with mouse 6465 // Move cursor position with mouse
6347 if (CheckCollisionPointRec(mousePosition, textBounds)) // Mouse hover text 6466 if (CheckCollisionPointRec(mousePosition, textBounds)) // Mouse hover text
6348 { 6467 {
6349 float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/(float)guiFont.baseSize; 6468 float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/(float)guiFont.baseSize;
6350 int codepointIndex = 0; 6469 int codepointIndex = 0;
6362 6481
6363 if (mousePosition.x <= (textBounds.x + (widthToMouseX + glyphWidth/2))) 6482 if (mousePosition.x <= (textBounds.x + (widthToMouseX + glyphWidth/2)))
6364 { 6483 {
6365 mouseCursor.x = textBounds.x + widthToMouseX; 6484 mouseCursor.x = textBounds.x + widthToMouseX;
6366 mouseCursorIndex = i; 6485 mouseCursorIndex = i;
6486 printf("before: %i\n", mouseCursorIndex);
6487 break;
6488 }
6489
6490 if (mousePosition.y >= textBounds.y && mousePosition.y <= textBounds.height)
6491 {
6492 mouseCursor.y = mousePosition.y;
6493 mouseCursorIndex = i;
6494 int number_of_n = (int)(mousePosition.y / lineHeight);
6495 for (int i = 0; i < textSize; i++)
6496 {
6497 if (text[i] == '\n')
6498 {
6499 number_of_n--;
6500 if (number_of_n == 0)
6501 mouseCursorIndex += i;
6502 }
6503 }
6367 break; 6504 break;
6368 } 6505 }
6369 6506
6370 widthToMouseX += (glyphWidth + (float)GuiGetStyle(DEFAULT, TEXT_SPACING)); 6507 widthToMouseX += (glyphWidth + (float)GuiGetStyle(DEFAULT, TEXT_SPACING));
6371 } 6508 }
6385 textBoxCursorIndex = mouseCursorIndex; 6522 textBoxCursorIndex = mouseCursorIndex;
6386 } 6523 }
6387 } 6524 }
6388 else mouseCursor.x = -1; 6525 else mouseCursor.x = -1;
6389 6526
6390 // Recalculate cursor position.y depending on textBoxCursorIndex 6527 // Recalculate cursor position for multiline
6391 cursor.x = bounds.x + GuiGetStyle(TEXTBOX, TEXT_PADDING) + GuiGetTextWidth(text + textIndexOffset) - GuiGetTextWidth(text + textBoxCursorIndex) + GuiGetStyle(DEFAULT, TEXT_SPACING); 6528 if (multiline)
6392 if (multiline) { 6529 {
6393 const char **lines = GetTextLines(text, &cursor.y); 6530 // Recalculate cursor line and position
6394 printf("Cursor: %f", cursor.y); 6531 int newCursorLine = 0;
6532 int newLineStart = 0;
6533
6534 for (int i = 0; i < textBoxCursorIndex; i++)
6535 {
6536 if (text[i] == '\n')
6537 {
6538 newCursorLine++;
6539 newLineStart = i + 1;
6540 }
6541 }
6542
6543 // Extract current line text up to cursor
6544 char currentLineText[1024] = { 0 };
6545 int currentLineLen = 0;
6546 int i = newLineStart;
6547 while (i < textBoxCursorIndex && text[i] != '\n' && currentLineLen < 1023)
6548 {
6549 currentLineText[currentLineLen++] = text[i++];
6550 }
6551 currentLineText[currentLineLen] = '\0';
6552
6553 cursor.x = bounds.x + GuiGetStyle(TEXTBOX, TEXT_PADDING) + GuiGetTextWidth(currentLineText) + GuiGetStyle(DEFAULT, TEXT_SPACING);
6554 cursor.y = textBounds.y + (newCursorLine * lineHeight * 1.5);
6555 }
6556 else
6557 {
6558 cursor.x = bounds.x + GuiGetStyle(TEXTBOX, TEXT_PADDING) + GuiGetTextWidth(text + textIndexOffset) - GuiGetTextWidth(text + textBoxCursorIndex) + GuiGetStyle(DEFAULT, TEXT_SPACING);
6395 } 6559 }
6396 6560
6397 // Finish text editing on ENTER or mouse click outside bounds 6561 // Finish text editing on ENTER or mouse click outside bounds
6398 if ((!multiline && IsKeyPressed(KEY_ENTER)) || 6562 if ((!multiline && IsKeyPressed(KEY_ENTER)) ||
6399 (!CheckCollisionPointRec(mousePosition, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) 6563 (!CheckCollisionPointRec(mousePosition, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)))
6430 { 6594 {
6431 GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_DISABLED))); 6595 GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_DISABLED)));
6432 } 6596 }
6433 else GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), BLANK); 6597 else GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), BLANK);
6434 6598
6435 6599 // Draw text considering index offset if required
6436 6600 // NOTE: Text index offset depends on cursor position
6601 // Set vertical alignment to top for multiline
6437 int prevVerticalAlignment = GuiGetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL); 6602 int prevVerticalAlignment = GuiGetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL);
6438 if (multiline) GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_TOP); 6603 if (multiline) GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, TEXT_ALIGN_TOP);
6439 6604
6440 // Draw text considering index offset if required 6605 GuiDrawText(text + textIndexOffset, textBounds, GuiGetStyle(TEXTBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(TEXTBOX, TEXT + (state*3))));
6441 // NOTE: Text index offset depends on cursor position 6606
6442 GuiDrawText( 6607 // Restore previous vertical alignment
6443 text + textIndexOffset,
6444 textBounds, GuiGetStyle(TEXTBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(TEXTBOX, TEXT + (state*3))));
6445
6446 // RESET
6447 if (multiline) GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, prevVerticalAlignment); 6608 if (multiline) GuiSetStyle(DEFAULT, TEXT_ALIGNMENT_VERTICAL, prevVerticalAlignment);
6448 6609
6449 // Draw cursor 6610 // Draw cursor
6450 if (editMode && !GuiGetStyle(TEXTBOX, TEXT_READONLY)) 6611 if (editMode && !GuiGetStyle(TEXTBOX, TEXT_READONLY))
6451 { 6612 {
6452 //if (autoCursorMode || ((blinkCursorFrameCounter/40)%2 == 0)) 6613 //if (autoCursorMode || ((blinkCursorFrameCounter/40)%2 == 0))
6453 GuiDrawRectangle(cursor, 0, BLANK, GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED))); 6614 GuiDrawRectangle(cursor, 0, BLANK, GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)));
6454 6615
6455 // Draw mouse position cursor (if required) 6616 // Draw mouse position cursor (if required)
6456 if (mouseCursor.x >= 0) GuiDrawRectangle(mouseCursor, 0, BLANK, GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED))); 6617 // if (mouseCursor.x >= 0) GuiDrawRectangle(mouseCursor, 0, BLANK, GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)));
6457 } 6618 }
6458 else if (state == STATE_FOCUSED) GuiTooltip(bounds); 6619 else if (state == STATE_FOCUSED) GuiTooltip(bounds);
6459 //-------------------------------------------------------------------- 6620 //--------------------------------------------------------------------
6460 6621
6461 return result; // Mouse button pressed: result = 1 6622 return result; // Mouse button pressed: result = 1
6462 } 6623 }
6463 6624
6625 void JUNE_DrawRectangleLinesNoBottom(Rectangle rect, float thickness, Color color) {
6626 Vector2 topLeft = { rect.x, rect.y };
6627 Vector2 topRight = { rect.x + rect.width, rect.y };
6628 Vector2 bottomLeft = { rect.x, rect.y + rect.height };
6629 Vector2 bottomRight = { rect.x + rect.width, rect.y + rect.height };
6630
6631 DrawLineEx(topLeft, topRight, thickness, color);
6632 DrawLineEx(topLeft, bottomLeft, thickness, color);
6633 DrawLineEx(topRight, bottomRight, thickness, color);
6634 }
6464 6635
6465 #endif // RAYGUI_IMPLEMENTnk_command_bufferATION 6636 #endif // RAYGUI_IMPLEMENTnk_command_bufferATION