mirror of
https://github.com/raysan5/raygui.git
synced 2026-02-03 20:59:18 -05:00
GuiListView: Start to review WIP
This commit is contained in:
@ -39,7 +39,7 @@ int main()
|
|||||||
int ValueBox002Value = 0;
|
int ValueBox002Value = 0;
|
||||||
char TextBox003Text[64] = "SAMPLE TEXT";
|
char TextBox003Text[64] = "SAMPLE TEXT";
|
||||||
int ListView004Active = 0;
|
int ListView004Active = 0;
|
||||||
const char *ListView004TextList[3] = { "ONE", "TWO", "THREE" };
|
const char *ListView004TextList[6] = { "Charmander", "Bulbasaur", "Squirtel", "Pikachu", "Eevee", "Pidgey" };
|
||||||
char TextBox006Text[141] = "SAMPLE TEXT";
|
char TextBox006Text[141] = "SAMPLE TEXT";
|
||||||
|
|
||||||
bool spinnerEditMode = false;
|
bool spinnerEditMode = false;
|
||||||
@ -72,7 +72,7 @@ int main()
|
|||||||
if (GuiValueBox((Rectangle){ 25, 125, 125, 30 }, &ValueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode;
|
if (GuiValueBox((Rectangle){ 25, 125, 125, 30 }, &ValueBox002Value, 0, 100, valueBoxEditMode)) valueBoxEditMode = !valueBoxEditMode;
|
||||||
if (GuiTextBox((Rectangle){ 25, 175, 125, 30 }, TextBox003Text, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;
|
if (GuiTextBox((Rectangle){ 25, 175, 125, 30 }, TextBox003Text, 64, textBoxEditMode)) textBoxEditMode = !textBoxEditMode;
|
||||||
|
|
||||||
ListView004Active = GuiListView((Rectangle){ 175, 25, 125, 325 }, ListView004TextList, 3, ListView004Active);
|
ListView004Active = GuiListView((Rectangle){ 175, 25, 125, 115 }, ListView004TextList, 6, ListView004Active);
|
||||||
if (GuiButton((Rectangle){ 25, 225, 125, 30 }, "SAMPLE TEXT")) Button005();
|
if (GuiButton((Rectangle){ 25, 225, 125, 30 }, "SAMPLE TEXT")) Button005();
|
||||||
|
|
||||||
if (GuiTextBoxMulti((Rectangle){ 325, 25, 225, 175 }, TextBox006Text, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;;
|
if (GuiTextBoxMulti((Rectangle){ 325, 25, 225, 175 }, TextBox006Text, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;;
|
||||||
|
|||||||
45
src/raygui.h
45
src/raygui.h
@ -758,7 +758,7 @@ static int style[NUM_PROPERTIES] = {
|
|||||||
0x97af81ff, // COLORPICKER_BASE_COLOR_PRESSED ----> DEFAULT_TEXT_COLOR_PRESSED
|
0x97af81ff, // COLORPICKER_BASE_COLOR_PRESSED ----> DEFAULT_TEXT_COLOR_PRESSED
|
||||||
0x5b6462ff, // COLORPICKER_BORDER_COLOR_DISABLED ----> DEFAULT_BORDER_COLOR_DISABLED
|
0x5b6462ff, // COLORPICKER_BORDER_COLOR_DISABLED ----> DEFAULT_BORDER_COLOR_DISABLED
|
||||||
0x2c3334ff, // COLORPICKER_BASE_COLOR_DISABLED ----> DEFAULT_BASE_COLOR_DISABLED
|
0x2c3334ff, // COLORPICKER_BASE_COLOR_DISABLED ----> DEFAULT_BASE_COLOR_DISABLED
|
||||||
0x1e, // LISTVIEW_ELEMENTS_HEIGHT
|
0x1a, // LISTVIEW_ELEMENTS_HEIGHT
|
||||||
0x2, // LISTVIEW_ELEMENTS_PADDING
|
0x2, // LISTVIEW_ELEMENTS_PADDING
|
||||||
0xa, // LISTVIEW_BAR_WIDTH
|
0xa, // LISTVIEW_BAR_WIDTH
|
||||||
0x60827dff, // LISTVIEW_BORDER_COLOR_NORMAL ----> DEFAULT_BORDER_COLOR_NORMAL
|
0x60827dff, // LISTVIEW_BORDER_COLOR_NORMAL ----> DEFAULT_BORDER_COLOR_NORMAL
|
||||||
@ -2699,33 +2699,34 @@ RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text)
|
|||||||
// List Element control, returns element state
|
// List Element control, returns element state
|
||||||
static bool GuiListElement(Rectangle bounds, const char *text, bool active)
|
static bool GuiListElement(Rectangle bounds, const char *text, bool active)
|
||||||
{
|
{
|
||||||
#define GUILISTELEMENT_PADDING 2
|
#define LISTELEMENT_PADDING 2
|
||||||
#define GUILISTELEMENT_BORDER_WIDTH 1
|
#define LISTELEMENT_BORDER_WIDTH 1
|
||||||
|
|
||||||
GuiControlState state = guiState;
|
GuiControlState state = guiState;
|
||||||
|
|
||||||
int textWidth = MeasureText(text, style[DEFAULT_TEXT_SIZE]);
|
int textWidth = MeasureText(text, style[DEFAULT_TEXT_SIZE]);
|
||||||
int textHeight = style[DEFAULT_TEXT_SIZE];
|
int textHeight = style[DEFAULT_TEXT_SIZE];
|
||||||
|
|
||||||
if (bounds.width < textWidth) bounds.width = textWidth + GUILISTELEMENT_PADDING*2;
|
|
||||||
if (bounds.height < textHeight) bounds.height = textHeight;
|
|
||||||
|
|
||||||
// Update control
|
// Update control
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
if (state != DISABLED)
|
if (state != DISABLED)
|
||||||
{
|
{
|
||||||
|
if (bounds.width < textWidth) bounds.width = textWidth + LISTELEMENT_PADDING*2;
|
||||||
|
if (bounds.height < textHeight) bounds.height = textHeight;
|
||||||
|
|
||||||
Vector2 mousePoint = GetMousePosition();
|
Vector2 mousePoint = GetMousePosition();
|
||||||
|
|
||||||
// Check toggle button state
|
|
||||||
if (CheckCollisionPointRec(mousePoint, bounds))
|
if (CheckCollisionPointRec(mousePoint, bounds))
|
||||||
{
|
{
|
||||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = PRESSED;
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||||
else if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON))
|
|
||||||
{
|
{
|
||||||
state = NORMAL;
|
state = NORMAL;
|
||||||
active = !active;
|
active = !active;
|
||||||
}
|
}
|
||||||
else state = FOCUSED;
|
|
||||||
|
if (!active)
|
||||||
|
{
|
||||||
|
state = FOCUSED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
@ -2739,7 +2740,7 @@ static bool GuiListElement(Rectangle bounds, const char *text, bool active)
|
|||||||
if (active)
|
if (active)
|
||||||
{
|
{
|
||||||
DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[LISTVIEW_BASE_COLOR_PRESSED]), guiAlpha));
|
DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[LISTVIEW_BASE_COLOR_PRESSED]), guiAlpha));
|
||||||
DrawRectangleLinesEx(bounds, GUILISTELEMENT_BORDER_WIDTH, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_PRESSED]), guiAlpha));
|
DrawRectangleLinesEx(bounds, LISTELEMENT_BORDER_WIDTH, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_PRESSED]), guiAlpha));
|
||||||
DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], Fade(GetColor(style[LISTVIEW_TEXT_COLOR_PRESSED]), guiAlpha));
|
DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], Fade(GetColor(style[LISTVIEW_TEXT_COLOR_PRESSED]), guiAlpha));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2750,15 +2751,12 @@ static bool GuiListElement(Rectangle bounds, const char *text, bool active)
|
|||||||
case FOCUSED:
|
case FOCUSED:
|
||||||
{
|
{
|
||||||
DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[LISTVIEW_BASE_COLOR_FOCUSED]), guiAlpha));
|
DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[LISTVIEW_BASE_COLOR_FOCUSED]), guiAlpha));
|
||||||
DrawRectangleLinesEx(bounds, GUILISTELEMENT_BORDER_WIDTH, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_FOCUSED]), guiAlpha));
|
DrawRectangleLinesEx(bounds, LISTELEMENT_BORDER_WIDTH, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_FOCUSED]), guiAlpha));
|
||||||
DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], Fade(GetColor(style[LISTVIEW_TEXT_COLOR_FOCUSED]), guiAlpha));
|
DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], Fade(GetColor(style[LISTVIEW_TEXT_COLOR_FOCUSED]), guiAlpha));
|
||||||
} break;
|
} break;
|
||||||
case PRESSED:
|
/*case PRESSED: // NOT USED
|
||||||
{
|
{
|
||||||
DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[LISTVIEW_BASE_COLOR_PRESSED]), guiAlpha));
|
} break;*/
|
||||||
DrawRectangleLinesEx(bounds, GUILISTELEMENT_BORDER_WIDTH, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_PRESSED]), guiAlpha));
|
|
||||||
DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], Fade(GetColor(style[LISTVIEW_TEXT_COLOR_PRESSED]), guiAlpha));
|
|
||||||
} break;
|
|
||||||
case DISABLED:
|
case DISABLED:
|
||||||
{
|
{
|
||||||
DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], Fade(GetColor(style[LISTVIEW_TEXT_COLOR_DISABLED]), guiAlpha));
|
DrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, style[DEFAULT_TEXT_SIZE], Fade(GetColor(style[LISTVIEW_TEXT_COLOR_DISABLED]), guiAlpha));
|
||||||
@ -2787,11 +2785,12 @@ RAYGUIDEF int GuiListView(Rectangle bounds, const char **text, int count, int ac
|
|||||||
for(int i = 0; i < count; i++)
|
for(int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
int textWidth = MeasureText(text[i], style[DEFAULT_TEXT_SIZE]);
|
int textWidth = MeasureText(text[i], style[DEFAULT_TEXT_SIZE]);
|
||||||
|
|
||||||
if (bounds.width - style[LISTVIEW_BAR_WIDTH] - 2*style[LISTVIEW_ELEMENTS_PADDING] - LISTVIEW_LINE_THICK < textWidth)
|
if (bounds.width - style[LISTVIEW_BAR_WIDTH] - 2*style[LISTVIEW_ELEMENTS_PADDING] - LISTVIEW_LINE_THICK < textWidth)
|
||||||
{
|
{
|
||||||
bounds.width = textWidth + style[LISTVIEW_BAR_WIDTH] + 2*style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK;
|
bounds.width = textWidth + style[LISTVIEW_BAR_WIDTH] + 2*style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 mousePoint = GetMousePosition();
|
Vector2 mousePoint = GetMousePosition();
|
||||||
|
|
||||||
@ -2812,6 +2811,7 @@ RAYGUIDEF int GuiListView(Rectangle bounds, const char **text, int count, int ac
|
|||||||
|
|
||||||
if (endIndex > count) endIndex = count;
|
if (endIndex > count) endIndex = count;
|
||||||
|
|
||||||
|
// Comprueba si caben todas las listas en la caja sin necesitar scrollbar.
|
||||||
if (count*style[LISTVIEW_ELEMENTS_HEIGHT] <= bounds.height) startIndex = 0;
|
if (count*style[LISTVIEW_ELEMENTS_HEIGHT] <= bounds.height) startIndex = 0;
|
||||||
|
|
||||||
if (CheckCollisionPointRec(mousePoint, bounds))
|
if (CheckCollisionPointRec(mousePoint, bounds))
|
||||||
@ -2824,10 +2824,6 @@ RAYGUIDEF int GuiListView(Rectangle bounds, const char **text, int count, int ac
|
|||||||
}
|
}
|
||||||
else state = FOCUSED;
|
else state = FOCUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//(maxIndexCount + indexOffset) > count) ? count : (maxIndexCount + indexOffset)
|
|
||||||
//if (maxIndexCount + indexOffset) > count) return count;
|
|
||||||
//else return (maxIndexCount + indexOffset);
|
|
||||||
}
|
}
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
@ -2847,6 +2843,7 @@ RAYGUIDEF int GuiListView(Rectangle bounds, const char **text, int count, int ac
|
|||||||
|
|
||||||
DrawRectangle(bounds.x, bounds.y, style[LISTVIEW_BAR_WIDTH], bounds.height, Fade(LIGHTGRAY, guiAlpha));
|
DrawRectangle(bounds.x, bounds.y, style[LISTVIEW_BAR_WIDTH], bounds.height, Fade(LIGHTGRAY, guiAlpha));
|
||||||
|
|
||||||
|
// Revisar esto...
|
||||||
int barHeight = bounds.height - (count - (endIndex - startIndex))*style[LISTVIEW_ELEMENTS_HEIGHT];
|
int barHeight = bounds.height - (count - (endIndex - startIndex))*style[LISTVIEW_ELEMENTS_HEIGHT];
|
||||||
|
|
||||||
// TODO: Review bar logic when bar size should be shorter than LISTVIEW_ELEMENT_HEIGHT
|
// TODO: Review bar logic when bar size should be shorter than LISTVIEW_ELEMENT_HEIGHT
|
||||||
|
|||||||
Reference in New Issue
Block a user