瀏覽代碼

Updated GuiListView()

Ray 6 年之前
父節點
當前提交
972e7f403b
共有 2 個文件被更改,包括 20 次插入9 次删除
  1. 3 4
      examples/controls_test_suite/controls_test_suite.c
  2. 17 5
      src/raygui.h

+ 3 - 4
examples/controls_test_suite/controls_test_suite.c

@@ -60,13 +60,12 @@ int main()
     
     
     int listViewScrollIndex = 0;
     int listViewScrollIndex = 0;
     int listViewActive = -1;
     int listViewActive = -1;
-    const char *listViewList[6] = { "Charmander", "Bulbasaur", "Squirtel", "Pikachu", "Eevee", "Pidgey" };
     bool listViewEditMode = false;
     bool listViewEditMode = false;
     
     
     int listViewExScrollIndex = 0;
     int listViewExScrollIndex = 0;
     int listViewExActive = -1;
     int listViewExActive = -1;
     int listViewExFocus = -1;
     int listViewExFocus = -1;
-    const char *listViewExList[8] = { "This", "is", "a", "list view", "with", "disable", "elements", "amazing!" };
+    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;
     
     
@@ -136,8 +135,8 @@ int main()
             if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode;
             if (GuiDropdownBox((Rectangle){ 25, 25, 125, 30 }, "ONE;TWO;THREE", &dropdownBox000Active, dropDown000EditMode)) dropDown000EditMode = !dropDown000EditMode;
             
             
             // Second GUI column      
             // Second GUI column      
-            if (GuiListView((Rectangle){ 165, 25, 140, 140 }, listViewList, 6, &listViewScrollIndex, &listViewActive, listViewEditMode)) listViewEditMode = !listViewEditMode;
-            if (GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, listViewExElementsEnable, 8, &listViewExScrollIndex, &listViewExActive, &listViewExFocus, listViewExEditMode)) listViewExEditMode = !listViewExEditMode;
+            if (GuiListView((Rectangle){ 165, 25, 140, 140 }, "Charmander;Bulbasaur;Squirtel;Pikachu;Eevee;Pidgey", &listViewActive, &listViewScrollIndex, listViewEditMode)) listViewEditMode = !listViewEditMode;
+            if (GuiListViewEx((Rectangle){ 165, 180, 140, 200 }, listViewExList, 8, listViewExElementsEnable, &listViewExActive, &listViewExFocus, &listViewExScrollIndex, listViewExEditMode)) listViewExEditMode = !listViewExEditMode;
             if (listViewExFocus >= 0 && listViewExFocus < 8) DrawText(FormatText("FOCUS: %s", listViewExList[listViewExFocus]), 165, 390, 10, listViewExElementsEnable[listViewExFocus] ? LIME : MAROON);
             if (listViewExFocus >= 0 && listViewExFocus < 8) DrawText(FormatText("FOCUS: %s", listViewExList[listViewExFocus]), 165, 390, 10, listViewExElementsEnable[listViewExFocus] ? LIME : MAROON);
             
             
             toggleGroupActive = GuiToggleGroupEx((Rectangle){ 165, 400, 140, 25 }, "ONE;TWO;THREE;FOUR", toggleGroupActive, 4, 1);
             toggleGroupActive = GuiToggleGroupEx((Rectangle){ 165, 400, 140, 25 }, "ONE;TWO;THREE;FOUR", toggleGroupActive, 4, 1);

+ 17 - 5
src/raygui.h

@@ -350,8 +350,8 @@ RAYGUIDEF void GuiStatusBar(Rectangle bounds, const char *text, int offsetX);
 RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text);                                         // Dummy control for placeholders
 RAYGUIDEF void GuiDummyRec(Rectangle bounds, const char *text);                                         // Dummy control for placeholders
 
 
 // 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 GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, int *focus, bool editMode); // with List View extended parameters
+RAYGUIDEF bool GuiListView(Rectangle bounds, const char *text, int *active, int *scrollIndex, bool editMode);   // List View control, returns selected list element index
+RAYGUIDEF bool GuiListViewEx(Rectangle bounds, char **text, int count, int *enabled, int *active, int *focus, int *scrollIndex, bool editMode); // List View with extended parameters
 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
 RAYGUIDEF Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs);                                // Grid
 RAYGUIDEF Vector2 GuiGrid(Rectangle bounds, float spacing, int subdivs);                                // Grid
@@ -2277,13 +2277,25 @@ static bool GuiListElement(Rectangle bounds, const char *text, bool active, bool
 }
 }
 
 
 // List View control
 // List View control
-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 *active, int *scrollIndex, bool editMode)
 {
 {
-    return GuiListViewEx(bounds, text, NULL, count, scrollIndex, active, NULL, editMode);
+    bool result = 0;
+    int count = 0;
+    char **textList = TextSplit(text, ';', &count);
+    
+    result = GuiListViewEx(bounds, textList, count, NULL, active, NULL, scrollIndex, editMode);
+    
+    for (int i = 0; i < count; i++) free(textList[i]);
+    if (textList != NULL) free(textList);
+    
+    return result;
 }
 }
 
 
 // List View control extended parameters
 // List View control extended parameters
-RAYGUIDEF bool GuiListViewEx(Rectangle bounds, const char **text, int *enabledElements, int count, int *scrollIndex, int *active, int *focus, bool editMode)
+// NOTE: Elements could be disabled individually and focused element could be obtained:
+//  int *enabled defines an array with enabled elements inside the list
+//  int *focus returns focused element (may be not pressed)    
+RAYGUIDEF bool GuiListViewEx(Rectangle bounds, char **text, int count, int *enabled, int *active, int *focus, int *scrollIndex, bool editMode)
 {
 {
     GuiControlState state = guiState;
     GuiControlState state = guiState;
     bool pressed = false;
     bool pressed = false;