+
+ private class TextEditorLayout : LayoutItem
+ {
+ protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
+ {
+ // Padding will be automatically applied by DALi TextEditor.
+ var totalWidth = widthMeasureSpec.Size.AsDecimal();
+ var totalHeight = heightMeasureSpec.Size.AsDecimal();
+ var minSize = Owner.MinimumSize;
+ var maxSize = Owner.MaximumSize;
+ var naturalSize = Owner.GetNaturalSize();
+
+ if (((TextEditor)Owner).Text.Length == 0)
+ {
+ // Calculate height of TextEditor by setting Text with " ".
+ // By calling SetTextWithoutTextChanged, TextChanged callback is not called for this.
+ ((TextEditor)Owner).SetTextWithoutTextChanged(" ");
+
+ // Store original WidthSpecification to restore it after setting ResizePolicy.
+ var widthSpecification = Owner.WidthSpecification;
+
+ // In DALi's Size logic, if Width or Height is set to be 0, then
+ // ResizePolicy is not changed to Fixed.
+ // This causes Size changes after NUI Layout's OnMeasure is finished.
+ // e.g. TextEditor's Width fills to its parent although Text is null and
+ // WidthSpecification is WrapContent.
+ // To prevent the Size changes, WidthResizePolicy is set to be Fixed
+ // in advance if Text is null.
+ Owner.WidthResizePolicy = ResizePolicyType.Fixed;
+
+ // Restore WidthSpecification because ResizePolicy changes WidthSpecification.
+ Owner.WidthSpecification = widthSpecification;
+
+ naturalSize = Owner.GetNaturalSize();
+
+ // Restore TextEditor's Text after calculating height of TextEditor.
+ // By calling SetTextWithoutTextChanged, TextChanged callback is not called for this.
+ ((TextEditor)Owner).SetTextWithoutTextChanged("");
+ }
+
+ if (widthMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
+ {
+ float width = naturalSize != null ? naturalSize.Width : 0;
+ totalWidth = Math.Min(Math.Max(width, minSize.Width), maxSize.Width);
+ }
+
+ if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
+ {
+ float height = naturalSize != null ? naturalSize.Height : 0;
+ totalHeight = Math.Min(Math.Max(height, minSize.Height), maxSize.Height);
+ }
+
+ widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
+ heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
+
+ MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
+ MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
+
+ SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, childWidthState),
+ ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
+ }
+ }