Browse Source

Adding UIWidget.Center

Josh Engebretson 10 years ago
parent
commit
332fa000cf
3 changed files with 16 additions and 0 deletions
  1. 1 0
      Source/Atomic/UI/UIButton.cpp
  2. 13 0
      Source/Atomic/UI/UIWidget.cpp
  3. 2 0
      Source/Atomic/UI/UIWidget.h

+ 1 - 0
Source/Atomic/UI/UIButton.cpp

@@ -31,6 +31,7 @@ bool UIButton::OnEvent(const tb::TBWidgetEvent &ev)
         VariantMap eventData;
         ConvertEvent(this, ev, eventData);
         SendEvent(E_WIDGETEVENT, eventData);
+        // this is catching the window close button
         return true;
     }
 

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

@@ -111,4 +111,17 @@ void UIWidget::SetSize(int width, int height)
     widget_->SetSize(width, height);
 }
 
+void UIWidget::Center()
+{
+    if (!widget_)
+        return;
+
+    UI* ui = GetSubsystem<UI>();
+    TBRect rect = widget_->GetRect();
+    TBWidget* root = ui->GetRootWidget();
+    TBRect bounds(0, 0, root->GetRect().w, root->GetRect().h);
+    widget_->SetRect(rect.CenterIn(bounds).MoveIn(bounds).Clip(bounds));
+
+}
+
 }

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

@@ -30,6 +30,8 @@ public:
     void SetSize(int width, int height);
     bool SetText(const String& text);
 
+    void Center();
+
     UIWidget* GetWidgetByID(const String& id);
 
     void AddChild(UIWidget* child);