Mercurial
comparison third_party/raylib/include/raygui.h @ 161:87d8d3eb3491
[PostDog] WIP to make it more mordern looking
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Thu, 15 Jan 2026 08:29:26 -0800 |
| parents | 2db6253f355d |
| children | 058de208e640 |
comparison
equal
deleted
inserted
replaced
| 160:948de3f54cea | 161:87d8d3eb3491 |
|---|---|
| 741 RAYGUIAPI int GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector2 *scroll, Rectangle *view); // Scroll Panel control | 741 RAYGUIAPI int GuiScrollPanel(Rectangle bounds, const char *text, Rectangle content, Vector2 *scroll, Rectangle *view); // Scroll Panel control |
| 742 | 742 |
| 743 // Basic controls set | 743 // Basic controls set |
| 744 RAYGUIAPI int GuiLabel(Rectangle bounds, const char *text); // Label control | 744 RAYGUIAPI int GuiLabel(Rectangle bounds, const char *text); // Label control |
| 745 RAYGUIAPI int GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked | 745 RAYGUIAPI int GuiButton(Rectangle bounds, const char *text); // Button control, returns true when clicked |
| 746 RAYGUIAPI int GuiButtonRounded(Rectangle bounds, const char *text, float roundness, int segments); | |
| 746 RAYGUIAPI int GuiLabelButton(Rectangle bounds, const char *text); // Label button control, returns true when clicked | 747 RAYGUIAPI int GuiLabelButton(Rectangle bounds, const char *text); // Label button control, returns true when clicked |
| 747 RAYGUIAPI int GuiToggle(Rectangle bounds, const char *text, bool *active); // Toggle Button control | 748 RAYGUIAPI int GuiToggle(Rectangle bounds, const char *text, bool *active); // Toggle Button control |
| 748 RAYGUIAPI int GuiToggleGroup(Rectangle bounds, const char *text, int *active); // Toggle Group control | 749 RAYGUIAPI int GuiToggleGroup(Rectangle bounds, const char *text, int *active); // Toggle Group control |
| 749 RAYGUIAPI int GuiToggleSlider(Rectangle bounds, const char *text, int *active); // Toggle Slider control | 750 RAYGUIAPI int GuiToggleSlider(Rectangle bounds, const char *text, int *active); // Toggle Slider control |
| 750 RAYGUIAPI int GuiCheckBox(Rectangle bounds, const char *text, bool *checked); // Check Box control, returns true when active | 751 RAYGUIAPI int GuiCheckBox(Rectangle bounds, const char *text, bool *checked); // Check Box control, returns true when active |
| 751 RAYGUIAPI int GuiComboBox(Rectangle bounds, const char *text, int *active); // Combo Box control | 752 RAYGUIAPI int GuiComboBox(Rectangle bounds, const char *text, int *active); // Combo Box control |
| 752 | 753 |
| 753 RAYGUIAPI int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode); // Dropdown Box control | 754 RAYGUIAPI int GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMode); // Dropdown Box control |
| 755 RAYGUIAPI int GuiDropdownBoxRounded(Rectangle bounds, const char *text, int *active, bool editMode, float roundness, int segments); | |
| 754 RAYGUIAPI int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Spinner control | 756 RAYGUIAPI int GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Spinner control |
| 755 RAYGUIAPI int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers | 757 RAYGUIAPI int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode); // Value Box control, updates input text with numbers |
| 756 RAYGUIAPI int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float *value, bool editMode); // Value box control for float values | 758 RAYGUIAPI int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float *value, bool editMode); // Value box control for float values |
| 757 RAYGUIAPI int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control, updates input text | 759 RAYGUIAPI int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode); // Text Box control, updates input text |
| 758 | 760 |
| 2037 //------------------------------------------------------------------ | 2039 //------------------------------------------------------------------ |
| 2038 | 2040 |
| 2039 return result; // Button pressed: result = 1 | 2041 return result; // Button pressed: result = 1 |
| 2040 } | 2042 } |
| 2041 | 2043 |
| 2044 // JUNE | |
| 2045 int GuiButtonRounded(Rectangle bounds, const char *text, float roundness, int segments) | |
| 2046 { | |
| 2047 int result = 0; | |
| 2048 GuiState state = guiState; | |
| 2049 | |
| 2050 // Update control | |
| 2051 //-------------------------------------------------------------------- | |
| 2052 if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode) | |
| 2053 { | |
| 2054 Vector2 mousePoint = GetMousePosition(); | |
| 2055 | |
| 2056 // Check button state | |
| 2057 if (CheckCollisionPointRec(mousePoint, bounds)) | |
| 2058 { | |
| 2059 if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED; | |
| 2060 else state = STATE_FOCUSED; | |
| 2061 | |
| 2062 if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) result = 1; | |
| 2063 } | |
| 2064 } | |
| 2065 //-------------------------------------------------------------------- | |
| 2066 | |
| 2067 // Draw control | |
| 2068 //-------------------------------------------------------------------- | |
| 2069 DrawRectangleRounded(bounds, roundness, segments, GetColor(GuiGetStyle(BUTTON, BASE + (state*3)))); | |
| 2070 GuiDrawText(text, GetTextBounds(BUTTON, bounds), GuiGetStyle(BUTTON, TEXT_ALIGNMENT), GetColor(GuiGetStyle(BUTTON, TEXT + (state*3)))); | |
| 2071 | |
| 2072 if (state == STATE_FOCUSED) GuiTooltip(bounds); | |
| 2073 //------------------------------------------------------------------ | |
| 2074 | |
| 2075 return result; // Button pressed: result = 1 | |
| 2076 } | |
| 2077 | |
| 2042 // Label button control | 2078 // Label button control |
| 2043 int GuiLabelButton(Rectangle bounds, const char *text) | 2079 int GuiLabelButton(Rectangle bounds, const char *text) |
| 2044 { | 2080 { |
| 2045 GuiState state = guiState; | 2081 GuiState state = guiState; |
| 2046 bool pressed = false; | 2082 bool pressed = false; |
| 2527 { | 2563 { |
| 2528 GuiDrawRectangle(itemBounds, GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH), GetColor(GuiGetStyle(DROPDOWNBOX, BORDER_COLOR_FOCUSED)), GetColor(GuiGetStyle(DROPDOWNBOX, BASE_COLOR_FOCUSED))); | 2564 GuiDrawRectangle(itemBounds, GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH), GetColor(GuiGetStyle(DROPDOWNBOX, BORDER_COLOR_FOCUSED)), GetColor(GuiGetStyle(DROPDOWNBOX, BASE_COLOR_FOCUSED))); |
| 2529 GuiDrawText(items[i], GetTextBounds(DROPDOWNBOX, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_FOCUSED))); | 2565 GuiDrawText(items[i], GetTextBounds(DROPDOWNBOX, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_FOCUSED))); |
| 2530 } | 2566 } |
| 2531 else GuiDrawText(items[i], GetTextBounds(DROPDOWNBOX, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_NORMAL))); | 2567 else GuiDrawText(items[i], GetTextBounds(DROPDOWNBOX, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_NORMAL))); |
| 2568 } | |
| 2569 } | |
| 2570 | |
| 2571 if (!GuiGetStyle(DROPDOWNBOX, DROPDOWN_ARROW_HIDDEN)) | |
| 2572 { | |
| 2573 // Draw arrows (using icon if available) | |
| 2574 #if defined(RAYGUI_NO_ICONS) | |
| 2575 GuiDrawText("v", RAYGUI_CLITERAL(Rectangle){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_PADDING), bounds.y + bounds.height/2 - 2, 10, 10 }, | |
| 2576 TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + (state*3)))); | |
| 2577 #else | |
| 2578 GuiDrawText(direction? "#121#" : "#120#", RAYGUI_CLITERAL(Rectangle){ bounds.x + bounds.width - GuiGetStyle(DROPDOWNBOX, ARROW_PADDING), bounds.y + bounds.height/2 - 6, 10, 10 }, | |
| 2579 TEXT_ALIGN_CENTER, GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + (state*3)))); // ICON_ARROW_DOWN_FILL | |
| 2580 #endif | |
| 2581 } | |
| 2582 //-------------------------------------------------------------------- | |
| 2583 | |
| 2584 *active = itemSelected; | |
| 2585 | |
| 2586 // TODO: Use result to return more internal states: mouse-press out-of-bounds, mouse-press over selected-item... | |
| 2587 return result; // Mouse click: result = 1 | |
| 2588 } | |
| 2589 | |
| 2590 // JUNE | |
| 2591 int GuiDropdownBoxRounded(Rectangle bounds, const char *text, int *active, bool editMode, float roundness, int segments) | |
| 2592 { | |
| 2593 int result = 0; | |
| 2594 GuiState state = guiState; | |
| 2595 | |
| 2596 int temp = 0; | |
| 2597 if (active == NULL) active = &temp; | |
| 2598 | |
| 2599 int itemSelected = *active; | |
| 2600 int itemFocused = -1; | |
| 2601 | |
| 2602 int direction = 0; // Dropdown box open direction: down (default) | |
| 2603 if (GuiGetStyle(DROPDOWNBOX, DROPDOWN_ROLL_UP) == 1) direction = 1; // Up | |
| 2604 | |
| 2605 // Get substrings items from text (items pointers, lengths and count) | |
| 2606 int itemCount = 0; | |
| 2607 const char **items = GuiTextSplit(text, ';', &itemCount, NULL); | |
| 2608 | |
| 2609 Rectangle boundsOpen = bounds; | |
| 2610 boundsOpen.height = (itemCount + 1)*(bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING)); | |
| 2611 if (direction == 1) boundsOpen.y -= itemCount*(bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING)) + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING); | |
| 2612 | |
| 2613 Rectangle itemBounds = bounds; | |
| 2614 | |
| 2615 // Update control | |
| 2616 //-------------------------------------------------------------------- | |
| 2617 if ((state != STATE_DISABLED) && (editMode || !guiLocked) && (itemCount > 1) && !guiControlExclusiveMode) | |
| 2618 { | |
| 2619 Vector2 mousePoint = GetMousePosition(); | |
| 2620 | |
| 2621 if (editMode) | |
| 2622 { | |
| 2623 state = STATE_PRESSED; | |
| 2624 | |
| 2625 // Check if mouse has been pressed or released outside limits | |
| 2626 if (!CheckCollisionPointRec(mousePoint, boundsOpen)) | |
| 2627 { | |
| 2628 if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) result = 1; | |
| 2629 } | |
| 2630 | |
| 2631 // Check if already selected item has been pressed again | |
| 2632 if (CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) result = 1; | |
| 2633 | |
| 2634 // Check focused and selected item | |
| 2635 for (int i = 0; i < itemCount; i++) | |
| 2636 { | |
| 2637 // Update item rectangle y position for next item | |
| 2638 if (direction == 0) itemBounds.y += (bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING)); | |
| 2639 else itemBounds.y -= (bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING)); | |
| 2640 | |
| 2641 if (CheckCollisionPointRec(mousePoint, itemBounds)) | |
| 2642 { | |
| 2643 itemFocused = i; | |
| 2644 if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) | |
| 2645 { | |
| 2646 itemSelected = i; | |
| 2647 result = 1; // Item selected | |
| 2648 } | |
| 2649 break; | |
| 2650 } | |
| 2651 } | |
| 2652 | |
| 2653 itemBounds = bounds; | |
| 2654 } | |
| 2655 else | |
| 2656 { | |
| 2657 if (CheckCollisionPointRec(mousePoint, bounds)) | |
| 2658 { | |
| 2659 if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) | |
| 2660 { | |
| 2661 result = 1; | |
| 2662 state = STATE_PRESSED; | |
| 2663 } | |
| 2664 else state = STATE_FOCUSED; | |
| 2665 } | |
| 2666 } | |
| 2667 } | |
| 2668 //-------------------------------------------------------------------- | |
| 2669 | |
| 2670 // Draw control | |
| 2671 //-------------------------------------------------------------------- | |
| 2672 if (editMode) GuiPanel(boundsOpen, NULL); | |
| 2673 | |
| 2674 // Main (closed) control: draw rounded background + rounded border | |
| 2675 { | |
| 2676 int borderWidth = GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH); | |
| 2677 Color borderColor = GetColor(GuiGetStyle(DROPDOWNBOX, BORDER + state*3)); | |
| 2678 Color baseColor = GetColor(GuiGetStyle(DROPDOWNBOX, BASE + state*3)); | |
| 2679 | |
| 2680 // Filled rounded rect | |
| 2681 DrawRectangleRounded(bounds, roundness, segments, baseColor); | |
| 2682 } | |
| 2683 | |
| 2684 GuiDrawText(items[itemSelected], GetTextBounds(DROPDOWNBOX, bounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT + state*3))); | |
| 2685 | |
| 2686 if (editMode) | |
| 2687 { | |
| 2688 // Draw visible items | |
| 2689 for (int i = 0; i < itemCount; i++) | |
| 2690 { | |
| 2691 // Update item rectangle y position for next item | |
| 2692 if (direction == 0) itemBounds.y += (bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING)); | |
| 2693 else itemBounds.y -= (bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_SPACING)); | |
| 2694 | |
| 2695 bool isLastVisible = (i == itemCount - 1); | |
| 2696 | |
| 2697 if (i == itemSelected) | |
| 2698 { | |
| 2699 Color borderColor = GetColor(GuiGetStyle(DROPDOWNBOX, BORDER_COLOR_PRESSED)); | |
| 2700 Color baseColor = GetColor(GuiGetStyle(DROPDOWNBOX, BASE_COLOR_PRESSED)); | |
| 2701 int borderWidth = GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH); | |
| 2702 | |
| 2703 if (isLastVisible) | |
| 2704 { | |
| 2705 DrawRectangleRounded(itemBounds, roundness, segments, baseColor); | |
| 2706 } | |
| 2707 else | |
| 2708 { | |
| 2709 DrawRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height, baseColor); | |
| 2710 if (borderWidth > 0) DrawRectangleLinesEx(itemBounds, borderWidth, borderColor); | |
| 2711 } | |
| 2712 | |
| 2713 GuiDrawText(items[i], GetTextBounds(DROPDOWNBOX, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_PRESSED))); | |
| 2714 } | |
| 2715 else if (i == itemFocused) | |
| 2716 { | |
| 2717 Color borderColor = GetColor(GuiGetStyle(DROPDOWNBOX, BORDER_COLOR_FOCUSED)); | |
| 2718 Color baseColor = GetColor(GuiGetStyle(DROPDOWNBOX, BASE_COLOR_FOCUSED)); | |
| 2719 int borderWidth = GuiGetStyle(DROPDOWNBOX, BORDER_WIDTH); | |
| 2720 | |
| 2721 if (isLastVisible) | |
| 2722 { | |
| 2723 DrawRectangleRounded(itemBounds, roundness, segments, baseColor); | |
| 2724 } | |
| 2725 else | |
| 2726 { | |
| 2727 DrawRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height, baseColor); | |
| 2728 if (borderWidth > 0) DrawRectangleLinesEx(itemBounds, borderWidth, borderColor); | |
| 2729 } | |
| 2730 | |
| 2731 GuiDrawText(items[i], GetTextBounds(DROPDOWNBOX, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_FOCUSED))); | |
| 2732 } | |
| 2733 else | |
| 2734 { | |
| 2735 // Normal item: draw only text (background left as panel background), | |
| 2736 // but if you want a visible background for normal items, uncomment the following: | |
| 2737 // DrawRectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height, GetColor(GuiGetStyle(DROPDOWNBOX, BASE_COLOR_NORMAL))); | |
| 2738 GuiDrawText(items[i], GetTextBounds(DROPDOWNBOX, itemBounds), GuiGetStyle(DROPDOWNBOX, TEXT_ALIGNMENT), GetColor(GuiGetStyle(DROPDOWNBOX, TEXT_COLOR_NORMAL))); | |
| 2739 } | |
| 2532 } | 2740 } |
| 2533 } | 2741 } |
| 2534 | 2742 |
| 2535 if (!GuiGetStyle(DROPDOWNBOX, DROPDOWN_ARROW_HIDDEN)) | 2743 if (!GuiGetStyle(DROPDOWNBOX, DROPDOWN_ARROW_HIDDEN)) |
| 2536 { | 2744 { |