Explorar el Código

Fixed indentation calculation for vertically layout UI-element parent. Fixed LineEdit indentation handling on internal objects. Added and exposed functions to determine whether UI-element size is fixed.

Wei Tjong Yao hace 12 años
padre
commit
342db6f72b

+ 3 - 3
Bin/Data/UI/EditorSceneWindow.xml

@@ -27,7 +27,7 @@
             <attribute name="Name" value="ExpandButton" />
             <attribute name="Min Size" value="70 17" />
             <attribute name="Max Size" value="70 17" />
-            <attribute name="Layout Mode" value="Vertical" />
+            <attribute name="Layout Mode" value="Horizontal" />
             <attribute name="Layout Border" value="1 1 1 1" />
             <element type="Text">>
                 <attribute name="Text" value="Expand" />
@@ -38,7 +38,7 @@
             <attribute name="Name" value="CollapseButton" />
             <attribute name="Min Size" value="70 17" />
             <attribute name="Max Size" value="70 17" />
-            <attribute name="Layout Mode" value="Vertical" />
+            <attribute name="Layout Mode" value="Horizontal" />
             <attribute name="Layout Border" value="1 1 1 1" />
             <element type="Text">
                 <attribute name="Text" value="Collapse" />
@@ -51,7 +51,7 @@
             <attribute name="Max Size" value="45 15" />
             <attribute name="Indent Spacing" value="30" />
             <attribute name="Indent" value="1" />
-            <attribute name="Layout Mode" value="Vertical" />
+            <attribute name="Layout Mode" value="Horizontal" />
             <attribute name="Layout Border" value="5 1 1 1" />
             <element type="Text">
                 <attribute name="Text" value="All" />

+ 42 - 0
Docs/ScriptAPI.dox

@@ -3219,6 +3219,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -3332,6 +3335,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -3542,6 +3548,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -3666,6 +3675,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -3788,6 +3800,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -3909,6 +3924,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -4034,6 +4052,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -4156,6 +4177,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -4294,6 +4318,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -4429,6 +4456,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -4554,6 +4584,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -4689,6 +4722,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -4828,6 +4864,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder
@@ -4961,6 +5000,9 @@ Properties:<br>
 - IntVector2 maxSize
 - int maxWidth
 - int maxHeight
+- bool fixedSize (readonly)
+- bool fixedWidth (readonly)
+- bool fixedHeight (readonly)
 - HorizontalAlignment horizontalAlignment
 - VerticalAlignment verticalAlignment
 - IntRect clipBorder

+ 3 - 0
Engine/Engine/APITemplates.h

@@ -894,6 +894,9 @@ template <class T> void RegisterUIElement(asIScriptEngine* engine, const char* c
         engine->RegisterObjectMethod(className, "int get_maxWidth() const", asMETHOD(T, GetMaxWidth), asCALL_THISCALL);
         engine->RegisterObjectMethod(className, "void set_maxHeight(int)", asMETHOD(T, SetMaxHeight), asCALL_THISCALL);
         engine->RegisterObjectMethod(className, "int get_maxHeight() const", asMETHOD(T, GetMaxHeight), asCALL_THISCALL);
+        engine->RegisterObjectMethod(className, "bool get_fixedSize() const", asMETHOD(T, IsFixedSize), asCALL_THISCALL);
+        engine->RegisterObjectMethod(className, "bool get_fixedWidth() const", asMETHOD(T, IsFixedWidth), asCALL_THISCALL);
+        engine->RegisterObjectMethod(className, "bool get_fixedHeight() const", asMETHOD(T, IsFixedHeight), asCALL_THISCALL);
     }
     engine->RegisterObjectMethod(className, "void set_horizontalAlignment(HorizontalAlignment)", asMETHOD(T, SetHorizontalAlignment), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "HorizontalAlignment get_horizontalAlignment() const", asMETHOD(T, GetHorizontalAlignment), asCALL_THISCALL);

+ 7 - 3
Engine/UI/LineEdit.cpp

