Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

UIElement: unsigned to signed #2972

Merged
merged 1 commit into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions Source/Urho3D/AngelScript/Generated_Members.h
Original file line number Diff line number Diff line change
Expand Up @@ -16375,8 +16375,8 @@ template <class T> void RegisterMembers_UIElement(asIScriptEngine* engine, const
// void UIElement::BringToFront()
engine->RegisterObjectMethod(className, "void BringToFront()", AS_METHODPR(T, BringToFront, (), void), AS_CALL_THISCALL);

// UIElement* UIElement::CreateChild(StringHash type, const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED)
engine->RegisterObjectMethod(className, "UIElement@+ CreateChild(StringHash, const String&in = String::EMPTY, uint = M_MAX_UNSIGNED)", AS_METHODPR(T, CreateChild, (StringHash, const String&, unsigned), UIElement*), AS_CALL_THISCALL);
// UIElement* UIElement::CreateChild(StringHash type, const String& name = String::EMPTY, i32 index = ENDPOS)
engine->RegisterObjectMethod(className, "UIElement@+ CreateChild(StringHash, const String&in = String::EMPTY, int = ENDPOS)", AS_METHODPR(T, CreateChild, (StringHash, const String&, i32), UIElement*), AS_CALL_THISCALL);

// void UIElement::DisableLayoutUpdate()
engine->RegisterObjectMethod(className, "void DisableLayoutUpdate()", AS_METHODPR(T, DisableLayoutUpdate, (), void), AS_CALL_THISCALL);
Expand All @@ -16390,8 +16390,8 @@ template <class T> void RegisterMembers_UIElement(asIScriptEngine* engine, const
// bool UIElement::FilterAttributes(XMLElement& dest) const
engine->RegisterObjectMethod(className, "bool FilterAttributes(XMLElement&) const", AS_METHODPR(T, FilterAttributes, (XMLElement&) const, bool), AS_CALL_THISCALL);

// unsigned UIElement::FindChild(UIElement* element) const
engine->RegisterObjectMethod(className, "uint FindChild(UIElement@+) const", AS_METHODPR(T, FindChild, (UIElement*) const, unsigned), AS_CALL_THISCALL);
// i32 UIElement::FindChild(UIElement* element) const
engine->RegisterObjectMethod(className, "int FindChild(UIElement@+) const", AS_METHODPR(T, FindChild, (UIElement*) const, i32), AS_CALL_THISCALL);

// const String& UIElement::GetAppliedStyle() const
engine->RegisterObjectMethod(className, "const String& GetAppliedStyle() const", AS_METHODPR(T, GetAppliedStyle, () const, const String&), AS_CALL_THISCALL);
Expand All @@ -16405,9 +16405,9 @@ template <class T> void RegisterMembers_UIElement(asIScriptEngine* engine, const
engine->RegisterObjectMethod(className, "bool GetBringToFront() const", AS_METHODPR(T, GetBringToFront, () const, bool), AS_CALL_THISCALL);
engine->RegisterObjectMethod(className, "bool get_bringToFront() const", AS_METHODPR(T, GetBringToFront, () const, bool), AS_CALL_THISCALL);

// UIElement* UIElement::GetChild(unsigned index) const
engine->RegisterObjectMethod(className, "UIElement@+ GetChild(uint) const", AS_METHODPR(T, GetChild, (unsigned) const, UIElement*), AS_CALL_THISCALL);
engine->RegisterObjectMethod(className, "UIElement@+ get_children(uint) const", AS_METHODPR(T, GetChild, (unsigned) const, UIElement*), AS_CALL_THISCALL);
// UIElement* UIElement::GetChild(i32 index) const
engine->RegisterObjectMethod(className, "UIElement@+ GetChild(int) const", AS_METHODPR(T, GetChild, (i32) const, UIElement*), AS_CALL_THISCALL);
engine->RegisterObjectMethod(className, "UIElement@+ get_children(int) const", AS_METHODPR(T, GetChild, (i32) const, UIElement*), AS_CALL_THISCALL);

// UIElement* UIElement::GetChild(const String& name, bool recursive = false) const
engine->RegisterObjectMethod(className, "UIElement@+ GetChild(const String&in, bool = false) const", AS_METHODPR(T, GetChild, (const String&, bool) const, UIElement*), AS_CALL_THISCALL);
Expand Down Expand Up @@ -16461,9 +16461,9 @@ template <class T> void RegisterMembers_UIElement(asIScriptEngine* engine, const
engine->RegisterObjectMethod(className, "MouseButtonFlags GetDragButtonCombo() const", AS_METHODPR(T, GetDragButtonCombo, () const, MouseButtonFlags), AS_CALL_THISCALL);
engine->RegisterObjectMethod(className, "MouseButtonFlags get_dragButtonCombo() const", AS_METHODPR(T, GetDragButtonCombo, () const, MouseButtonFlags), AS_CALL_THISCALL);

// unsigned UIElement::GetDragButtonCount() const
engine->RegisterObjectMethod(className, "uint GetDragButtonCount() const", AS_METHODPR(T, GetDragButtonCount, () const, unsigned), AS_CALL_THISCALL);
engine->RegisterObjectMethod(className, "uint get_dragButtonCount() const", AS_METHODPR(T, GetDragButtonCount, () const, unsigned), AS_CALL_THISCALL);
// i32 UIElement::GetDragButtonCount() const
engine->RegisterObjectMethod(className, "int GetDragButtonCount() const", AS_METHODPR(T, GetDragButtonCount, () const, i32), AS_CALL_THISCALL);
engine->RegisterObjectMethod(className, "int get_dragButtonCount() const", AS_METHODPR(T, GetDragButtonCount, () const, i32), AS_CALL_THISCALL);

// DragAndDropModeFlags UIElement::GetDragDropMode() const
engine->RegisterObjectMethod(className, "DragAndDropModeFlags GetDragDropMode() const", AS_METHODPR(T, GetDragDropMode, () const, DragAndDropModeFlags), AS_CALL_THISCALL);
Expand Down Expand Up @@ -16566,8 +16566,8 @@ template <class T> void RegisterMembers_UIElement(asIScriptEngine* engine, const
engine->RegisterObjectMethod(className, "const String& GetName() const", AS_METHODPR(T, GetName, () const, const String&), AS_CALL_THISCALL);
engine->RegisterObjectMethod(className, "const String& get_name() const", AS_METHODPR(T, GetName, () const, const String&), AS_CALL_THISCALL);

// unsigned UIElement::GetNumChildren(bool recursive = false) const
engine->RegisterObjectMethod(className, "uint GetNumChildren(bool = false) const", AS_METHODPR(T, GetNumChildren, (bool) const, unsigned), AS_CALL_THISCALL);
// i32 UIElement::GetNumChildren(bool recursive = false) const
engine->RegisterObjectMethod(className, "int GetNumChildren(bool = false) const", AS_METHODPR(T, GetNumChildren, (bool) const, i32), AS_CALL_THISCALL);

// float UIElement::GetOpacity() const
engine->RegisterObjectMethod(className, "float GetOpacity() const", AS_METHODPR(T, GetOpacity, () const, float), AS_CALL_THISCALL);
Expand Down Expand Up @@ -16638,8 +16638,8 @@ template <class T> void RegisterMembers_UIElement(asIScriptEngine* engine, const
// bool UIElement::HasTag(const String& tag) const
engine->RegisterObjectMethod(className, "bool HasTag(const String&in) const", AS_METHODPR(T, HasTag, (const String&) const, bool), AS_CALL_THISCALL);

// void UIElement::InsertChild(unsigned index, UIElement* element)
engine->RegisterObjectMethod(className, "void InsertChild(uint, UIElement@+)", AS_METHODPR(T, InsertChild, (unsigned, UIElement*), void), AS_CALL_THISCALL);
// void UIElement::InsertChild(i32 index, UIElement* element)
engine->RegisterObjectMethod(className, "void InsertChild(int, UIElement@+)", AS_METHODPR(T, InsertChild, (i32, UIElement*), void), AS_CALL_THISCALL);

// bool UIElement::IsChildOf(UIElement* element) const
engine->RegisterObjectMethod(className, "bool IsChildOf(UIElement@+) const", AS_METHODPR(T, IsChildOf, (UIElement*) const, bool), AS_CALL_THISCALL);
Expand Down Expand Up @@ -16769,11 +16769,11 @@ template <class T> void RegisterMembers_UIElement(asIScriptEngine* engine, const
// void UIElement::RemoveAllTags()
engine->RegisterObjectMethod(className, "void RemoveAllTags()", AS_METHODPR(T, RemoveAllTags, (), void), AS_CALL_THISCALL);

// void UIElement::RemoveChild(UIElement* element, unsigned index = 0)
engine->RegisterObjectMethod(className, "void RemoveChild(UIElement@+, uint = 0)", AS_METHODPR(T, RemoveChild, (UIElement*, unsigned), void), AS_CALL_THISCALL);
// void UIElement::RemoveChild(UIElement* element, i32 index = 0)
engine->RegisterObjectMethod(className, "void RemoveChild(UIElement@+, int = 0)", AS_METHODPR(T, RemoveChild, (UIElement*, i32), void), AS_CALL_THISCALL);

// void UIElement::RemoveChildAtIndex(unsigned index)
engine->RegisterObjectMethod(className, "void RemoveChildAtIndex(uint)", AS_METHODPR(T, RemoveChildAtIndex, (unsigned), void), AS_CALL_THISCALL);
// void UIElement::RemoveChildAtIndex(i32 index)
engine->RegisterObjectMethod(className, "void RemoveChildAtIndex(int)", AS_METHODPR(T, RemoveChildAtIndex, (i32), void), AS_CALL_THISCALL);

// bool UIElement::RemoveTag(const String& tag)
engine->RegisterObjectMethod(className, "bool RemoveTag(const String&in)", AS_METHODPR(T, RemoveTag, (const String&), bool), AS_CALL_THISCALL);
Expand Down Expand Up @@ -16969,8 +16969,8 @@ template <class T> void RegisterMembers_UIElement(asIScriptEngine* engine, const
engine->RegisterObjectMethod(className, "void SetOpacity(float)", AS_METHODPR(T, SetOpacity, (float), void), AS_CALL_THISCALL);
engine->RegisterObjectMethod(className, "void set_opacity(float)", AS_METHODPR(T, SetOpacity, (float), void), AS_CALL_THISCALL);

// void UIElement::SetParent(UIElement* parent, unsigned index = M_MAX_UNSIGNED)
engine->RegisterObjectMethod(className, "void SetParent(UIElement@+, uint = M_MAX_UNSIGNED)", AS_METHODPR(T, SetParent, (UIElement*, unsigned), void), AS_CALL_THISCALL);
// void UIElement::SetParent(UIElement* parent, i32 index = ENDPOS)
engine->RegisterObjectMethod(className, "void SetParent(UIElement@+, int = ENDPOS)", AS_METHODPR(T, SetParent, (UIElement*, i32), void), AS_CALL_THISCALL);

// void UIElement::SetPivot(const Vector2& pivot)
engine->RegisterObjectMethod(className, "void SetPivot(const Vector2&in)", AS_METHODPR(T, SetPivot, (const Vector2&), void), AS_CALL_THISCALL);
Expand Down Expand Up @@ -17045,15 +17045,15 @@ template <class T> void RegisterMembers_UIElement(asIScriptEngine* engine, const
// void UIElement::UpdateLayout()
engine->RegisterObjectMethod(className, "void UpdateLayout()", AS_METHODPR(T, UpdateLayout, (), void), AS_CALL_THISCALL);

// template <class T> T* UIElement::CreateChild(const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED)
// template <class T> T* UIElement::CreateChild(const String& name = String::EMPTY, i32 index = ENDPOS)
// Not registered because template
// template <class T> T* UIElement::GetChildDynamicCast(unsigned index) const
// template <class T> T* UIElement::GetChildDynamicCast(i32 index) const
// Not registered because template
// template <class T> T* UIElement::GetChildDynamicCast(const String& name, bool recursive = false) const
// Not registered because template
// template <class T> T* UIElement::GetChildDynamicCast(const StringHash& key, const Variant& value = Variant::EMPTY, bool recursive = false) const
// Not registered because template
// template <class T> T* UIElement::GetChildStaticCast(unsigned index) const
// template <class T> T* UIElement::GetChildStaticCast(i32 index) const
// Not registered because template
// template <class T> T* UIElement::GetChildStaticCast(const String& name, bool recursive = false) const
// Not registered because template
Expand Down
58 changes: 39 additions & 19 deletions Source/Urho3D/UI/UIElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile)
String typeName = childElem.GetAttribute("type");
if (typeName.Empty())
typeName = "UIElement";
unsigned index = childElem.HasAttribute("index") ? childElem.GetUInt("index") : M_MAX_UNSIGNED;
i32 index = childElem.HasAttribute("index") ? childElem.GetInt("index") : ENDPOS;
UIElement* child = nullptr;

if (!internalElem)
{
child = CreateChild(typeName, String::EMPTY, index);
}
else
{
for (unsigned i = nextInternalChild; i < children_.Size(); ++i)
Expand Down Expand Up @@ -252,7 +254,7 @@ UIElement* UIElement::LoadChildXML(const XMLElement& childElem, XMLFile* styleFi
String typeName = childElem.GetAttribute("type");
if (typeName.Empty())
typeName = "UIElement";
unsigned index = childElem.HasAttribute("index") ? childElem.GetUInt("index") : M_MAX_UNSIGNED;
i32 index = childElem.HasAttribute("index") ? childElem.GetUInt("index") : ENDPOS;
UIElement* child = CreateChild(typeName, String::EMPTY, index);

if (child)
Expand Down Expand Up @@ -1249,10 +1251,13 @@ void UIElement::BringToFront()
}
}

UIElement* UIElement::CreateChild(StringHash type, const String& name, unsigned index)
UIElement* UIElement::CreateChild(StringHash type, const String& name, i32 index/* = ENDPOS*/)
{
assert(index == ENDPOS || (index >= 0 && index <= children_.Size()));

// Check that creation succeeds and that the object in fact is a UI element
SharedPtr<UIElement> newElement = DynamicCast<UIElement>(context_->CreateObject(type));

if (!newElement)
{
URHO3D_LOGERROR("Could not create unknown UI element type " + type.ToString());
Expand All @@ -1268,25 +1273,30 @@ UIElement* UIElement::CreateChild(StringHash type, const String& name, unsigned

void UIElement::AddChild(UIElement* element)
{
InsertChild(M_MAX_UNSIGNED, element);
InsertChild(ENDPOS, element);
}

void UIElement::InsertChild(unsigned index, UIElement* element)
void UIElement::InsertChild(i32 index, UIElement* element)
{
assert(index == ENDPOS || (index >= 0 && index <= children_.Size()));

// Check for illegal or redundant parent assignment
if (!element || element == this || element->parent_ == this)
return;

// Check for possible cyclic parent assignment
UIElement* parent = parent_;

while (parent)
{
if (parent == element)
return;

parent = parent->parent_;
}

// Add first, then remove from old parent, to ensure the element does not get deleted
if (index >= children_.Size())
if (index >= children_.Size() || index == ENDPOS)
children_.Push(SharedPtr<UIElement>(element));
else
children_.Insert(children_.Begin() + index, SharedPtr<UIElement>(element));
Expand All @@ -1308,6 +1318,7 @@ void UIElement::InsertChild(unsigned index, UIElement* element)
// Send change event
UIElement* root = GetRoot();
UIElement* sender = GetElementEventSender();

if (sender)
{
using namespace ElementAdded;
Expand All @@ -1321,14 +1332,17 @@ void UIElement::InsertChild(unsigned index, UIElement* element)
}
}

void UIElement::RemoveChild(UIElement* element, unsigned index)
void UIElement::RemoveChild(UIElement* element, i32 index/* = 0*/)
{
for (unsigned i = index; i < children_.Size(); ++i)
assert(index >= 0);

for (i32 i = index; i < children_.Size(); ++i)
{
if (children_[i] == element)
{
// Send change event if not already being destroyed
UIElement* sender = Refs() > 0 ? GetElementEventSender() : nullptr;

if (sender)
{
using namespace ElementRemoved;
Expand All @@ -1349,8 +1363,10 @@ void UIElement::RemoveChild(UIElement* element, unsigned index)
}
}

void UIElement::RemoveChildAtIndex(unsigned index)
void UIElement::RemoveChildAtIndex(i32 index)
{
assert(index >= 0);

if (index >= children_.Size())
return;

Expand Down Expand Up @@ -1405,13 +1421,13 @@ void UIElement::Remove()
parent_->RemoveChild(this);
}

unsigned UIElement::FindChild(UIElement* element) const
i32 UIElement::FindChild(UIElement* element) const
{
Vector<SharedPtr<UIElement>>::ConstIterator i = children_.Find(SharedPtr<UIElement>(element));
return i != children_.End() ? (unsigned)(i - children_.Begin()) : M_MAX_UNSIGNED;
Vector<SharedPtr<UIElement>>::ConstIterator it = children_.Find(SharedPtr<UIElement>(element));
return it != children_.End() ? (i32)(it - children_.Begin()) : NINDEX;
}

void UIElement::SetParent(UIElement* parent, unsigned index)
void UIElement::SetParent(UIElement* parent, i32 index/* = ENDPOS*/)
{
if (parent)
parent->InsertChild(index, this);
Expand Down Expand Up @@ -1595,23 +1611,27 @@ Vector<UIElement*> UIElement::GetChildren(bool recursive) const
return dest;
}

unsigned UIElement::GetNumChildren(bool recursive) const
i32 UIElement::GetNumChildren(bool recursive/* = false*/) const
{
if (!recursive)
{
return children_.Size();
}
else
{
unsigned allChildren = children_.Size();
for (Vector<SharedPtr<UIElement>>::ConstIterator i = children_.Begin(); i != children_.End(); ++i)
allChildren += (*i)->GetNumChildren(true);
i32 allChildren = children_.Size();

for (const SharedPtr<UIElement>& child : children_)
allChildren += child->GetNumChildren(true);

return allChildren;
}
}

UIElement* UIElement::GetChild(unsigned index) const
UIElement* UIElement::GetChild(i32 index) const
{
return index < children_.Size() ? children_[index] : nullptr;
assert(index >= 0 || index == NINDEX);
return (index >= 0 && index < children_.Size()) ? children_[index] : nullptr;
}

UIElement* UIElement::GetChild(const String& name, bool recursive) const
Expand Down
Loading