mirror of
https://github.com/raysan5/raygui.git
synced 2026-02-02 12:19:17 -05:00
GuiListViewEx return focused element. Changing how the active elements draws when you are not editing the listview.
This commit is contained in:
@ -56,6 +56,7 @@ int main()
|
|||||||
|
|
||||||
int listViewExScrollIndex = 0;
|
int listViewExScrollIndex = 0;
|
||||||
int listViewExActive = -1;
|
int listViewExActive = -1;
|
||||||
|
int listViewExFocus = -1;
|
||||||
const char *listViewExList[8] = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" };
|
const char *listViewExList[8] = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" };
|
||||||
int listViewExElementsEnable[8] = {1, 0, 1, 1, 0, 0, 1};
|
int listViewExElementsEnable[8] = {1, 0, 1, 1, 0, 0, 1};
|
||||||
bool listViewExEditMode = false;
|
bool listViewExEditMode = false;
|
||||||
@ -103,7 +104,8 @@ int main()
|
|||||||
|
|
||||||
// Second GUI column
|
// Second GUI column
|
||||||
if (GuiListView((Rectangle){ 185, 25, 120, 100 }, listViewList, 6, &listViewScrollIndex, &listViewActive, listViewEditMode)) listViewEditMode = !listViewEditMode;
|
if (GuiListView((Rectangle){ 185, 25, 120, 100 }, listViewList, 6, &listViewScrollIndex, &listViewActive, listViewEditMode)) listViewEditMode = !listViewEditMode;
|
||||||
if (GuiListViewEx((Rectangle){ 185, 155, 120, 200 }, listViewExList, listViewExElementsEnable, 8, &listViewExScrollIndex, &listViewExActive, listViewExEditMode)) listViewExEditMode = !listViewExEditMode;
|
if (GuiListViewEx((Rectangle){ 185, 155, 120, 200 }, listViewExList, listViewExElementsEnable, 8, &listViewExScrollIndex, &listViewExActive, &listViewExFocus, listViewExEditMode)) listViewExEditMode = !listViewExEditMode;
|
||||||
|
if (listViewExFocus >= 0 && listViewExFocus < 8) DrawText(listViewExList[listViewExFocus], 195, 370, 20, RED);
|
||||||
|
|
||||||
// Third GUI column
|
// Third GUI column
|
||||||
if (GuiTextBoxMulti((Rectangle){ 325, 25, 225, 175 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
|
if (GuiTextBoxMulti((Rectangle){ 325, 25, 225, 175 }, multiTextBoxText, 141, multiTextBoxEditMode)) multiTextBoxEditMode = !multiTextBoxEditMode;
|
||||||
|
|||||||
63
src/raygui.h
63
src/raygui.h
@ -409,7 +409,7 @@ RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text);
|
|||||||
|
|
||||||
// Advance controls set
|
// Advance controls set
|
||||||
RAYGUIDEF bool GuiListView(Rectangle bounds, const char **text, int count, int*scrollIndex, int *active, bool editMode); // List View control, returns selected list element index
|
RAYGUIDEF bool GuiListView(Rectangle bounds, const char **text, int count, int*scrollIndex, int *active, bool editMode); // List View control, returns selected list element index
|
||||||
RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, bool editMode);
|
RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, int*focus, bool editMode);
|
||||||
RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color); // Color Picker control
|
RAYGUIDEF Color GuiColorPicker(Rectangle bounds, Color color); // Color Picker control
|
||||||
RAYGUIDEF bool GuiMessageBox(Rectangle bounds, const char *windowTitle, const char *message); // Message Box control, displays a message
|
RAYGUIDEF bool GuiMessageBox(Rectangle bounds, const char *windowTitle, const char *message); // Message Box control, displays a message
|
||||||
|
|
||||||
@ -2870,13 +2870,20 @@ static bool GuiListElement(Rectangle bounds, const char *text, bool active, bool
|
|||||||
} break;
|
} break;
|
||||||
case PRESSED:
|
case PRESSED:
|
||||||
{
|
{
|
||||||
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, LISTELEMENT_BORDER_WIDTH, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_PRESSED]), guiAlpha));
|
DrawRectangleLinesEx(bounds, LISTELEMENT_BORDER_WIDTH, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_PRESSED]), guiAlpha));
|
||||||
GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(style[LISTVIEW_TEXT_COLOR_PRESSED]), guiAlpha));
|
GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(style[LISTVIEW_TEXT_COLOR_PRESSED]), guiAlpha));
|
||||||
} break;
|
} break;
|
||||||
case DISABLED:
|
case DISABLED:
|
||||||
{
|
{
|
||||||
GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(style[LISTVIEW_TEXT_COLOR_DISABLED]), guiAlpha));
|
if (active)
|
||||||
|
{
|
||||||
|
DrawRectangle(bounds.x, bounds.y, bounds.width, bounds.height, Fade(GetColor(style[LISTVIEW_BASE_COLOR_DISABLED]), guiAlpha));
|
||||||
|
DrawRectangleLinesEx(bounds, LISTELEMENT_BORDER_WIDTH, Fade(GetColor(style[LISTVIEW_BORDER_COLOR_NORMAL]), guiAlpha));
|
||||||
|
GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(style[LISTVIEW_TEXT_COLOR_NORMAL]), guiAlpha));
|
||||||
|
|
||||||
|
}
|
||||||
|
else GuiDrawText(text, bounds.x + bounds.width/2 - textWidth/2, bounds.y + bounds.height/2 - textHeight/2, Fade(GetColor(style[LISTVIEW_TEXT_COLOR_DISABLED]), guiAlpha));
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
@ -2888,16 +2895,19 @@ static bool GuiListElement(Rectangle bounds, const char *text, bool active, bool
|
|||||||
// List View control, returns selected list element index // int *startIndex)
|
// List View control, returns selected list element index // int *startIndex)
|
||||||
RAYGUIDEF bool GuiListView(Rectangle bounds, const char **text, int count, int*scrollIndex, int *active, bool editMode)
|
RAYGUIDEF bool GuiListView(Rectangle bounds, const char **text, int count, int*scrollIndex, int *active, bool editMode)
|
||||||
{
|
{
|
||||||
return GuiListViewEx(bounds, text, NULL, count, scrollIndex, active, editMode);
|
int focusDefault = 0;
|
||||||
|
return GuiListViewEx(bounds, text, NULL, count, scrollIndex, active, &focusDefault, editMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, bool editMode)
|
RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, int*focus, bool editMode)
|
||||||
{
|
{
|
||||||
#define LISTVIEW_LINE_THICK 1
|
#define LISTVIEW_LINE_THICK 1
|
||||||
|
|
||||||
bool usingEnableList = false;
|
bool usingEnableList = false;
|
||||||
if (enabledElements != NULL) usingEnableList = true;
|
if (enabledElements != NULL) usingEnableList = true;
|
||||||
|
|
||||||
|
int focusElement = -1;
|
||||||
|
|
||||||
GuiControlState state = guiState;
|
GuiControlState state = guiState;
|
||||||
|
|
||||||
bool pressed = false;
|
bool pressed = false;
|
||||||
@ -2927,6 +2937,15 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
|
|||||||
endIndex = count;
|
endIndex = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate position X and width to draw each element.
|
||||||
|
int posX = bounds.x + style[LISTVIEW_BAR_WIDTH] + style[LISTVIEW_ELEMENTS_PADDING];
|
||||||
|
int elementWidth = bounds.width - style[LISTVIEW_BAR_WIDTH] - 2*style[LISTVIEW_ELEMENTS_PADDING] - LISTVIEW_LINE_THICK;
|
||||||
|
if (!useScrollBar)
|
||||||
|
{
|
||||||
|
posX = bounds.x + style[LISTVIEW_ELEMENTS_PADDING];
|
||||||
|
elementWidth = bounds.width - 2*style[LISTVIEW_ELEMENTS_PADDING] - LISTVIEW_LINE_THICK;
|
||||||
|
}
|
||||||
|
|
||||||
if ((state != DISABLED) && !guiLocked) // && !guiLocked
|
if ((state != DISABLED) && !guiLocked) // && !guiLocked
|
||||||
{
|
{
|
||||||
Vector2 mousePoint = GetMousePosition();
|
Vector2 mousePoint = GetMousePosition();
|
||||||
@ -3004,7 +3023,19 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(0)) pressed = true;
|
if (!CheckCollisionPointRec(mousePoint, bounds))
|
||||||
|
{
|
||||||
|
if (IsMouseButtonPressed(0) || GetMouseWheelMove() != 0) pressed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get focused element
|
||||||
|
for (int i = startIndex; i < endIndex; i++)
|
||||||
|
{
|
||||||
|
if (CheckCollisionPointRec(mousePoint, (Rectangle){ posX, bounds.y + style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK + (i - startIndex)*(style[LISTVIEW_ELEMENTS_HEIGHT] + style[LISTVIEW_ELEMENTS_PADDING]), elementWidth, style[LISTVIEW_ELEMENTS_HEIGHT] }))
|
||||||
|
{
|
||||||
|
focusElement = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3029,14 +3060,6 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
|
|||||||
// Draw background
|
// Draw background
|
||||||
DrawRectangleRec(bounds, GetColor(style[DEFAULT_BACKGROUND_COLOR]));
|
DrawRectangleRec(bounds, GetColor(style[DEFAULT_BACKGROUND_COLOR]));
|
||||||
|
|
||||||
int posX = bounds.x + style[LISTVIEW_BAR_WIDTH] + style[LISTVIEW_ELEMENTS_PADDING];
|
|
||||||
int elementWidth = bounds.width - style[LISTVIEW_BAR_WIDTH] - 2*style[LISTVIEW_ELEMENTS_PADDING] - LISTVIEW_LINE_THICK;
|
|
||||||
if (!useScrollBar)
|
|
||||||
{
|
|
||||||
posX = bounds.x + style[LISTVIEW_ELEMENTS_PADDING];
|
|
||||||
elementWidth = bounds.width - 2*style[LISTVIEW_ELEMENTS_PADDING] - LISTVIEW_LINE_THICK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw scrollBar background
|
// Draw scrollBar background
|
||||||
if (useScrollBar) DrawRectangle(bounds.x, bounds.y, style[LISTVIEW_BAR_WIDTH], bounds.height, Fade(GetColor(style[DEFAULT_BORDER_COLOR_DISABLED]), guiAlpha));
|
if (useScrollBar) DrawRectangle(bounds.x, bounds.y, style[LISTVIEW_BAR_WIDTH], bounds.height, Fade(GetColor(style[DEFAULT_BORDER_COLOR_DISABLED]), guiAlpha));
|
||||||
|
|
||||||
@ -3056,7 +3079,12 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
|
|||||||
GuiListElement((Rectangle){ posX, bounds.y + style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK + (i - startIndex)*(style[LISTVIEW_ELEMENTS_HEIGHT] + style[LISTVIEW_ELEMENTS_PADDING]), elementWidth, style[LISTVIEW_ELEMENTS_HEIGHT] }, text[i], false, false);
|
GuiListElement((Rectangle){ posX, bounds.y + style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK + (i - startIndex)*(style[LISTVIEW_ELEMENTS_HEIGHT] + style[LISTVIEW_ELEMENTS_PADDING]), elementWidth, style[LISTVIEW_ELEMENTS_HEIGHT] }, text[i], false, false);
|
||||||
GuiEnable();
|
GuiEnable();
|
||||||
}
|
}
|
||||||
else if (i == auxActive) GuiListElement((Rectangle){ posX, bounds.y + style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK + (i - startIndex)*(style[LISTVIEW_ELEMENTS_HEIGHT] + style[LISTVIEW_ELEMENTS_PADDING]), elementWidth, style[LISTVIEW_ELEMENTS_HEIGHT] }, text[i], true, false);
|
else if (i == auxActive)
|
||||||
|
{
|
||||||
|
GuiDisable();
|
||||||
|
GuiListElement((Rectangle){ posX, bounds.y + style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK + (i - startIndex)*(style[LISTVIEW_ELEMENTS_HEIGHT] + style[LISTVIEW_ELEMENTS_PADDING]), elementWidth, style[LISTVIEW_ELEMENTS_HEIGHT] }, text[i], true, false);
|
||||||
|
GuiEnable();
|
||||||
|
}
|
||||||
else GuiListElement((Rectangle){ posX, bounds.y + style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK + (i - startIndex)*(style[LISTVIEW_ELEMENTS_HEIGHT] + style[LISTVIEW_ELEMENTS_PADDING]), elementWidth, style[LISTVIEW_ELEMENTS_HEIGHT] }, text[i], false, false);
|
else GuiListElement((Rectangle){ posX, bounds.y + style[LISTVIEW_ELEMENTS_PADDING] + LISTVIEW_LINE_THICK + (i - startIndex)*(style[LISTVIEW_ELEMENTS_HEIGHT] + style[LISTVIEW_ELEMENTS_PADDING]), elementWidth, style[LISTVIEW_ELEMENTS_HEIGHT] }, text[i], false, false);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
@ -3118,6 +3146,7 @@ RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledEl
|
|||||||
}
|
}
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
*scrollIndex = startIndex;
|
*scrollIndex = startIndex;
|
||||||
|
*focus = focusElement;
|
||||||
*active = auxActive;
|
*active = auxActive;
|
||||||
return pressed;
|
return pressed;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user