Browse Source

Make AddChild virtual so we can inflate children in the case of adding to a window

Josh Engebretson 10 years ago
parent
commit
879d8782c8

+ 0 - 6
Source/Atomic/UI/UIWidget.cpp

@@ -109,12 +109,6 @@ void UIWidget::AddChild(UIWidget* child)
         return;
         return;
 
 
     widget_->AddChild(child->widget_);
     widget_->AddChild(child->widget_);
-
-    // this is to get proper padding, for instance when adding to a window
-    // takes title into account.  This *may* cause problems here, if so
-    // may need to make UIWidget AddChild virtual and inflate only on UIWindow::AddChild, etc
-    widget_->OnInflateChild(child->widget_);
-
 }
 }
 
 
 void UIWidget::SetText(const String& text)
 void UIWidget::SetText(const String& text)

+ 1 - 1
Source/Atomic/UI/UIWidget.h

@@ -47,7 +47,7 @@ public:
     // get this or child widget with id
     // get this or child widget with id
     UIWidget* GetWidget(const String& id);
     UIWidget* GetWidget(const String& id);
 
 
-    void AddChild(UIWidget* child);
+    virtual void AddChild(UIWidget* child);
 
 
     tb::TBWidget* GetInternalWidget() { return widget_; }
     tb::TBWidget* GetInternalWidget() { return widget_; }
 
 

+ 15 - 0
Source/Atomic/UI/UIWindow.cpp

@@ -41,6 +41,21 @@ void UIWindow::ResizeToFitContent()
 
 
 }
 }
 
 
+void UIWindow::AddChild(UIWidget *child)
+{
+    if (!widget_ || !child->GetInternalWidget())
+        return;
+
+    UIWidget::AddChild(child);
+
+    // this is to get proper padding, this may cause problems
+    // as this is called from the widget_reader, and not as part of
+    // AddChild.  This may also need to be called from other widgets
+    // that have padding, etc
+    widget_->OnInflateChild(child->GetInternalWidget());
+
+}
+
 UIWindow::~UIWindow()
 UIWindow::~UIWindow()
 {
 {
 }
 }

+ 2 - 0
Source/Atomic/UI/UIWindow.h

@@ -20,6 +20,8 @@ public:
 
 
     void ResizeToFitContent();
     void ResizeToFitContent();
 
 
+    void AddChild(UIWidget *child);
+
 protected:
 protected:
 
 
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);