Browse Source

DropDownList: unsigned to int | ListView: fix asserts

1vanK 3 years ago
parent
commit
dcfeffc418

+ 18 - 18
Source/Urho3D/AngelScript/Generated_Members.h

@@ -25338,9 +25338,9 @@ template <class T> void RegisterMembers_DropDownList(asIScriptEngine* engine, co
     // void DropDownList::AddItem(UIElement* item)
     // void DropDownList::AddItem(UIElement* item)
     engine->RegisterObjectMethod(className, "void AddItem(UIElement@+)", AS_METHODPR(T, AddItem, (UIElement*), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void AddItem(UIElement@+)", AS_METHODPR(T, AddItem, (UIElement*), void), AS_CALL_THISCALL);
 
 
-    // UIElement* DropDownList::GetItem(unsigned index) const
-    engine->RegisterObjectMethod(className, "UIElement@+ GetItem(uint) const", AS_METHODPR(T, GetItem, (unsigned) const, UIElement*), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "UIElement@+ get_items(uint) const", AS_METHODPR(T, GetItem, (unsigned) const, UIElement*), AS_CALL_THISCALL);
+    // UIElement* DropDownList::GetItem(i32 index) const
+    engine->RegisterObjectMethod(className, "UIElement@+ GetItem(int) const", AS_METHODPR(T, GetItem, (i32) const, UIElement*), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "UIElement@+ get_items(int) const", AS_METHODPR(T, GetItem, (i32) const, UIElement*), AS_CALL_THISCALL);
 
 
     // Vector<UIElement*> DropDownList::GetItems() const
     // Vector<UIElement*> DropDownList::GetItems() const
     engine->RegisterObjectMethod(className, "Array<UIElement@>@ GetItems() const", AS_FUNCTION_OBJFIRST(DropDownList_VectorlesUIElementstargre_GetItems_void_template<DropDownList>), AS_CALL_CDECL_OBJFIRST);
     engine->RegisterObjectMethod(className, "Array<UIElement@>@ GetItems() const", AS_FUNCTION_OBJFIRST(DropDownList_VectorlesUIElementstargre_GetItems_void_template<DropDownList>), AS_CALL_CDECL_OBJFIRST);
@@ -25349,9 +25349,9 @@ template <class T> void RegisterMembers_DropDownList(asIScriptEngine* engine, co
     engine->RegisterObjectMethod(className, "ListView@+ GetListView() const", AS_METHODPR(T, GetListView, () const, ListView*), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "ListView@+ GetListView() const", AS_METHODPR(T, GetListView, () const, ListView*), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "ListView@+ get_listView() const", AS_METHODPR(T, GetListView, () const, ListView*), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "ListView@+ get_listView() const", AS_METHODPR(T, GetListView, () const, ListView*), AS_CALL_THISCALL);
 
 
-    // unsigned DropDownList::GetNumItems() const
-    engine->RegisterObjectMethod(className, "uint GetNumItems() const", AS_METHODPR(T, GetNumItems, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_numItems() const", AS_METHODPR(T, GetNumItems, () const, unsigned), AS_CALL_THISCALL);
+    // i32 DropDownList::GetNumItems() const
+    engine->RegisterObjectMethod(className, "int GetNumItems() const", AS_METHODPR(T, GetNumItems, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_numItems() const", AS_METHODPR(T, GetNumItems, () const, i32), AS_CALL_THISCALL);
 
 
     // UIElement* DropDownList::GetPlaceholder() const
     // UIElement* DropDownList::GetPlaceholder() const
     engine->RegisterObjectMethod(className, "UIElement@+ GetPlaceholder() const", AS_METHODPR(T, GetPlaceholder, () const, UIElement*), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "UIElement@+ GetPlaceholder() const", AS_METHODPR(T, GetPlaceholder, () const, UIElement*), AS_CALL_THISCALL);
@@ -25369,12 +25369,12 @@ template <class T> void RegisterMembers_DropDownList(asIScriptEngine* engine, co
     engine->RegisterObjectMethod(className, "UIElement@+ GetSelectedItem() const", AS_METHODPR(T, GetSelectedItem, () const, UIElement*), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "UIElement@+ GetSelectedItem() const", AS_METHODPR(T, GetSelectedItem, () const, UIElement*), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "UIElement@+ get_selectedItem() const", AS_METHODPR(T, GetSelectedItem, () const, UIElement*), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "UIElement@+ get_selectedItem() const", AS_METHODPR(T, GetSelectedItem, () const, UIElement*), AS_CALL_THISCALL);
 
 
-    // unsigned DropDownList::GetSelection() const
-    engine->RegisterObjectMethod(className, "uint GetSelection() const", AS_METHODPR(T, GetSelection, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_selection() const", AS_METHODPR(T, GetSelection, () const, unsigned), AS_CALL_THISCALL);
+    // i32 DropDownList::GetSelection() const
+    engine->RegisterObjectMethod(className, "int GetSelection() const", AS_METHODPR(T, GetSelection, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_selection() const", AS_METHODPR(T, GetSelection, () const, i32), AS_CALL_THISCALL);
 
 
-    // void DropDownList::InsertItem(unsigned index, UIElement* item)
-    engine->RegisterObjectMethod(className, "void InsertItem(uint, UIElement@+)", AS_METHODPR(T, InsertItem, (unsigned, UIElement*), void), AS_CALL_THISCALL);
+    // void DropDownList::InsertItem(i32 index, UIElement* item)
+    engine->RegisterObjectMethod(className, "void InsertItem(int, UIElement@+)", AS_METHODPR(T, InsertItem, (i32, UIElement*), void), AS_CALL_THISCALL);
 
 
     // void DropDownList::RemoveAllItems()
     // void DropDownList::RemoveAllItems()
     engine->RegisterObjectMethod(className, "void RemoveAllItems()", AS_METHODPR(T, RemoveAllItems, (), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void RemoveAllItems()", AS_METHODPR(T, RemoveAllItems, (), void), AS_CALL_THISCALL);
@@ -25382,8 +25382,8 @@ template <class T> void RegisterMembers_DropDownList(asIScriptEngine* engine, co
     // void DropDownList::RemoveItem(UIElement* item)
     // void DropDownList::RemoveItem(UIElement* item)
     engine->RegisterObjectMethod(className, "void RemoveItem(UIElement@+)", AS_METHODPR(T, RemoveItem, (UIElement*), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void RemoveItem(UIElement@+)", AS_METHODPR(T, RemoveItem, (UIElement*), void), AS_CALL_THISCALL);
 
 
-    // void DropDownList::RemoveItem(unsigned index)
-    engine->RegisterObjectMethod(className, "void RemoveItem(uint)", AS_METHODPR(T, RemoveItem, (unsigned), void), AS_CALL_THISCALL);
+    // void DropDownList::RemoveItem(i32 index)
+    engine->RegisterObjectMethod(className, "void RemoveItem(int)", AS_METHODPR(T, RemoveItem, (i32), void), AS_CALL_THISCALL);
 
 
     // void DropDownList::SetPlaceholderText(const String& text)
     // void DropDownList::SetPlaceholderText(const String& text)
     engine->RegisterObjectMethod(className, "void SetPlaceholderText(const String&in)", AS_METHODPR(T, SetPlaceholderText, (const String&), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetPlaceholderText(const String&in)", AS_METHODPR(T, SetPlaceholderText, (const String&), void), AS_CALL_THISCALL);
@@ -25393,12 +25393,12 @@ template <class T> void RegisterMembers_DropDownList(asIScriptEngine* engine, co
     engine->RegisterObjectMethod(className, "void SetResizePopup(bool)", AS_METHODPR(T, SetResizePopup, (bool), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetResizePopup(bool)", AS_METHODPR(T, SetResizePopup, (bool), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_resizePopup(bool)", AS_METHODPR(T, SetResizePopup, (bool), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_resizePopup(bool)", AS_METHODPR(T, SetResizePopup, (bool), void), AS_CALL_THISCALL);
 
 
-    // void DropDownList::SetSelection(unsigned index)
-    engine->RegisterObjectMethod(className, "void SetSelection(uint)", AS_METHODPR(T, SetSelection, (unsigned), void), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void set_selection(uint)", AS_METHODPR(T, SetSelection, (unsigned), void), AS_CALL_THISCALL);
+    // void DropDownList::SetSelection(i32 index)
+    engine->RegisterObjectMethod(className, "void SetSelection(int)", AS_METHODPR(T, SetSelection, (i32), void), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void set_selection(int)", AS_METHODPR(T, SetSelection, (i32), void), AS_CALL_THISCALL);
 
 
-    // void DropDownList::SetSelectionAttr(unsigned index)
-    engine->RegisterObjectMethod(className, "void SetSelectionAttr(uint)", AS_METHODPR(T, SetSelectionAttr, (unsigned), void), AS_CALL_THISCALL);
+    // void DropDownList::SetSelectionAttr(i32 index)
+    engine->RegisterObjectMethod(className, "void SetSelectionAttr(int)", AS_METHODPR(T, SetSelectionAttr, (i32), void), AS_CALL_THISCALL);
 
 
     #ifdef REGISTER_MEMBERS_MANUAL_PART_DropDownList
     #ifdef REGISTER_MEMBERS_MANUAL_PART_DropDownList
         REGISTER_MEMBERS_MANUAL_PART_DropDownList();
         REGISTER_MEMBERS_MANUAL_PART_DropDownList();

+ 16 - 11
Source/Urho3D/UI/DropDownList.cpp

@@ -55,7 +55,7 @@ void DropDownList::RegisterObject(Context* context)
 
 
     URHO3D_COPY_BASE_ATTRIBUTES(Menu);
     URHO3D_COPY_BASE_ATTRIBUTES(Menu);
     URHO3D_UPDATE_ATTRIBUTE_DEFAULT_VALUE("Focus Mode", FM_FOCUSABLE_DEFOCUSABLE);
     URHO3D_UPDATE_ATTRIBUTE_DEFAULT_VALUE("Focus Mode", FM_FOCUSABLE_DEFOCUSABLE);
-    URHO3D_ACCESSOR_ATTRIBUTE("Selection", GetSelection, SetSelectionAttr, unsigned, 0, AM_FILE);
+    URHO3D_ACCESSOR_ATTRIBUTE("Selection", GetSelection, SetSelectionAttr, i32, 0, AM_FILE);
     URHO3D_ACCESSOR_ATTRIBUTE("Resize Popup", GetResizePopup, SetResizePopup, bool, false, AM_FILE);
     URHO3D_ACCESSOR_ATTRIBUTE("Resize Popup", GetResizePopup, SetResizePopup, bool, false, AM_FILE);
 }
 }
 
 
@@ -134,15 +134,16 @@ void DropDownList::OnSetEditable()
 
 
 void DropDownList::AddItem(UIElement* item)
 void DropDownList::AddItem(UIElement* item)
 {
 {
-    InsertItem(M_MAX_UNSIGNED, item);
+    InsertItem(ENDPOS, item);
 }
 }
 
 
-void DropDownList::InsertItem(unsigned index, UIElement* item)
+void DropDownList::InsertItem(i32 index, UIElement* item)
 {
 {
+    assert(index >= 0 || index == ENDPOS);
     listView_->InsertItem(index, item);
     listView_->InsertItem(index, item);
 
 
     // If there was no selection, set to the first
     // If there was no selection, set to the first
-    if (GetSelection() == M_MAX_UNSIGNED)
+    if (GetSelection() == NINDEX)
         SetSelection(0);
         SetSelection(0);
 }
 }
 
 
@@ -151,8 +152,9 @@ void DropDownList::RemoveItem(UIElement* item)
     listView_->RemoveItem(item);
     listView_->RemoveItem(item);
 }
 }
 
 
-void DropDownList::RemoveItem(unsigned index)
+void DropDownList::RemoveItem(i32 index)
 {
 {
+    assert(index >= 0);
     listView_->RemoveItem(index);
     listView_->RemoveItem(index);
 }
 }
 
 
@@ -161,8 +163,9 @@ void DropDownList::RemoveAllItems()
     listView_->RemoveAllItems();
     listView_->RemoveAllItems();
 }
 }
 
 
-void DropDownList::SetSelection(unsigned index)
+void DropDownList::SetSelection(i32 index)
 {
 {
+    assert(index >= 0);
     listView_->SetSelection(index);
     listView_->SetSelection(index);
 }
 }
 
 
@@ -176,13 +179,14 @@ void DropDownList::SetResizePopup(bool enable)
     resizePopup_ = enable;
     resizePopup_ = enable;
 }
 }
 
 
-unsigned DropDownList::GetNumItems() const
+i32 DropDownList::GetNumItems() const
 {
 {
     return listView_->GetNumItems();
     return listView_->GetNumItems();
 }
 }
 
 
-UIElement* DropDownList::GetItem(unsigned index) const
+UIElement* DropDownList::GetItem(i32 index) const
 {
 {
+    assert(index >= 0);
     return listView_->GetItem(index);
     return listView_->GetItem(index);
 }
 }
 
 
@@ -191,7 +195,7 @@ Vector<UIElement*> DropDownList::GetItems() const
     return listView_->GetItems();
     return listView_->GetItems();
 }
 }
 
 
-unsigned DropDownList::GetSelection() const
+i32 DropDownList::GetSelection() const
 {
 {
     return listView_->GetSelection();
     return listView_->GetSelection();
 }
 }
@@ -206,8 +210,9 @@ const String& DropDownList::GetPlaceholderText() const
     return placeholder_->GetChildStaticCast<Text>(0)->GetText();
     return placeholder_->GetChildStaticCast<Text>(0)->GetText();
 }
 }
 
 
-void DropDownList::SetSelectionAttr(unsigned index)
+void DropDownList::SetSelectionAttr(i32 index)
 {
 {
+    assert(index >= 0);
     selectionAttr_ = index;
     selectionAttr_ = index;
 
 
     // We may not have the list items yet. Apply the index again in ApplyAttributes().
     // We may not have the list items yet. Apply the index again in ApplyAttributes().
@@ -321,7 +326,7 @@ void DropDownList::HandleListViewKey(StringHash eventType, VariantMap& eventData
 void DropDownList::HandleSelectionChanged(StringHash eventType, VariantMap& eventData)
 void DropDownList::HandleSelectionChanged(StringHash eventType, VariantMap& eventData)
 {
 {
     // Display the place holder text when there is no selection, however, the place holder text is only visible when the place holder itself is set to visible
     // Display the place holder text when there is no selection, however, the place holder text is only visible when the place holder itself is set to visible
-    placeholder_->GetChild(0)->SetVisible(GetSelection() == M_MAX_UNSIGNED);
+    placeholder_->GetChild(0)->SetVisible(GetSelection() == NINDEX);
 }
 }
 
 
 }
 }

+ 10 - 10
Source/Urho3D/UI/DropDownList.h

@@ -37,17 +37,17 @@ public:
 
 
     /// Add item to the end of the list.
     /// Add item to the end of the list.
     void AddItem(UIElement* item);
     void AddItem(UIElement* item);
-    /// Insert item to a specific position.
-    void InsertItem(unsigned index, UIElement* item);
+    /// Insert item to a specific position. index can be ENDPOS.
+    void InsertItem(i32 index, UIElement* item);
     /// Remove specific item.
     /// Remove specific item.
     void RemoveItem(UIElement* item);
     void RemoveItem(UIElement* item);
     /// Remove item at index.
     /// Remove item at index.
-    void RemoveItem(unsigned index);
+    void RemoveItem(i32 index);
     /// Remove all items.
     /// Remove all items.
     void RemoveAllItems();
     void RemoveAllItems();
     /// Set selection.
     /// Set selection.
     /// @property
     /// @property
-    void SetSelection(unsigned index);
+    void SetSelection(i32 index);
     /// Set place holder text. This is the text shown when there is no selection (-1) in drop down list. Note that if the list has items, the default is to show the first item, so the "no selection" state has to be set explicitly.
     /// Set place holder text. This is the text shown when there is no selection (-1) in drop down list. Note that if the list has items, the default is to show the first item, so the "no selection" state has to be set explicitly.
     /// @property
     /// @property
     void SetPlaceholderText(const String& text);
     void SetPlaceholderText(const String& text);
@@ -57,15 +57,15 @@ public:
 
 
     /// Return number of items.
     /// Return number of items.
     /// @property
     /// @property
-    unsigned GetNumItems() const;
+    i32 GetNumItems() const;
     /// Return item at index.
     /// Return item at index.
     /// @property{get_items}
     /// @property{get_items}
-    UIElement* GetItem(unsigned index) const;
+    UIElement* GetItem(i32 index) const;
     /// Return all items.
     /// Return all items.
     Vector<UIElement*> GetItems() const;
     Vector<UIElement*> GetItems() const;
-    /// Return selection index, or M_MAX_UNSIGNED if none selected.
+    /// Return selection index, or NINDEX if none selected.
     /// @property
     /// @property
-    unsigned GetSelection() const;
+    i32 GetSelection() const;
     /// Return selected item, or null if none selected.
     /// Return selected item, or null if none selected.
     /// @property
     /// @property
     UIElement* GetSelectedItem() const;
     UIElement* GetSelectedItem() const;
@@ -87,7 +87,7 @@ public:
     bool GetResizePopup() const { return resizePopup_; }
     bool GetResizePopup() const { return resizePopup_; }
 
 
     /// Set selection attribute.
     /// Set selection attribute.
-    void SetSelectionAttr(unsigned index);
+    void SetSelectionAttr(i32 index);
 
 
 protected:
 protected:
     /// Filter implicit attributes in serialization process.
     /// Filter implicit attributes in serialization process.
@@ -111,7 +111,7 @@ private:
     void HandleSelectionChanged(StringHash eventType, VariantMap& eventData);
     void HandleSelectionChanged(StringHash eventType, VariantMap& eventData);
 
 
     /// Selected item index attribute.
     /// Selected item index attribute.
-    unsigned selectionAttr_;
+    i32 selectionAttr_;
 };
 };
 
 
 }
 }

+ 4 - 4
Source/Urho3D/UI/ListView.cpp

@@ -771,14 +771,14 @@ void ListView::SetSelectOnClickEnd(bool enable)
 
 
 void ListView::Expand(i32 index, bool enable, bool recursive)
 void ListView::Expand(i32 index, bool enable, bool recursive)
 {
 {
-    assert(index >= 0);
+    assert(index >= 0 || index == NINDEX);
 
 
     if (!hierarchyMode_)
     if (!hierarchyMode_)
         return;
         return;
 
 
     i32 numItems = GetNumItems();
     i32 numItems = GetNumItems();
-    if (index >= numItems)
-        return;
+    if (index >= numItems || index == NINDEX)
+        return; // TODO: write out of range warning to log
 
 
     UIElement* item = GetItem(index++);
     UIElement* item = GetItem(index++);
     SetItemExpanded(item, enable);
     SetItemExpanded(item, enable);
@@ -935,7 +935,7 @@ bool ListView::IsSelected(i32 index) const
 
 
 bool ListView::IsExpanded(i32 index) const
 bool ListView::IsExpanded(i32 index) const
 {
 {
-    assert(index >= 0);
+    assert(index >= 0 || index == NINDEX);
     return GetItemExpanded(contentElement_->GetChild(index));
     return GetItemExpanded(contentElement_->GetChild(index));
 }
 }