Browse Source

UIElement.cpp: fix warnings, style

1vanK 3 years ago
parent
commit
b2d3e8e867
1 changed files with 60 additions and 57 deletions
  1. 60 57
      Source/Urho3D/UI/UIElement.cpp

+ 60 - 57
Source/Urho3D/UI/UIElement.cpp

@@ -142,7 +142,7 @@ void UIElement::ApplyAttributes()
     colorGradient_ = false;
     colorGradient_ = false;
     derivedColorDirty_ = true;
     derivedColorDirty_ = true;
 
 
-    for (unsigned i = 1; i < MAX_UIELEMENT_CORNERS; ++i)
+    for (i32 i = 1; i < MAX_UIELEMENT_CORNERS; ++i)
     {
     {
         if (colors_[i] != colors_[0])
         if (colors_[i] != colors_[0])
             colorGradient_ = true;
             colorGradient_ = true;
@@ -190,7 +190,7 @@ bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile)
     if (!Animatable::LoadXML(source))
     if (!Animatable::LoadXML(source))
         return false;
         return false;
 
 
-    unsigned nextInternalChild = 0;
+    i32 nextInternalChild = 0;
 
 
     // Load child elements. Internal elements are not to be created as they already exist
     // Load child elements. Internal elements are not to be created as they already exist
     XMLElement childElem = source.GetChild("element");
     XMLElement childElem = source.GetChild("element");
@@ -209,7 +209,7 @@ bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile)
         }
         }
         else
         else
         {
         {
-            for (unsigned i = nextInternalChild; i < children_.Size(); ++i)
+            for (i32 i = nextInternalChild; i < children_.Size(); ++i)
             {
             {
                 if (children_[i]->IsInternal() && children_[i]->GetTypeName() == typeName)
                 if (children_[i]->IsInternal() && children_[i]->GetTypeName() == typeName)
                 {
                 {
@@ -304,9 +304,8 @@ bool UIElement::SaveXML(XMLElement& dest) const
         return false;
         return false;
 
 
     // Write child elements
     // Write child elements
-    for (unsigned i = 0; i < children_.Size(); ++i)
+    for (const SharedPtr<UIElement>& element : children_)
     {
     {
-        UIElement* element = children_[i];
         if (element->IsTemporary())
         if (element->IsTemporary())
             continue;
             continue;
 
 
@@ -804,7 +803,7 @@ void UIElement::SetClipBorder(const IntRect& rect)
 
 
 void UIElement::SetColor(const Color& color)
 void UIElement::SetColor(const Color& color)
 {
 {
-    for (auto& cornerColor : colors_)
+    for (Color& cornerColor : colors_)
         cornerColor = color;
         cornerColor = color;
     colorGradient_ = false;
     colorGradient_ = false;
     derivedColorDirty_ = true;
     derivedColorDirty_ = true;
@@ -816,7 +815,7 @@ void UIElement::SetColor(Corner corner, const Color& color)
     colorGradient_ = false;
     colorGradient_ = false;
     derivedColorDirty_ = true;
     derivedColorDirty_ = true;
 
 
-    for (unsigned i = 0; i < MAX_UIELEMENT_CORNERS; ++i)
+    for (i32 i = 0; i < MAX_UIELEMENT_CORNERS; ++i)
     {
     {
         if (i != corner && colors_[i] != colors_[corner])
         if (i != corner && colors_[i] != colors_[corner])
             colorGradient_ = true;
             colorGradient_ = true;
@@ -915,7 +914,7 @@ void UIElement::SetFocus(bool enable)
     if (focusMode_ < FM_FOCUSABLE || !IsVisibleEffective())
     if (focusMode_ < FM_FOCUSABLE || !IsVisibleEffective())
         enable = false;
         enable = false;
 
 
-    auto* ui = GetSubsystem<UI>();
+    UI* ui = GetSubsystem<UI>();
     // Can be null at exit time; no-op in that case
     // Can be null at exit time; no-op in that case
     if (!ui)
     if (!ui)
         return;
         return;
@@ -939,7 +938,7 @@ void UIElement::SetSelected(bool enable)
 
 
 void UIElement::SetVisible(bool enable)
 void UIElement::SetVisible(bool enable)
 {
 {
-    auto* ui = GetSubsystem<UI>();
+    UI* ui = GetSubsystem<UI>();
     // Can be null at exit time; no-op in that case
     // Can be null at exit time; no-op in that case
     if (!ui)
     if (!ui)
         return;
         return;
@@ -1095,17 +1094,18 @@ void UIElement::UpdateLayout()
     {
     {
         int minChildHeight = 0;
         int minChildHeight = 0;
 
 
-        for (unsigned i = 0; i < children_.Size(); ++i)
+        for (const SharedPtr<UIElement>& child : children_)
         {
         {
-            if (!children_[i]->IsVisible())
+            if (!child->IsVisible())
                 continue;
                 continue;
+
             positions.Push(baseIndentWidth);
             positions.Push(baseIndentWidth);
-            auto indent = (unsigned)children_[i]->GetIndentWidth();
-            sizes.Push(children_[i]->GetWidth() + indent);
-            minSizes.Push(children_[i]->GetEffectiveMinSize().x_ + indent);
-            maxSizes.Push(children_[i]->GetMaxWidth() + indent);
-            flexScales.Push(children_[i]->GetLayoutFlexScale().x_);
-            minChildHeight = Max(minChildHeight, children_[i]->GetEffectiveMinSize().y_);
+            i32 indent = child->GetIndentWidth();
+            sizes.Push(child->GetWidth() + indent);
+            minSizes.Push(child->GetEffectiveMinSize().x_ + indent);
+            maxSizes.Push(child->GetMaxWidth() + indent);
+            flexScales.Push(child->GetLayoutFlexScale().x_);
+            minChildHeight = Max(minChildHeight, child->GetEffectiveMinSize().y_);
         }
         }
 
 
         CalculateLayout(positions, sizes, minSizes, maxSizes, flexScales, GetWidth(), layoutBorder_.left_, layoutBorder_.right_,
         CalculateLayout(positions, sizes, minSizes, maxSizes, flexScales, GetWidth(), layoutBorder_.left_, layoutBorder_.right_,
@@ -1121,13 +1121,14 @@ void UIElement::UpdateLayout()
         width = size_.x_;
         width = size_.x_;
         height = size_.y_;
         height = size_.y_;
 
 
-        unsigned j = 0;
-        for (unsigned i = 0; i < children_.Size(); ++i)
+        i32 j = 0;
+        for (const SharedPtr<UIElement>& child : children_)
         {
         {
-            if (!children_[i]->IsVisible())
+            if (!child->IsVisible())
                 continue;
                 continue;
-            children_[i]->SetPosition(positions[j], GetLayoutChildPosition(children_[i]).y_);
-            children_[i]->SetSize(sizes[j], height - layoutBorder_.top_ - layoutBorder_.bottom_);
+
+            child->SetPosition(positions[j], GetLayoutChildPosition(child).y_);
+            child->SetSize(sizes[j], height - layoutBorder_.top_ - layoutBorder_.bottom_);
             ++j;
             ++j;
         }
         }
     }
     }
@@ -1135,16 +1136,17 @@ void UIElement::UpdateLayout()
     {
     {
         int minChildWidth = 0;
         int minChildWidth = 0;
 
 
-        for (unsigned i = 0; i < children_.Size(); ++i)
+        for (const SharedPtr<UIElement>& child : children_)
         {
         {
-            if (!children_[i]->IsVisible())
+            if (!child->IsVisible())
                 continue;
                 continue;
+
             positions.Push(0);
             positions.Push(0);
-            sizes.Push(children_[i]->GetHeight());
-            minSizes.Push(children_[i]->GetEffectiveMinSize().y_);
-            maxSizes.Push(children_[i]->GetMaxHeight());
-            flexScales.Push(children_[i]->GetLayoutFlexScale().y_);
-            minChildWidth = Max(minChildWidth, children_[i]->GetEffectiveMinSize().x_ + children_[i]->GetIndentWidth());
+            sizes.Push(child->GetHeight());
+            minSizes.Push(child->GetEffectiveMinSize().y_);
+            maxSizes.Push(child->GetMaxHeight());
+            flexScales.Push(child->GetLayoutFlexScale().y_);
+            minChildWidth = Max(minChildWidth, child->GetEffectiveMinSize().x_ + child->GetIndentWidth());
         }
         }
 
 
         CalculateLayout(positions, sizes, minSizes, maxSizes, flexScales, GetHeight(), layoutBorder_.top_, layoutBorder_.bottom_,
         CalculateLayout(positions, sizes, minSizes, maxSizes, flexScales, GetHeight(), layoutBorder_.top_, layoutBorder_.bottom_,
@@ -1159,22 +1161,23 @@ void UIElement::UpdateLayout()
         width = size_.x_;
         width = size_.x_;
         height = size_.y_;
         height = size_.y_;
 
 
-        unsigned j = 0;
-        for (unsigned i = 0; i < children_.Size(); ++i)
+        i32 j = 0;
+        for (const SharedPtr<UIElement>& child : children_)
         {
         {
-            if (!children_[i]->IsVisible())
+            if (!child->IsVisible())
                 continue;
                 continue;
-            children_[i]->SetPosition(GetLayoutChildPosition(children_[i]).x_ + baseIndentWidth, positions[j]);
-            children_[i]->SetSize(width - layoutBorder_.left_ - layoutBorder_.right_, sizes[j]);
+
+            child->SetPosition(GetLayoutChildPosition(child).x_ + baseIndentWidth, positions[j]);
+            child->SetSize(width - layoutBorder_.left_ - layoutBorder_.right_, sizes[j]);
             ++j;
             ++j;
         }
         }
     }
     }
     else
     else
     {
     {
-        for (unsigned i = 0; i < children_.Size(); ++i)
+        for (const SharedPtr<UIElement>& child : children_)
         {
         {
-            if (children_[i]->GetEnableAnchor())
-                children_[i]->UpdateAnchoring();
+            if (child->GetEnableAnchor())
+                child->UpdateAnchoring();
         }
         }
     }
     }
 
 
@@ -1475,8 +1478,8 @@ void UIElement::AddTags(const String& tags, char separator)
 
 
 void UIElement::AddTags(const StringVector& tags)
 void UIElement::AddTags(const StringVector& tags)
 {
 {
-    for (unsigned i = 0; i < tags.Size(); ++i)
-        AddTag(tags[i]);
+    for (const String& tag : tags)
+        AddTag(tag);
 }
 }
 
 
 bool UIElement::RemoveTag(const String& tag)
 bool UIElement::RemoveTag(const String& tag)
@@ -1537,7 +1540,7 @@ float UIElement::GetDerivedOpacity() const
 
 
 bool UIElement::HasFocus() const
 bool UIElement::HasFocus() const
 {
 {
-    auto* ui = GetSubsystem<UI>();
+    UI* ui = GetSubsystem<UI>();
     return ui ? ui->GetFocusElement() == this : false;
     return ui ? ui->GetFocusElement() == this : false;
 }
 }
 
 
@@ -1833,10 +1836,10 @@ void UIElement::GetBatchesWithOffset(IntVector2& offset, Vector<UIBatch>& batche
     IntRect currentScissor)
     IntRect currentScissor)
 {
 {
     Vector2 floatOffset((float)offset.x_, (float)offset.y_);
     Vector2 floatOffset((float)offset.x_, (float)offset.y_);
-    unsigned initialSize = vertexData.Size();
+    i32 initialSize = vertexData.Size();
 
 
     GetBatches(batches, vertexData, currentScissor);
     GetBatches(batches, vertexData, currentScissor);
-    for (unsigned i = initialSize; i < vertexData.Size(); i += 6)
+    for (i32 i = initialSize; i < vertexData.Size(); i += 6)
     {
     {
         vertexData[i] += floatOffset.x_;
         vertexData[i] += floatOffset.x_;
         vertexData[i + 1] += floatOffset.y_;
         vertexData[i + 1] += floatOffset.y_;
@@ -1852,7 +1855,7 @@ void UIElement::GetBatchesWithOffset(IntVector2& offset, Vector<UIBatch>& batche
 
 
 UIElement* UIElement::GetElementEventSender() const
 UIElement* UIElement::GetElementEventSender() const
 {
 {
-    auto* element = const_cast<UIElement*>(this);
+    UIElement* element = const_cast<UIElement*>(this);
     if (elementEventSender_)
     if (elementEventSender_)
         return element;
         return element;
 
 
@@ -1900,7 +1903,7 @@ Animatable* UIElement::FindAttributeAnimationTarget(const String& name, String&
     {
     {
         // Name must in following format: "#0/#1/attribute"
         // Name must in following format: "#0/#1/attribute"
         UIElement* element = this;
         UIElement* element = this;
-        for (unsigned i = 0; i < names.Size() - 1; ++i)
+        for (i32 i = 0; i < names.Size() - 1; ++i)
         {
         {
             if (names[i].Front() != '#')
             if (names[i].Front() != '#')
             {
             {
@@ -1912,7 +1915,7 @@ Animatable* UIElement::FindAttributeAnimationTarget(const String& name, String&
             char s = name.Front();
             char s = name.Front();
             if (s >= '0' && s <= '9')
             if (s >= '0' && s <= '9')
             {
             {
-                unsigned index = ToUInt(name);
+                i32 index = ToInt(name);
                 element = element->GetChild(index);
                 element = element->GetChild(index);
             }
             }
             else
             else
@@ -2080,12 +2083,12 @@ int UIElement::CalculateLayoutParentSize(const Vector<int>& sizes, int begin, in
     if (sizes.Empty())
     if (sizes.Empty())
         return width;
         return width;
 
 
-    for (unsigned i = 0; i < sizes.Size(); ++i)
+    for (i32 size : sizes)
     {
     {
         // If calculating maximum size, and the default is specified, do not overflow it
         // If calculating maximum size, and the default is specified, do not overflow it
-        if (sizes[i] == M_MAX_INT)
+        if (size == M_MAX_INT)
             return M_MAX_INT;
             return M_MAX_INT;
-        width += sizes[i] + spacing;
+        width += size + spacing;
     }
     }
     // The last spacing is not needed
     // The last spacing is not needed
     return width - spacing;
     return width - spacing;
@@ -2094,7 +2097,7 @@ int UIElement::CalculateLayoutParentSize(const Vector<int>& sizes, int begin, in
 void UIElement::CalculateLayout(Vector<int>& positions, Vector<int>& sizes, const Vector<int>& minSizes,
 void UIElement::CalculateLayout(Vector<int>& positions, Vector<int>& sizes, const Vector<int>& minSizes,
     const Vector<int>& maxSizes, const Vector<float>& flexScales, int targetSize, int begin, int end, int spacing)
     const Vector<int>& maxSizes, const Vector<float>& flexScales, int targetSize, int begin, int end, int spacing)
 {
 {
-    unsigned numChildren = sizes.Size();
+    i32 numChildren = sizes.Size();
     if (!numChildren)
     if (!numChildren)
         return;
         return;
     int targetTotalSize = targetSize - begin - end - (numChildren - 1) * spacing;
     int targetTotalSize = targetSize - begin - end - (numChildren - 1) * spacing;
@@ -2106,9 +2109,9 @@ void UIElement::CalculateLayout(Vector<int>& positions, Vector<int>& sizes, cons
     float acc = 0.0f;
     float acc = 0.0f;
 
 
     // Initial pass
     // Initial pass
-    for (unsigned i = 0; i < numChildren; ++i)
+    for (i32 i = 0; i < numChildren; ++i)
     {
     {
-        auto targetSize = (int)(targetChildSize * flexScales[i]);
+        i32 targetSize = (i32)(targetChildSize * flexScales[i]);
         if (remainder)
         if (remainder)
         {
         {
             acc += add;
             acc += add;
@@ -2126,7 +2129,7 @@ void UIElement::CalculateLayout(Vector<int>& positions, Vector<int>& sizes, cons
     for (;;)
     for (;;)
     {
     {
         int actualTotalSize = 0;
         int actualTotalSize = 0;
-        for (unsigned i = 0; i < numChildren; ++i)
+        for (i32 i = 0; i < numChildren; ++i)
             actualTotalSize += sizes[i];
             actualTotalSize += sizes[i];
         int error = targetTotalSize - actualTotalSize;
         int error = targetTotalSize - actualTotalSize;
         // Break if no error
         // Break if no error
@@ -2134,8 +2137,8 @@ void UIElement::CalculateLayout(Vector<int>& positions, Vector<int>& sizes, cons
             break;
             break;
 
 
         // Check which of the children can be resized to correct the error. If none, must break
         // Check which of the children can be resized to correct the error. If none, must break
-        Vector<unsigned> resizable;
-        for (unsigned i = 0; i < numChildren; ++i)
+        Vector<i32> resizable;
+        for (i32 i = 0; i < numChildren; ++i)
         {
         {
             if (error < 0 && sizes[i] > minSizes[i])
             if (error < 0 && sizes[i] > minSizes[i])
                 resizable.Push(i);
                 resizable.Push(i);
@@ -2153,7 +2156,7 @@ void UIElement::CalculateLayout(Vector<int>& positions, Vector<int>& sizes, cons
 
 
         for (int i = 0; i < numResizable; ++i)
         for (int i = 0; i < numResizable; ++i)
         {
         {
-            unsigned index = resizable[i];
+            i32 index = resizable[i];
             int targetSize = sizes[index] + errorPerChild;
             int targetSize = sizes[index] + errorPerChild;
             if (remainder)
             if (remainder)
             {
             {
@@ -2173,7 +2176,7 @@ void UIElement::CalculateLayout(Vector<int>& positions, Vector<int>& sizes, cons
     // Calculate final positions and store the maximum child element size for optimizations
     // Calculate final positions and store the maximum child element size for optimizations
     layoutElementMaxSize_ = 0;
     layoutElementMaxSize_ = 0;
     int position = begin;
     int position = begin;
-    for (unsigned i = 0; i < numChildren; ++i)
+    for (i32 i = 0; i < numChildren; ++i)
     {
     {
         positions[i] = position;
         positions[i] = position;
         position += sizes[i] + spacing;
         position += sizes[i] + spacing;
@@ -2244,7 +2247,7 @@ void UIElement::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
 
 
 void UIElement::SetRenderTexture(Texture2D* texture)
 void UIElement::SetRenderTexture(Texture2D* texture)
 {
 {
-    if (auto* ui = GetSubsystem<UI>())
+    if (UI* ui = GetSubsystem<UI>())
         ui->SetElementRenderTexture(this, texture);
         ui->SetElementRenderTexture(this, texture);
 }
 }