Forráskód Böngészése

Fixed UI layout bugs.

Lasse Öörni 15 éve
szülő
commit
d33562e87a

+ 1 - 1
Bin/Data/UI/DefaultStyle.xml

@@ -318,8 +318,8 @@
         <font name="Cour.ttf" size="12" />
     </element>
     <element type="ConsoleBackground">
-        <layout spacing="0" border="4 4 4 4" />
         <color topleft="0 0.25 0 0.75" topright="0 0.25 0 0.75" bottomleft="0.25 0.75 0.25 0.75" bottomright="0.25 0.75 0.25 0.75" />
+        <layout spacing="0" border="4 4 4 4" />
     </element>
     <element type="ConsoleText">
         <font name="Cour.ttf" size="12" />

+ 10 - 5
Engine/Engine/Console.cpp

@@ -56,7 +56,6 @@ Console::Console(Engine* engine) :
     if (uiRoot)
     {
         mBackground = new BorderImage();
-        mBackground->setFixedWidth(uiRoot->getWidth());
         mBackground->setBringToBack(false);
         mBackground->setClipChildren(true);
         mBackground->setEnabled(true);
@@ -64,6 +63,11 @@ Console::Console(Engine* engine) :
         mBackground->setPriority(200); // Show on top of the debug HUD
         mBackground->setLayout(LM_VERTICAL);
         
+        mRowContainer = new UIElement();
+        mRowContainer->setClipChildren(true);
+        mRowContainer->setLayout(LM_VERTICAL);
+        mBackground->addChild(mRowContainer);
+        
         mLineEdit = new LineEdit();
         mLineEdit->setFocusMode(FM_FOCUSABLE); // Do not allow defocus with ESC
         mBackground->addChild(mLineEdit);
@@ -134,7 +138,7 @@ void Console::setNumRows(unsigned rows)
     if ((!mBackground) || (!rows))
         return;
     
-    mBackground->removeAllChildren();
+    mRowContainer->removeAllChildren();
     
     mRows.resize(rows);
     for (unsigned i = 0; i < mRows.size(); ++i)
@@ -146,9 +150,8 @@ void Console::setNumRows(unsigned rows)
             if (textElem)
                 mRows[i]->setStyle(textElem, mEngine->getResourceCache());
         }
-        mBackground->addChild(mRows[i]);
+        mRowContainer->addChild(mRows[i]);
     }
-    mBackground->addChild(mLineEdit);
     
     updateElements();
 }
@@ -165,8 +168,10 @@ void Console::setNumHistoryRows(unsigned rows)
 void Console::updateElements()
 {
     int width = mEngine->getRenderer()->getWidth();
-    mLineEdit->setFixedHeight(mLineEdit->getTextElement()->getRowHeight());
+    const IntRect& border = mBackground->getLayoutBorder();
     mBackground->setFixedWidth(width);
+    mRowContainer->setFixedWidth(width - border.mLeft - border.mRight);
+    mLineEdit->setFixedHeight(mLineEdit->getTextElement()->getRowHeight());
 }
 
 bool Console::isVisible() const

+ 3 - 0
Engine/Engine/Console.h

@@ -32,6 +32,7 @@ class Engine;
 class Font;
 class LineEdit;
 class Text;
+class UIElement;
 class XMLFile;
 
 //! A console window with log history and AngelScript prompt
@@ -89,6 +90,8 @@ private:
     SharedPtr<XMLFile> mStyle;
     //! Background
     SharedPtr<BorderImage> mBackground;
+    //! Container for text rows
+    SharedPtr<UIElement> mRowContainer;
     //! Text rows
     std::vector<SharedPtr<Text> > mRows;
     //! Line edit

+ 14 - 9
Engine/UI/UIElement.cpp

@@ -362,13 +362,10 @@ void UIElement::setHeight(int height)
     setSize(IntVector2(mSize.mX, height));
 }
 
-
 void UIElement::setMinSize(const IntVector2& minSize)
 {
     mMinSize.mX = max(minSize.mX, 0);
     mMinSize.mY = max(minSize.mY, 0);
-    mMaxSize.mX = max(minSize.mX, mMaxSize.mX);
-    mMaxSize.mY = max(minSize.mY, mMaxSize.mY);
     setSize(mSize);
 }
 
@@ -389,8 +386,8 @@ void UIElement::setMinHeight(int height)
 
 void UIElement::setMaxSize(const IntVector2& maxSize)
 {
-    mMaxSize.mX = max(mMinSize.mX, maxSize.mX);
-    mMaxSize.mY = max(mMinSize.mY, maxSize.mY);
+    mMaxSize.mX = max(maxSize.mX, 0);
+    mMaxSize.mY = max(maxSize.mY, 0);
     setSize(mSize);
 }
 
@@ -634,10 +631,15 @@ void UIElement::updateLayout()
         
         int width = calculateLayoutParentSize(sizes, mLayoutBorder.mLeft, mLayoutBorder.mRight, mLayoutSpacing);
         int height = max(getHeight(), minChildHeight + mLayoutBorder.mTop + mLayoutBorder.mBottom);
-        int minWidth = calculateLayoutParentSize(minSizes, mLayoutBorder.mLeft, mLayoutBorder.mRight, mLayoutSpacing);
-        int minHeight = minChildHeight + mLayoutBorder.mTop + mLayoutBorder.mBottom;
+        // Make sure the minimum size we are going to set is not higher than current maximum size
+        int minWidth = min(calculateLayoutParentSize(minSizes, mLayoutBorder.mLeft, mLayoutBorder.mRight, mLayoutSpacing), mMaxSize.mX);
+        int minHeight = min(minChildHeight + mLayoutBorder.mTop + mLayoutBorder.mBottom, mMaxSize.mY);
+        
         setMinSize(minWidth, minHeight);
         setSize(width, height);
+        // Validate the size before resizing child elements, in case of min/max limits
+        width = mSize.mX;
+        height = mSize.mY;
         
         unsigned j = 0;
         for (unsigned i = 0; i < mChildren.size(); ++i)
@@ -672,10 +674,13 @@ void UIElement::updateLayout()
         
         int height = calculateLayoutParentSize(sizes, mLayoutBorder.mTop, mLayoutBorder.mBottom, mLayoutSpacing);
         int width = max(getWidth(), minChildWidth + mLayoutBorder.mLeft + mLayoutBorder.mRight);
-        int minHeight = calculateLayoutParentSize(minSizes, mLayoutBorder.mTop, mLayoutBorder.mBottom, mLayoutSpacing);
-        int minWidth = minChildWidth + mLayoutBorder.mLeft + mLayoutBorder.mRight;
+        int minHeight = min(calculateLayoutParentSize(minSizes, mLayoutBorder.mTop, mLayoutBorder.mBottom, mLayoutSpacing), mMaxSize.mY);
+        int minWidth = min(minChildWidth + mLayoutBorder.mLeft + mLayoutBorder.mRight, mMaxSize.mX);
+        
         setMinSize(minWidth, minHeight);
         setSize(width, height);
+        width = mSize.mX;
+        height = mSize.mY;
         
         unsigned j = 0;
         for (unsigned i = 0; i < mChildren.size(); ++i)