@@ -62,6 +62,7 @@ LineEdit::LineEdit(Context* context) :
 
     SubscribeToEvent(this, E_FOCUSED, HANDLER(LineEdit, HandleFocused));
     SubscribeToEvent(this, E_DEFOCUSED, HANDLER(LineEdit, HandleDefocused));
+    SubscribeToEvent(this, E_LAYOUTUPDATED, HANDLER(LineEdit, HandleFocused));
 }
 
 LineEdit::~LineEdit()
@@ -86,8 +87,11 @@ void LineEdit::ApplyAttributes()
 {
     BorderImage::ApplyAttributes();
 
-    // Set the text's position to match clipping, so that text left edge is not left partially hidden
-    text_->SetPosition(clipBorder_.left_, clipBorder_.top_);
+    // Set the text's position to match clipping and indent width, so that text left edge is not left partially hidden
+    text_->SetPosition(GetIndentWidth() + clipBorder_.left_, clipBorder_.top_);
+
+    // Sync the text line
+    line_ = text_->GetText();
 }
 
 void LineEdit::Update(float timeStep)
@@ -534,7 +538,7 @@ void LineEdit::UpdateCursor()
     if (charPositions.Size())
         x = cursorPosition_ < charPositions.Size() ? charPositions[cursorPosition_].x_ : charPositions.Back().x_;
 
-    text_->SetPosition(clipBorder_.left_, clipBorder_.top_);
+    text_->SetPosition(GetIndentWidth() + clipBorder_.left_, clipBorder_.top_);
     cursor_->SetPosition(text_->GetPosition() + IntVector2(x, 0));
     cursor_->SetSize(cursor_->GetWidth(), text_->GetRowHeight());
 

+ 4 - 2
Engine/UI/UIElement.cpp

@@ -823,6 +823,7 @@ void UIElement::SetIndent(int indent)
     indent_ = indent;
     if (parent_)
         parent_->UpdateLayout();
+    UpdateLayout();
 }
 
 void UIElement::SetIndentSpacing(int indentSpacing)
@@ -830,6 +831,7 @@ void UIElement::SetIndentSpacing(int indentSpacing)
     indentSpacing_ = Max(indentSpacing, 0);
     if (parent_)
         parent_->UpdateLayout();
+    UpdateLayout();
 }
 
 void UIElement::UpdateLayout()
@@ -900,7 +902,7 @@ void UIElement::UpdateLayout()
         {
             if (!children_[i]->IsVisible())
                 continue;
-            positions.Push(baseIndentWidth);
+            positions.Push(0);
             sizes.Push(children_[i]->GetHeight());
             minSizes.Push(children_[i]->GetMinHeight());
             maxSizes.Push(children_[i]->GetMaxHeight());
@@ -928,7 +930,7 @@ void UIElement::UpdateLayout()
                 continue;
             VerticalAlignment verticalAlignment = children_[i]->verticalAlignment_;
             children_[i]->verticalAlignment_ = VA_TOP;
-            children_[i]->SetPosition(GetLayoutChildPosition(children_[i]).x_, positions[j]);
+            children_[i]->SetPosition(GetLayoutChildPosition(children_[i]).x_ + baseIndentWidth, positions[j]);
             children_[i]->verticalAlignment_ = verticalAlignment;
             children_[i]->SetSize(width - layoutBorder_.left_ - layoutBorder_.right_, sizes[j]);
             ++j;

+ 6 - 0
Engine/UI/UIElement.h

@@ -328,6 +328,12 @@ public:
     int GetMaxWidth() const { return maxSize_.x_; }
     /// Return minimum height.
     int GetMaxHeight() const { return maxSize_.y_; }
+    /// Return true if size is fixed.
+    bool IsFixedSize() const { return minSize_ == maxSize_; }
+    /// Return true if width is fixed.
+    bool IsFixedWidth() const { return minSize_.x_ == maxSize_.x_; }
+    /// Return true if height is fixed.
+    bool IsFixedHeight() const { return minSize_.y_ == maxSize_.y_; }
     /// Return child element offset.
     const IntVector2& GetChildOffset() const { return childOffset_; }
     /// Return horizontal alignment.