Browse Source

If a child element set a style name without a style file, apply it when added to parent.

Lasse Öörni 12 năm trước cách đây
mục cha
commit
8516b9335a
1 tập tin đã thay đổi với 12 bổ sung0 xóa
  1. 12 0
      Engine/UI/UIElement.cpp

+ 12 - 0
Engine/UI/UIElement.cpp

@@ -886,6 +886,11 @@ bool UIElement::SetStyle(const String& styleName, XMLFile* file)
         if (!file)
             return false;
     }
+    else
+    {
+        // If a custom style file specified, remember it
+        defaultStyle_ = file;
+    }
 
     styleXPathQuery_.SetVariable("typeName", styleName);
     XMLElement styleElem = file->GetRoot().SelectSinglePrepared(styleXPathQuery_);
@@ -1167,6 +1172,8 @@ void UIElement::InsertChild(unsigned index, UIElement* element)
     else
         children_.Insert(children_.Begin() + index, SharedPtr<UIElement>(element));
 
+    XMLFile* previousStyleFile = element->GetDefaultStyle();
+
     element->Remove();
 
     if (sortChildren_)
@@ -1174,6 +1181,11 @@ void UIElement::InsertChild(unsigned index, UIElement* element)
 
     element->parent_ = this;
     element->MarkDirty();
+
+    // If child element did not already have a style file, but has specified a style name, apply it now
+    if (!previousStyleFile && !element->appliedStyle_.Empty() && GetDefaultStyle())
+        element->SetStyle(element->appliedStyle_);
+
     UpdateLayout();
 
     // Send change event