Browse Source

Merge pull request #1542 from JimMarlowe/JM-UILIST-STR

Add UISelectList accessors to get list strings
JoshEngebretson 8 years ago
parent
commit
e11a504f92
2 changed files with 32 additions and 0 deletions
  1. 27 0
      Source/Atomic/UI/UISelectList.cpp
  2. 5 0
      Source/Atomic/UI/UISelectList.h

+ 27 - 0
Source/Atomic/UI/UISelectList.cpp

@@ -123,6 +123,20 @@ String UISelectList::GetSelectedItemID()
     return id_;
 }
 
+/// Returns the string of the selected item from the list widget
+String UISelectList::GetSelectedItemString()
+{
+    int selected = ((TBSelectList*)widget_)->GetValue();
+    TBSelectItemSource *tbsource = (TBSelectItemSource*)((TBSelectList*)widget_)->GetSource();
+    if ( tbsource && selected >= 0 && selected < tbsource->GetNumItems() )
+    {
+        const char *strx = tbsource->GetItemString(selected);
+        if (strx )
+            return ( tbsource->GetItemString(selected) );
+    }
+    return String::EMPTY;
+}
+
 bool UISelectList::GetItemSelected(int index)
 {
     if (!widget_)
@@ -146,6 +160,19 @@ String UISelectList::GetItemID(int index)
 
 }
 
+/// Returns the string of item at the requested index from the list widget
+String UISelectList::GetItemString(int index)
+{
+    TBSelectItemSource *tbsource = (TBSelectItemSource*)((TBSelectList*)widget_)->GetSource();
+    if ( tbsource && index >= 0 && index < tbsource->GetNumItems() )
+    {
+        const char *strx = tbsource->GetItemString(index);
+        if (strx != NULL)
+            return ( tbsource->GetItemString(index) );
+    }
+    return String::EMPTY;
+}
+
 String UISelectList::GetHoverItemID()
 {
     if (!widget_)

+ 5 - 0
Source/Atomic/UI/UISelectList.h

@@ -70,6 +70,11 @@ public:
 
     void SetUIListView(bool value);
 
+    /// Returns the string of item at the requested index
+    String GetItemString(int index);
+    /// Returns the string of the selected item
+    String GetSelectedItemString();
+
 protected:
 
     void HandleUIUpdate(StringHash eventType, VariantMap& eventData);