Browse Source

align controls only if alignment is set

Andrew Karpushin 12 years ago
parent
commit
4eaed12cf5
2 changed files with 30 additions and 21 deletions
  1. 4 1
      gameplay/src/Control.cpp
  2. 26 20
      gameplay/src/Layout.cpp

+ 4 - 1
gameplay/src/Control.cpp

@@ -37,7 +37,10 @@ void Control::initialize(Theme::Style* style, Properties* properties)
     _style = style;
     _style = style;
 
 
     // Properties not defined by the style.
     // Properties not defined by the style.
-    _alignment = getAlignment(properties->getString("alignment"));
+    const char * alignmentString = properties->getString("alignment");
+
+    _isAlignmentSet = alignmentString != NULL;
+    _alignment = getAlignment(alignmentString);
     _autoWidth = properties->getBool("autoWidth");
     _autoWidth = properties->getBool("autoWidth");
     _autoHeight = properties->getBool("autoHeight");
     _autoHeight = properties->getBool("autoHeight");
 
 

+ 26 - 20
gameplay/src/Layout.cpp

@@ -47,31 +47,37 @@ void Layout::align(Control* control, const Container* container)
         }
         }
 
 
         // Vertical alignment
         // Vertical alignment
-        if ((control->_alignment & Control::ALIGN_BOTTOM) == Control::ALIGN_BOTTOM)
+        if(control->_isAlignmentSet || control->_autoHeight)
         {
         {
-            controlBounds.y = clipHeight - controlBounds.height - controlMargin.bottom;
-        }
-        else if ((control->_alignment & Control::ALIGN_VCENTER) == Control::ALIGN_VCENTER)
-        {
-            controlBounds.y = clipHeight * 0.5f - controlBounds.height * 0.5f;
-        }
-        else if ((control->_alignment & Control::ALIGN_TOP) == Control::ALIGN_TOP)
-        {
-            controlBounds.y = controlMargin.top;
+            if ((control->_alignment & Control::ALIGN_BOTTOM) == Control::ALIGN_BOTTOM)
+            {
+                controlBounds.y = clipHeight - controlBounds.height - controlMargin.bottom;
+            }
+            else if ((control->_alignment & Control::ALIGN_VCENTER) == Control::ALIGN_VCENTER)
+            {
+                controlBounds.y = clipHeight * 0.5f - controlBounds.height * 0.5f;
+            }
+            else if ((control->_alignment & Control::ALIGN_TOP) == Control::ALIGN_TOP)
+            {
+                controlBounds.y = controlMargin.top;
+            }
         }
         }
 
 
         // Horizontal alignment
         // Horizontal alignment
-        if ((control->_alignment & Control::ALIGN_RIGHT) == Control::ALIGN_RIGHT)
-        {
-            controlBounds.x = clipWidth - controlBounds.width - controlMargin.right;
-        }
-        else if ((control->_alignment & Control::ALIGN_HCENTER) == Control::ALIGN_HCENTER)
-        {
-            controlBounds.x = clipWidth * 0.5f - controlBounds.width * 0.5f;
-        }
-        else if ((control->_alignment & Control::ALIGN_LEFT) == Control::ALIGN_LEFT)
+        if(control->_isAlignmentSet || control->_autoWidth)
         {
         {
-            controlBounds.x = controlMargin.left;
+            if ((control->_alignment & Control::ALIGN_RIGHT) == Control::ALIGN_RIGHT)
+            {
+                controlBounds.x = clipWidth - controlBounds.width - controlMargin.right;
+            }
+            else if ((control->_alignment & Control::ALIGN_HCENTER) == Control::ALIGN_HCENTER)
+            {
+                controlBounds.x = clipWidth * 0.5f - controlBounds.width * 0.5f;
+            }
+            else if ((control->_alignment & Control::ALIGN_LEFT) == Control::ALIGN_LEFT)
+            {
+                controlBounds.x = controlMargin.left;
+            }
         }
         }
 
 
         control->setBounds(controlBounds);
         control->setBounds(controlBounds);