#include "raylib.h"
#undef RAYGUI_IMPLEMENTATION
#include "../../src/raygui.h"
#ifndef GUI_PROPERTY_LIST_H
#define GUI_PROPERTY_LIST_H
#ifdef __cplusplus
extern "C" { #endif
#define PROP_SET_FLAG(P, F) ((P)->flags |= (F))
#define PROP_CLEAR_FLAG(P, F) ((P)->flags &= ~(F))
#define PROP_TOGGLE_FLAG(P, F) ((P)->flags ^= (F))
#define PROP_CHECK_FLAG(P, F) ((P)->flags & (F))
#define PBOOL(N, F, V) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_BOOL, F, .value.vbool = V}
#define PINT(N, F, V) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_INT, F, .value.vint = {V,0,0,1}}
#define PINT_RANGE(N, F, V, S, MIN, MAX) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_INT, F, .value.vint = {V,MIN,MAX,S}}
#define PFLOAT(N, F, V) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_FLOAT, F, .value.vfloat = {V,0.f,0.f,1.0f,3}}
#define PFLOAT_RANGE(N, F, V, S, P, MIN, MAX) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_FLOAT, F, .value.vfloat = {V,MIN,MAX,S,P}}
#define PTEXT(N, F, V, S) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_TEXT, F, .value.vtext = {V, S} }
#define PSELECT(N, F, V, A) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_SELECT, F, .value.vselect = {V, A} }
#define PVEC2(N, F, X, Y) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_VECTOR2, F, .value.v2 = {X, Y} }
#define PVEC3(N, F, X, Y, Z) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_VECTOR3, F, .value.v3 = {X, Y, Z} }
#define PVEC4(N, F, X, Y, Z, W) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_VECTOR4, F, .value.v4 = {X, Y, Z, W} }
#define PRECT(N, F, X, Y, W, H) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_RECT, F, .value.vrect = {X, Y, W, H} }
#define PCOLOR(N, F, R, G, B, A) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_COLOR, F, .value.vcolor = {R, G, B, A} }
#define PSECTION(N, F, C) RAYGUI_CLITERAL(GuiDMProperty){N, GUI_PROP_SECTION, F, .value.vsection = (C)}
enum GuiDMPropertyTypes {
GUI_PROP_BOOL = 0,
GUI_PROP_INT,
GUI_PROP_FLOAT,
GUI_PROP_TEXT,
GUI_PROP_SELECT,
GUI_PROP_VECTOR2,
GUI_PROP_VECTOR3,
GUI_PROP_VECTOR4,
GUI_PROP_RECT,
GUI_PROP_COLOR,
GUI_PROP_SECTION,
};
enum GuiDMPropertyFlags {
GUI_PFLAG_COLLAPSED = 1 << 0, GUI_PFLAG_DISABLED = 1 << 1, };
typedef struct {
char* name;
short type;
short flags;
union {
bool vbool;
struct { int val; int min; int max; int step; } vint;
struct { float val; float min; float max; float step; int precision; } vfloat;
struct { char* val; int size; } vtext;
struct { char* val; int active; } vselect;
int vsection;
Vector2 v2;
Vector3 v3;
Vector4 v4;
Rectangle vrect;
Color vcolor;
} value;
} GuiDMProperty;
double GuiDMValueBox(Rectangle bounds, double value, double minValue, double maxValue, int precision, bool editMode);
double GuiDMSpinner(Rectangle bounds, double value, double minValue, double maxValue, double step, int precision, bool editMode);
void GuiDMPropertyList(Rectangle bounds, GuiDMProperty* props, int count, int* focus, int* scrollIndex);
bool GuiDMSaveProperties(const char* file, GuiDMProperty* props, int count);
#ifdef __cplusplus
}
#endif
#endif
#if defined(GUI_PROPERTY_LIST_IMPLEMENTATION)
#include "../../src/raygui.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifndef __cplusplus
#if __STDC_VERSION__ >= 199901L
#include <stdbool.h>
#endif
#endif
double GuiDMValueBox(Rectangle bounds, double value, double minValue, double maxValue, int precision, bool editMode) {
static int framesCounter = 0; static int cursor = 0;
enum {cursorTimer = 6, maxChars = 31, textPadding = 2};
GuiState state = GuiGetState();
if(maxValue != minValue){
if(value < minValue) value = minValue;
if(value > maxValue) value = maxValue;
}
char textValue[maxChars + 1] = "\0";
snprintf(textValue, maxChars, "%.*f", precision, value); int len = strlen(textValue);
bool valueHasChanged = false;
if ((state != STATE_DISABLED) && !guiLocked)
{
if (editMode)
{
if(cursor > len) cursor = len;
if(cursor < 0) cursor = 0;
state = STATE_PRESSED;
framesCounter++;
if(IsKeyPressed(KEY_RIGHT) || (IsKeyDown(KEY_RIGHT) && (framesCounter%cursorTimer == 0))) {
++cursor;
framesCounter = 0;
} else if(IsKeyPressed(KEY_LEFT) || (IsKeyDown(KEY_LEFT) && (framesCounter%cursorTimer == 0))) {
--cursor;
framesCounter = 0;
} else if (IsKeyPressed(KEY_BACKSPACE) || (IsKeyDown(KEY_BACKSPACE) && (framesCounter%cursorTimer) == 0)) {
if(cursor > 0) {
if(textValue[cursor-1] != '.') {
if(cursor < len )
memmove(&textValue[cursor-1], &textValue[cursor], len-cursor);
textValue[len - 1] = '\0';
valueHasChanged = true;
}
--cursor;
}
framesCounter = 0;
} else if (IsKeyPressed(KEY_DELETE) || (IsKeyDown(KEY_DELETE) && (framesCounter%cursorTimer) == 0)) {
if(len > 0 && cursor < len && textValue[cursor] != '.') {
memmove(&textValue[cursor], &textValue[cursor+1], len-cursor);
textValue[len] = '\0';
len -= 1;
valueHasChanged = true;
}
} else if (IsKeyPressed(KEY_HOME)) {
cursor = 0;
} else if (IsKeyPressed(KEY_END)) {
cursor = len;
} else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_C)) {
SetClipboardText(textValue);
} else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_X)) {
SetClipboardText(textValue);
textValue[0] = '\0';
cursor = len = 0;
value = 0.0; } else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_V)) {
const char* clip = GetClipboardText();
int clipLen = strlen(clip);
clipLen = clipLen > maxChars ? maxChars : clipLen;
memcpy(textValue, clip, clipLen);
len = clipLen;
textValue[len] = '\0';
valueHasChanged = true;
}
else {
int key = GetKeyPressed();
if( ((len < maxChars) && (key >= 48) && (key <= 57)) || (key == 46) || (key == 45) ) {
if(precision != 0 && cursor < len) { memmove(&textValue[cursor], &textValue[cursor-1], len+1-cursor);
textValue[len+1] = '\0';
textValue[cursor] = (char)key;
cursor++;
valueHasChanged = true;
}
else if(precision == 0) {
if(cursor < len) memmove(&textValue[cursor], &textValue[cursor-1], len+1-cursor);
len += 1;
textValue[len+1] = '\0';
textValue[cursor] = (char)key;
cursor++;
valueHasChanged = true;
}
}
}
if(cursor > len) cursor = len;
if(cursor < 0) cursor = 0;
}
else
{
if (CheckCollisionPointRec(GetMousePosition(), bounds))
{
state = STATE_FOCUSED;
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) framesCounter = 0;
}
}
}
DrawRectangleLinesEx(bounds, GuiGetStyle(VALUEBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(VALUEBOX, BORDER + (state*3))), guiAlpha));
Rectangle textBounds = {bounds.x + GuiGetStyle(VALUEBOX, BORDER_WIDTH) + textPadding, bounds.y + GuiGetStyle(VALUEBOX, BORDER_WIDTH),
bounds.width - 2*(GuiGetStyle(VALUEBOX, BORDER_WIDTH) + textPadding), bounds.height - 2*GuiGetStyle(VALUEBOX, BORDER_WIDTH)};
int textWidth = GuiGetTextWidth(textValue);
if(textWidth > textBounds.width) textBounds.width = textWidth;
if (state == STATE_PRESSED)
{
DrawRectangle(bounds.x + GuiGetStyle(VALUEBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(VALUEBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(VALUEBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(VALUEBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(VALUEBOX, BASE_COLOR_PRESSED)), guiAlpha));
if (editMode && ((framesCounter/20)%2 == 0)) {
int textWidthCursor = -2;
if(cursor > 0) {
char c = textValue[cursor];
textValue[cursor] = '\0';
textWidthCursor = GuiGetTextWidth(textValue);
textValue[cursor] = c;
}
DrawRectangle(bounds.x + textWidthCursor + (int)((bounds.width - textWidth - textPadding)/2.0f) + 2, bounds.y + 2*GuiGetStyle(VALUEBOX, BORDER_WIDTH), 1, bounds.height - 4*GuiGetStyle(VALUEBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(VALUEBOX, BORDER_COLOR_PRESSED)), guiAlpha));
}
}
else if (state == STATE_DISABLED)
{
DrawRectangle(bounds.x + GuiGetStyle(VALUEBOX, BORDER_WIDTH), bounds.y + GuiGetStyle(VALUEBOX, BORDER_WIDTH), bounds.width - 2*GuiGetStyle(VALUEBOX, BORDER_WIDTH), bounds.height - 2*GuiGetStyle(VALUEBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(VALUEBOX, BASE_COLOR_DISABLED)), guiAlpha));
}
GuiDrawText(textValue, textBounds, TEXT_ALIGN_CENTER, Fade(GetColor(GuiGetStyle(VALUEBOX, TEXT + (state*3))), guiAlpha));
value = valueHasChanged ? strtod(textValue, NULL) : value;
if(maxValue != minValue){
if(value < minValue) value = minValue;
if(value > maxValue) value = maxValue;
}
return value;
}
double GuiDMSpinner(Rectangle bounds, double value, double minValue, double maxValue, double step, int precision, bool editMode) {
GuiState state = GuiGetState();
Rectangle spinner = { bounds.x + GuiGetStyle(VALUEBOX, SPINNER_BUTTON_WIDTH) + GuiGetStyle(VALUEBOX, SPINNER_BUTTON_SPACING), bounds.y,
bounds.width - 2*(GuiGetStyle(VALUEBOX, SPINNER_BUTTON_WIDTH) + GuiGetStyle(VALUEBOX, SPINNER_BUTTON_SPACING)), bounds.height };
Rectangle leftButtonBound = { (float)bounds.x, (float)bounds.y, (float)GuiGetStyle(VALUEBOX, SPINNER_BUTTON_WIDTH), (float)bounds.height };
Rectangle rightButtonBound = { (float)bounds.x + bounds.width - GuiGetStyle(VALUEBOX, SPINNER_BUTTON_WIDTH),
(float)bounds.y, (float)GuiGetStyle(VALUEBOX, SPINNER_BUTTON_WIDTH), (float)bounds.height };
if ((state != STATE_DISABLED) && !guiLocked)
{
Vector2 mousePoint = GetMousePosition();
if (CheckCollisionPointRec(mousePoint, bounds))
{
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = STATE_PRESSED;
else state = STATE_FOCUSED;
}
}
int tempBorderWidth = GuiGetStyle(BUTTON, BORDER_WIDTH);
int tempTextAlign = GuiGetStyle(BUTTON, TEXT_ALIGNMENT);
GuiSetStyle(BUTTON, BORDER_WIDTH, GuiGetStyle(VALUEBOX, BORDER_WIDTH));
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, TEXT_ALIGN_CENTER);
#if defined(RAYGUI_SUPPORT_RICONS)
if (GuiButton(leftButtonBound, GuiIconText(RICON_ARROW_LEFT_FILL, NULL))) value -= step;
if (GuiButton(rightButtonBound, GuiIconText(RICON_ARROW_RIGHT_FILL, NULL))) value += step;
#else
if (GuiButton(leftButtonBound, "<")) value -= step;
if (GuiButton(rightButtonBound, ">")) value += step;
#endif
GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlign);
GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth);
value = GuiDMValueBox(spinner, value, minValue, maxValue, precision, editMode);
return value;
}
void GuiDMPropertyList(Rectangle bounds, GuiDMProperty* props, int count, int* focus, int* scrollIndex) {
#ifdef RAYGUI_SUPPORT_RICONS
#define PROPERTY_COLLAPSED_ICON "#120#"
#define PROPERTY_EXPANDED_ICON "#121#"
#else
#define PROPERTY_COLLAPSED_ICON "+"
#define PROPERTY_EXPANDED_ICON "-"
#endif
#define PROPERTY_PADDING 6
#define PROPERTY_ICON_SIZE 16
#define PROPERTY_DECIMAL_DIGITS 3
GuiState state = GuiGetState();
int propFocused = (focus == NULL)? -1 : *focus;
int scroll = *scrollIndex > 0 ? 0 : *scrollIndex;
const int propSlots[] = {1,1,1,2,1,3,4,5,5,5,1};
Rectangle absoluteBounds = {0}; for(int p=0; p<count; ++p) {
int height = GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
if(props[p].type < (sizeof(propSlots)/sizeof(propSlots[0]))) {
if(!PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED)) height = propSlots[props[p].type]*GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
if(props[p].type == GUI_PROP_SECTION && (PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED))) p += props[p].value.vsection; }
absoluteBounds.height += height+1;
}
bool useScrollBar = absoluteBounds.height > bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH) ? true : false;
if(!useScrollBar && scroll != 0) scroll = 0;
Rectangle scrollBarBounds = {bounds.x + GuiGetStyle(LISTVIEW, BORDER_WIDTH), bounds.y + GuiGetStyle(LISTVIEW, BORDER_WIDTH),
GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH), bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH)};
absoluteBounds.x = bounds.x + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING) + GuiGetStyle(DEFAULT, BORDER_WIDTH);
absoluteBounds.y = bounds.y + GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING) + GuiGetStyle(DEFAULT, BORDER_WIDTH) + scroll;
absoluteBounds.width = bounds.width - 2*(GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING) + GuiGetStyle(DEFAULT, BORDER_WIDTH));
if(useScrollBar) {
if(GuiGetStyle(LISTVIEW, SCROLLBAR_SIDE) == SCROLLBAR_LEFT_SIDE)
absoluteBounds.x += GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH); else
scrollBarBounds.x = bounds.x + bounds.width - GuiGetStyle(LISTVIEW, BORDER_WIDTH) - GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH); absoluteBounds.width -= GuiGetStyle(LISTVIEW, SCROLLBAR_WIDTH); }
int maxScroll = absoluteBounds.height + 2*(GuiGetStyle(LISTVIEW, LIST_ITEMS_SPACING) + GuiGetStyle(DEFAULT, BORDER_WIDTH))-bounds.height;
Vector2 mousePos = GetMousePosition();
if ((state != STATE_DISABLED) && !guiLocked) {
if(!CheckCollisionPointRec(mousePos, bounds)) {
propFocused = -1;
}
if (useScrollBar)
{
int wheelMove = GetMouseWheelMove();
scroll += wheelMove*count;
if(-scroll > maxScroll) scroll = -maxScroll;
}
}
DrawRectangleRec(bounds, Fade(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)), guiAlpha) ); DrawRectangleLinesEx(bounds, GuiGetStyle(DEFAULT, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(LISTVIEW, BORDER + state*3)), guiAlpha));
BeginScissorMode(absoluteBounds.x, bounds.y + GuiGetStyle(DEFAULT, BORDER_WIDTH), absoluteBounds.width, bounds.height - 2*GuiGetStyle(DEFAULT, BORDER_WIDTH));
int currentHeight = 0;
for(int p=0; p<count; ++p)
{
int height = GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
if(props[p].type < (sizeof(propSlots)/sizeof(propSlots[0])) && !PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED) )
height = propSlots[props[p].type]*GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
if(absoluteBounds.y + currentHeight + height >= bounds.y && absoluteBounds.y + currentHeight <= bounds.y + bounds.height)
{
Rectangle propBounds = {absoluteBounds.x, absoluteBounds.y + currentHeight, absoluteBounds.width, height};
Color textColor = Fade(GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_NORMAL)), guiAlpha);
int propState = STATE_NORMAL;
if(PROP_CHECK_FLAG(&props[p], GUI_PFLAG_DISABLED)) {
propState = STATE_DISABLED;
propBounds.height += 1;
DrawRectangleRec(propBounds, Fade(GetColor(GuiGetStyle(LISTVIEW, BASE_COLOR_DISABLED)), guiAlpha));
propBounds.height -= 1;
textColor = Fade(GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_DISABLED)), guiAlpha);
} else {
if(CheckCollisionPointRec(mousePos, propBounds) && !guiLocked) {
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
propState = STATE_PRESSED;
textColor = Fade(GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_PRESSED)), guiAlpha);
} else {
propState = STATE_FOCUSED;
propFocused = p;
textColor = Fade(GetColor(GuiGetStyle(LISTVIEW, TEXT_COLOR_FOCUSED)), guiAlpha);
}
} else propState = STATE_NORMAL;
}
if(propState == STATE_DISABLED) GuiSetState(propState);
switch(props[p].type)
{
case GUI_PROP_BOOL: {
GuiDrawText(props[p].name, (Rectangle){propBounds.x + PROPERTY_PADDING, propBounds.y, propBounds.width/2-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_LEFT, textColor);
if(propState == STATE_PRESSED) props[p].value.vbool = !props[p].value.vbool;
const bool locked = guiLocked;
GuiLock(); GuiCheckBox((Rectangle){propBounds.x+propBounds.width/2, propBounds.y + height/4, height/2, height/2}, props[p].value.vbool? "Yes" : "No", &props[p].value.vbool);
if(!locked) GuiUnlock(); } break;
case GUI_PROP_INT:
GuiDrawText(props[p].name, (Rectangle){propBounds.x + PROPERTY_PADDING, propBounds.y, propBounds.width/2-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_LEFT, textColor);
props[p].value.vint.val = GuiDMSpinner((Rectangle){propBounds.x+propBounds.width/2, propBounds.y + 1, propBounds.width/2, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 2},
props[p].value.vint.val, props[p].value.vint.min, props[p].value.vint.max, props[p].value.vint.step, 0, (propState == STATE_FOCUSED) );
break;
case GUI_PROP_FLOAT:
GuiDrawText(props[p].name, (Rectangle){propBounds.x + PROPERTY_PADDING, propBounds.y, propBounds.width/2-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_LEFT, textColor);
props[p].value.vfloat.val = GuiDMSpinner((Rectangle){propBounds.x+propBounds.width/2, propBounds.y + 1, propBounds.width/2, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 2},
props[p].value.vfloat.val, props[p].value.vfloat.min, props[p].value.vfloat.max, props[p].value.vfloat.step, props[p].value.vfloat.precision, (propState == STATE_FOCUSED) );
break;
case GUI_PROP_TEXT: {
Rectangle titleBounds = { propBounds.x, propBounds.y, propBounds.width, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) };
if((propState == STATE_PRESSED) && CheckCollisionPointRec(mousePos, titleBounds))
PROP_TOGGLE_FLAG(&props[p], GUI_PFLAG_COLLAPSED);
GuiDrawText(PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED) ? PROPERTY_COLLAPSED_ICON : PROPERTY_EXPANDED_ICON, titleBounds, TEXT_ALIGN_LEFT, textColor);
GuiDrawText(props[p].name, (Rectangle){propBounds.x+PROPERTY_ICON_SIZE+PROPERTY_PADDING, propBounds.y, propBounds.width-PROPERTY_ICON_SIZE-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_LEFT, textColor);
GuiDrawText(TextFormat("%i/%i", strlen(props[p].value.vtext.val), props[p].value.vtext.size), (Rectangle){propBounds.x+propBounds.width/2, propBounds.y + 1, propBounds.width/2, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 2}, TEXT_ALIGN_LEFT, textColor);
if(!PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED))
GuiTextBox((Rectangle){propBounds.x, propBounds.y + GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)+1, propBounds.width, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)-2}, props[p].value.vtext.val, props[p].value.vtext.size, (propState == STATE_FOCUSED));
} break;
case GUI_PROP_SELECT: {
GuiDrawText(props[p].name, (Rectangle){propBounds.x + PROPERTY_PADDING, propBounds.y, propBounds.width/2-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_LEFT, textColor);
GuiComboBox((Rectangle){propBounds.x+propBounds.width/2, propBounds.y + 1, propBounds.width/2, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 2},
props[p].value.vselect.val, &props[p].value.vselect.active);
} break;
case GUI_PROP_VECTOR2: case GUI_PROP_VECTOR3: case GUI_PROP_VECTOR4: {
Rectangle titleBounds = { propBounds.x, propBounds.y, propBounds.width, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) };
if((propState == STATE_PRESSED) && CheckCollisionPointRec(mousePos, titleBounds))
PROP_TOGGLE_FLAG(&props[p], GUI_PFLAG_COLLAPSED);
const char* fmt = "";
if(props[p].type == GUI_PROP_VECTOR2) fmt = TextFormat("[%.0f, %.0f]", props[p].value.v2.x, props[p].value.v2.y);
else if(props[p].type == GUI_PROP_VECTOR3) fmt = TextFormat("[%.0f, %.0f, %.0f]", props[p].value.v3.x, props[p].value.v3.y, props[p].value.v3.z);
else fmt = TextFormat("[%.0f, %.0f, %.0f, %.0f]", props[p].value.v4.x, props[p].value.v4.y, props[p].value.v4.z, props[p].value.v4.w);
GuiDrawText(PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED) ? PROPERTY_COLLAPSED_ICON : PROPERTY_EXPANDED_ICON, titleBounds, TEXT_ALIGN_LEFT, textColor);
GuiDrawText(props[p].name, (Rectangle){propBounds.x+PROPERTY_ICON_SIZE+PROPERTY_PADDING, propBounds.y, propBounds.width-PROPERTY_ICON_SIZE-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_LEFT, textColor);
GuiDrawText(fmt, (Rectangle){propBounds.x+propBounds.width/2, propBounds.y + 1, propBounds.width/2, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 2}, TEXT_ALIGN_LEFT, textColor);
if(!PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED)) {
Rectangle slotBounds = { propBounds.x, propBounds.y+GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)+1, propBounds.width, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)-2};
Rectangle lblBounds = { propBounds.x+PROPERTY_PADDING, slotBounds.y, GuiGetTextWidth("A"), slotBounds.height};
Rectangle valBounds = { lblBounds.x+lblBounds.width+PROPERTY_PADDING, slotBounds.y, propBounds.width-lblBounds.width-2*PROPERTY_PADDING, slotBounds.height};
GuiDrawText("X", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.v2.x = GuiDMSpinner(valBounds, props[p].value.v2.x, 0.0, 0.0, 1.0, PROPERTY_DECIMAL_DIGITS, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
slotBounds.y += GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
lblBounds.y = valBounds.y = slotBounds.y;
GuiDrawText("Y", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.v2.y = GuiDMSpinner(valBounds, props[p].value.v2.y, 0.0, 0.0, 1.0, PROPERTY_DECIMAL_DIGITS, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
slotBounds.y += GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
lblBounds.y = valBounds.y = slotBounds.y;
if(props[p].type >= GUI_PROP_VECTOR3) {
GuiDrawText("Z", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.v3.z = GuiDMSpinner(valBounds, props[p].value.v3.z, 0.0, 0.0, 1.0, PROPERTY_DECIMAL_DIGITS, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
slotBounds.y += GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
lblBounds.y = valBounds.y = slotBounds.y;
}
if(props[p].type >= GUI_PROP_VECTOR4) {
GuiDrawText("W", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.v4.w = GuiDMSpinner(valBounds, props[p].value.v4.w, 0.0, 0.0, 1.0, PROPERTY_DECIMAL_DIGITS, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
}
}
} break;
case GUI_PROP_RECT:{
Rectangle titleBounds = { propBounds.x, propBounds.y, propBounds.width, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) };
if((propState == STATE_PRESSED) && CheckCollisionPointRec(mousePos, titleBounds))
PROP_TOGGLE_FLAG(&props[p], GUI_PFLAG_COLLAPSED);
GuiDrawText(PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED) ? PROPERTY_COLLAPSED_ICON : PROPERTY_EXPANDED_ICON, titleBounds, TEXT_ALIGN_LEFT, textColor);
GuiDrawText(props[p].name, (Rectangle){propBounds.x+PROPERTY_ICON_SIZE+PROPERTY_PADDING, propBounds.y, propBounds.width-PROPERTY_ICON_SIZE-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_LEFT, textColor);
GuiDrawText(TextFormat("[%.0f, %.0f, %.0f, %.0f]", props[p].value.vrect.x, props[p].value.vrect.y, props[p].value.vrect.width, props[p].value.vrect.height),
(Rectangle){propBounds.x+propBounds.width/2, propBounds.y + 1, propBounds.width/2, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 2}, TEXT_ALIGN_LEFT, textColor);
if(!PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED)) {
Rectangle slotBounds = { propBounds.x, propBounds.y+GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)+1, propBounds.width, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)-2};
Rectangle lblBounds = { propBounds.x+PROPERTY_PADDING, slotBounds.y, GuiGetTextWidth("Height"), slotBounds.height};
Rectangle valBounds = { lblBounds.x+lblBounds.width+PROPERTY_PADDING, slotBounds.y, propBounds.width-lblBounds.width-2*PROPERTY_PADDING, slotBounds.height};
GuiDrawText("X", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.vrect.x = GuiDMSpinner(valBounds, props[p].value.vrect.x, 0.0, 0.0, 1.0, 0, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
slotBounds.y += GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
lblBounds.y = valBounds.y = slotBounds.y;
GuiDrawText("Y", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.vrect.y = GuiDMSpinner(valBounds, props[p].value.vrect.y, 0.0, 0.0, 1.0, 0, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
slotBounds.y += GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
lblBounds.y = valBounds.y = slotBounds.y;
GuiDrawText("Width", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.vrect.width = GuiDMSpinner(valBounds, props[p].value.vrect.width, 0.0, 0.0, 1.0, 0, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
slotBounds.y += GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
lblBounds.y = valBounds.y = slotBounds.y;
GuiDrawText("Height", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.vrect.height = GuiDMSpinner(valBounds, props[p].value.vrect.height, 0.0, 0.0, 1.0, 0, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
}
} break;
case GUI_PROP_COLOR: {
Rectangle titleBounds = { propBounds.x, propBounds.y, propBounds.width, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) };
if((propState == STATE_PRESSED) && CheckCollisionPointRec(mousePos, titleBounds))
PROP_TOGGLE_FLAG(&props[p], GUI_PFLAG_COLLAPSED);
GuiDrawText(PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED) ? PROPERTY_COLLAPSED_ICON : PROPERTY_EXPANDED_ICON, titleBounds, TEXT_ALIGN_LEFT, textColor);
GuiDrawText(props[p].name, (Rectangle){propBounds.x+PROPERTY_ICON_SIZE+PROPERTY_PADDING, propBounds.y+1, propBounds.width-PROPERTY_ICON_SIZE-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)-2}, TEXT_ALIGN_LEFT, textColor);
DrawLineEx( (Vector2){propBounds.x+propBounds.width/2, propBounds.y + GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 5}, (Vector2){propBounds.x+propBounds.width, propBounds.y + GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 5}, 6.0f, props[p].value.vcolor);
const char* fmt = TextFormat("#%02X%02X%02X%02X", props[p].value.vcolor.r, props[p].value.vcolor.g, props[p].value.vcolor.b, props[p].value.vcolor.a);
char clip[10] = "\0";
memcpy(clip, fmt, 10*sizeof(char)); GuiDrawText(fmt, (Rectangle){propBounds.x+propBounds.width/2, propBounds.y + 1, propBounds.width/2, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 2}, TEXT_ALIGN_LEFT, textColor);
if(!PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED)) {
Rectangle slotBounds = { propBounds.x, propBounds.y+GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)+1, propBounds.width, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)-2};
Rectangle lblBounds = { propBounds.x+PROPERTY_PADDING, slotBounds.y, GuiGetTextWidth("A"), slotBounds.height};
Rectangle valBounds = { lblBounds.x+lblBounds.width+PROPERTY_PADDING, slotBounds.y, GuiGetTextWidth("000000"), slotBounds.height};
Rectangle sbarBounds = { valBounds.x + valBounds.width + PROPERTY_PADDING, slotBounds.y, slotBounds.width - 3*PROPERTY_PADDING - lblBounds.width - valBounds.width, slotBounds.height };
if(sbarBounds.width <= GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)-2) valBounds.width = propBounds.width-lblBounds.width-2*PROPERTY_PADDING; int tmpSliderPadding = GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING);
int tmpPadding = GuiGetStyle(SCROLLBAR, SCROLL_PADDING);
int tmpBorder = GuiGetStyle(SCROLLBAR, BORDER_WIDTH);
int tmpSliderSize = GuiGetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE);
int tmpArrows = GuiGetStyle(SCROLLBAR, ARROWS_VISIBLE);
Color tmpBG1 = GetColor(GuiGetStyle(DEFAULT, BORDER_COLOR_DISABLED));
GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING, 3);
GuiSetStyle(SCROLLBAR, SCROLL_PADDING, 10);
GuiSetStyle(SCROLLBAR, BORDER_WIDTH, 0);
GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, 6);
GuiSetStyle(SCROLLBAR, ARROWS_VISIBLE, 0);
GuiSetStyle(DEFAULT, BORDER_COLOR_DISABLED, GuiGetStyle(DEFAULT, BACKGROUND_COLOR));
GuiDrawText("R", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.vcolor.r = GuiDMValueBox(valBounds, props[p].value.vcolor.r, 0.0, 255.0, 0, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
if(sbarBounds.width > GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)-2)
props[p].value.vcolor.r = GuiScrollBar(sbarBounds, props[p].value.vcolor.r, 0, 255);
slotBounds.y += GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
lblBounds.y = valBounds.y = sbarBounds.y = slotBounds.y;
GuiDrawText("G", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.vcolor.g = GuiDMValueBox(valBounds, props[p].value.vcolor.g, 0.0, 255.0, 0, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
if(sbarBounds.width > GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)-2)
props[p].value.vcolor.g = GuiScrollBar(sbarBounds, props[p].value.vcolor.g, 0, 255);
slotBounds.y += GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
lblBounds.y = valBounds.y = sbarBounds.y = slotBounds.y;
GuiDrawText("B", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.vcolor.b = GuiDMValueBox(valBounds, props[p].value.vcolor.b, 0.0, 255.0, 0, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
if(sbarBounds.width > GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)-2)
props[p].value.vcolor.b = GuiScrollBar(sbarBounds, props[p].value.vcolor.b, 0, 255);
slotBounds.y += GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT);
lblBounds.y = valBounds.y = sbarBounds.y = slotBounds.y;
GuiDrawText("A", lblBounds, TEXT_ALIGN_LEFT, textColor);
props[p].value.vcolor.a = GuiDMValueBox(valBounds, props[p].value.vcolor.a, 0.0, 255.0, 0, (propState == STATE_FOCUSED) && CheckCollisionPointRec(mousePos, slotBounds) );
if(sbarBounds.width > GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)-2)
props[p].value.vcolor.a = GuiScrollBar(sbarBounds, props[p].value.vcolor.a, 0, 255);
GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_PADDING, tmpSliderPadding);
GuiSetStyle(SCROLLBAR, SCROLL_PADDING, tmpPadding);
GuiSetStyle(SCROLLBAR, BORDER_WIDTH, tmpBorder);
GuiSetStyle(SCROLLBAR, SCROLL_SLIDER_SIZE, tmpSliderSize);
GuiSetStyle(SCROLLBAR, ARROWS_VISIBLE, tmpArrows);
GuiSetStyle(DEFAULT, BORDER_COLOR_DISABLED, ColorToInt(tmpBG1));
}
if((propState == STATE_FOCUSED)) {
if(IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_C))
SetClipboardText(clip);
else if(IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_V)){
unsigned int a = props[p].value.vcolor.a, r = props[p].value.vcolor.r, g=props[p].value.vcolor.g, b=props[p].value.vcolor.b;
sscanf(GetClipboardText(), "#%02X%02X%02X%02X", &r, &g, &b, &a);
props[p].value.vcolor.r=r; props[p].value.vcolor.g=g; props[p].value.vcolor.b=b; props[p].value.vcolor.a=a;
}
}
} break;
case GUI_PROP_SECTION: {
Rectangle titleBounds = { propBounds.x, propBounds.y, propBounds.width, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) };
if( (propState == STATE_PRESSED) && CheckCollisionPointRec(mousePos, titleBounds) )
PROP_TOGGLE_FLAG(&props[p], GUI_PFLAG_COLLAPSED);
if(!PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED)) {
GuiDrawText(PROPERTY_EXPANDED_ICON, titleBounds, TEXT_ALIGN_LEFT, textColor);
GuiDrawText(props[p].name, (Rectangle){propBounds.x+PROPERTY_ICON_SIZE+PROPERTY_PADDING, propBounds.y, propBounds.width-PROPERTY_ICON_SIZE-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_CENTER, textColor);
} else {
GuiDrawText(PROPERTY_COLLAPSED_ICON, titleBounds, TEXT_ALIGN_LEFT, textColor);
GuiDrawText(TextFormat("%s [%i]", props[p].name, props[p].value.vsection), (Rectangle){propBounds.x+PROPERTY_ICON_SIZE+PROPERTY_PADDING, propBounds.y, propBounds.width-PROPERTY_ICON_SIZE-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_CENTER, textColor);
}
} break;
default: {
GuiDrawText(props[p].name, (Rectangle){propBounds.x + PROPERTY_PADDING, propBounds.y, propBounds.width/2-PROPERTY_PADDING, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT)}, TEXT_ALIGN_LEFT, textColor);
GuiDrawText(TextFormat("TYPE %i", props[p].type), (Rectangle){propBounds.x+propBounds.width/2, propBounds.y + 1, propBounds.width/2, GuiGetStyle(LISTVIEW, LIST_ITEMS_HEIGHT) - 2}, TEXT_ALIGN_LEFT, textColor);
} break;
}
GuiSetState(state);
}
currentHeight += height + 1;
if(props[p].type == GUI_PROP_SECTION && (PROP_CHECK_FLAG(&props[p], GUI_PFLAG_COLLAPSED))) p += props[p].value.vsection;
} EndScissorMode();
if(useScrollBar) {
scroll = -GuiScrollBar(scrollBarBounds, -scroll, 0, maxScroll);
*scrollIndex = scroll;
}
if(focus != NULL) *focus = propFocused;
}
bool GuiDMSaveProperties(const char* file, GuiDMProperty* props, int count) {
if(file == NULL || props == NULL) return false;
if(count == 0) return true;
FILE* f = fopen(file, "w");
if(f == NULL) return false;
fprintf(f, "#\n# Property types:\n"
"# b <name> <flags> <value> // Bool\n"
"# i <name> <flags> <value> <min> <max> <step> // Int\n"
"# f <name> <flags> <value> <min> <max> <step> <precision> // Float\n"
"# t <name> <flags> <value> <edit_length> // Text\n"
"# l <name> <flags> <value> <active> // Select\n"
"# g <name> <flags> <value> // Section (Group)\n"
"# v2 <name> <flags> <x> <y> // Vector 2D\n"
"# v3 <name> <flags> <x> <y> <z> // Vector 3D\n"
"# v4 <name> <flags> <x> <y> <z> <w> // Vector 4D\n"
"# r <name> <flags> <x> <y> <width> <height> // Rectangle\n"
"# c <name> <flags> <r> <g> <b> <a> // Color\n"
"#\n\n");
for(int p=0; p<count; ++p)
{
switch(props[p].type) {
case GUI_PROP_BOOL: fprintf(f, "b %s %i %i\n", props[p].name, (int)props[p].flags, (int)props[p].value.vbool);
break;
case GUI_PROP_INT: fprintf(f, "i %s %i %i %i %i %i\n", props[p].name, (int)props[p].flags, props[p].value.vint.val, props[p].value.vint.min,
props[p].value.vint.max, props[p].value.vint.step);
break;
case GUI_PROP_FLOAT: fprintf(f, "f %s %i %f %f %f %f %i\n", props[p].name, (int)props[p].flags, props[p].value.vfloat.val, props[p].value.vfloat.min,
props[p].value.vfloat.max, props[p].value.vfloat.step, props[p].value.vfloat.precision);
break;
case GUI_PROP_TEXT: fprintf(f, "t %s %i %s %i\n", props[p].name, (int)props[p].flags, props[p].value.vtext.val, props[p].value.vtext.size);
break;
case GUI_PROP_SELECT: fprintf(f, "l %s %i %s %i\n", props[p].name, (int)props[p].flags, props[p].value.vselect.val, props[p].value.vselect.active);
break;
case GUI_PROP_SECTION: fprintf(f, "g %s %i %i\n", props[p].name, (int)props[p].flags, props[p].value.vsection);
break;
case GUI_PROP_VECTOR2: fprintf(f, "v2 %s %i %f %f\n", props[p].name, (int)props[p].flags, props[p].value.v2.x, props[p].value.v2.y);
break;
case GUI_PROP_VECTOR3: fprintf(f, "v3 %s %i %f %f %f\n", props[p].name, (int)props[p].flags, props[p].value.v3.x, props[p].value.v3.y, props[p].value.v3.z);
break;
case GUI_PROP_VECTOR4: fprintf(f, "v4 %s %i %f %f %f %f\n", props[p].name, (int)props[p].flags, props[p].value.v4.x, props[p].value.v4.y,
props[p].value.v4.z, props[p].value.v4.w);
break;
case GUI_PROP_RECT: fprintf(f, "r %s %i %i %i %i %i\n", props[p].name, (int)props[p].flags, (int)props[p].value.vrect.x, (int)props[p].value.vrect.y,
(int)props[p].value.vrect.width, (int)props[p].value.vrect.height);
break;
case GUI_PROP_COLOR: fprintf(f, "c %s %i %i %i %i %i\n", props[p].name, (int)props[p].flags, props[p].value.vcolor.r, props[p].value.vcolor.g,
props[p].value.vcolor.b, props[p].value.vcolor.a);
break;
}
}
fclose(f);
return true;
}
#endif