2
0
Tig 1 жил өмнө
parent
commit
f3b5ed7afc

+ 3 - 3
Terminal.Gui/Text/TextFormatter.cs

@@ -175,7 +175,7 @@ public class TextFormatter
             bool textWasNull = _text is null && value != null;
             _text = EnableNeedsFormat (value);
 
-            if (/*(Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) ||*/ (textWasNull && Size.IsEmpty))
+//            if (/*(Alignment != TextAlignment.Justified && VerticalAlignment != VerticalTextAlignment.Justified) ||*/ (textWasNull && Size.IsEmpty))
             {
                 Size = CalcRect (0, 0, _text, Direction, TabWidth).Size;
             }
@@ -304,7 +304,7 @@ public class TextFormatter
             {
                 if (isVertical)
                 {
-                    int runesWidth = GetWidestLineLength (linesFormatted, line, TabWidth);
+                    int runesWidth = GetWidestLineLength (linesFormatted, 0, line, TabWidth);
                     x = screen.Right - runesWidth;
                     CursorPosition = screen.Width - runesWidth + (_hotKeyPos > -1 ? _hotKeyPos : 0);
                 }
@@ -335,7 +335,7 @@ public class TextFormatter
             {
                 if (isVertical)
                 {
-                    int runesWidth = GetWidestLineLength (linesFormatted, line, TabWidth);
+                    int runesWidth = GetWidestLineLength (linesFormatted, 0, line, TabWidth);
                     x = screen.Left + line + (screen.Width - runesWidth) / 2;
 
                     CursorPosition = (screen.Width - runesWidth) / 2 + (_hotKeyPos > -1 ? _hotKeyPos : 0);

+ 1 - 3
Terminal.Gui/View/Layout/PosDim.cs

@@ -619,9 +619,7 @@ public class Dim
     {
         /// <summary>
         ///     The dimension will be computed using both the view's <see cref="View.Text"/> and
-        ///     <see cref="View.Subviews"/>.
-        ///     The larger of the corresponding text dimension or Subview in <see cref="View.Subviews"/>
-        ///     with the largest corresponding position plus dimension will determine the dimension.
+        ///     <see cref="View.Subviews"/> (whichever is larger).
         /// </summary>
         Auto,
 

+ 4 - 4
Terminal.Gui/View/Layout/ViewLayout.cs

@@ -368,14 +368,14 @@ public partial class View
             {
                 if (IsInitialized)
                 {
-                    Height = Height.Anchor (ContentSize.Height);
-                    Width = Width.Anchor (ContentSize.Width);
+                    Height = ContentSize.Height;
+                    Width = ContentSize.Width;
 
                 }
                 else
                 {
-                    _height = Height.Anchor (ContentSize.Height);
-                    _width = Width.Anchor (ContentSize.Width);
+                    _height = ContentSize.Height;
+                    _width = ContentSize.Width;
                     OnResizeNeeded ();
                 }
             }

+ 26 - 0
UnitTests/Text/TextFormatterTests.cs

@@ -154,6 +154,32 @@ public class TextFormatterTests
         Assert.Equal (new (0, 0, width, height), TextFormatter.CalcRect (0, 0, text, textDirection));
     }
 
+    [Theory]
+    [InlineData ("test", TextDirection.LeftRight_TopBottom)]
+    [InlineData (" ~  s  gui.cs   master ↑10", TextDirection.LeftRight_TopBottom)]
+    [InlineData ("Say Hello view4 你", TextDirection.LeftRight_TopBottom)]
+    [InlineData ("Say Hello view4 你", TextDirection.RightLeft_TopBottom)]
+    [InlineData ("Say Hello view4 你", TextDirection.LeftRight_BottomTop)]
+    [InlineData ("Say Hello view4 你", TextDirection.RightLeft_BottomTop)]
+    public void CalcRect_Horizontal_Width_Correct (string text, TextDirection textDirection)
+    {
+        // The width is the number of columns in the text
+        Assert.Equal (new Size ( text.GetColumns (), 1), TextFormatter.CalcRect (0, 0, text, textDirection).Size);
+    }
+
+    [Theory]
+    [InlineData ("test", TextDirection.TopBottom_LeftRight)]
+    [InlineData (" ~  s  gui.cs   master ↑10", TextDirection.TopBottom_LeftRight)]
+    [InlineData ("Say Hello view4 你", TextDirection.TopBottom_LeftRight)]
+    [InlineData ("Say Hello view4 你", TextDirection.TopBottom_RightLeft)]
+    [InlineData ("Say Hello view4 你", TextDirection.BottomTop_LeftRight)]
+    [InlineData ("Say Hello view4 你", TextDirection.BottomTop_RightLeft)]
+    public void CalcRect_Vertical_Height_Correct (string text, TextDirection textDirection)
+    {
+        // The height is based both the number of lines and the number of wide chars
+        Assert.Equal (new Size (1 + text.GetColumns() - text.Length, text.Length), TextFormatter.CalcRect (0, 0, text, textDirection).Size);
+    }
+
     [Theory]
     [InlineData ("")]
     [InlineData (null)]

+ 40 - 2
UnitTests/View/Layout/DimAutoTests.cs

@@ -1,6 +1,8 @@
 using System.Globalization;
 using System.Text;
 using Xunit.Abstractions;
+using static Terminal.Gui.Dim;
+
 
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
@@ -587,7 +589,7 @@ public class DimAutoTests
     [InlineData (1, 10, 10)]
     [InlineData (9, 10, 10)]
     [InlineData (10, 10, 10)]
-    public void Width_Auto_Subviews_Does_Not_Constrain_To_SuperView (int subX, int textLen, int expectedSubWidth)
+    public void Width_Auto_Subviews_Does_Not_Constrain_To_SuperView (int subX, int subSubViewWidth, int expectedSubWidth)
     {
         var superView = new View
         {
@@ -600,7 +602,6 @@ public class DimAutoTests
 
         var subView = new View
         {
-            Text = new string ('*', textLen),
             X = subX,
             Y = 0,
             Width = Dim.Auto (Dim.DimAutoStyle.Subviews),
@@ -608,6 +609,16 @@ public class DimAutoTests
             ValidatePosDim = true
         };
 
+        var subSubView = new View
+        {
+            X = 0,
+            Y = 0,
+            Width = subSubViewWidth,
+            Height = 1,
+            ValidatePosDim = true
+        };
+        subView.Add (subSubView);
+
         superView.Add (subView);
 
         superView.BeginInit ();
@@ -618,5 +629,32 @@ public class DimAutoTests
         Assert.Equal (expectedSubWidth, subView.Frame.Width);
     }
 
+    [Fact]
+    public void DimAuto_Text_Viewport_Stays_Set ()
+    {
+        var super = new View ()
+        {
+            Width = Dim.Fill (),
+            Height = Dim.Fill ()
+        };
+
+        var view = new View ()
+        {
+            Width = Auto (DimAutoStyle.Text),
+            Height = Auto (DimAutoStyle.Text),
+            Text = "New text"
+        };
+        Rectangle expectedViewport = new (0, 0, 8, 1);
+        Assert.Equal (expectedViewport, view.Viewport);
+
+        super.Add (view);
+        Assert.Equal (expectedViewport, view.Viewport);
+
+        super.LayoutSubviews ();
+        Assert.Equal (expectedViewport, view.Viewport);
+
+        super.Dispose ();
+    }
+
     // Test variations of Frame
 }

+ 3 - 2
UnitTests/View/Layout/DimTests.cs

@@ -75,6 +75,7 @@ public class DimTests
         Assert.Equal (10, result);
     }
 
+
     // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
     // A new test that does not depend on Application is needed.
     [Fact]
@@ -897,8 +898,8 @@ public class DimTests
                        Assert.Equal (50, v4.Frame.Width);
                        Assert.Equal (50, v4.Frame.Height);
                        v4.AutoSize = true;
-                       Assert.Equal ("Absolute(11)", v4.Width.ToString ());
-                       Assert.Equal ("Absolute(1)", v4.Height.ToString ());
+                       Assert.Equal (Dim.Auto (DimAutoStyle.Text), v4.Width);
+                       Assert.Equal (Dim.Auto (DimAutoStyle.Text), v4.Height);
                        Assert.Equal (11, v4.Frame.Width); // 11 is the text length and because is Dim.DimAbsolute
                        Assert.Equal (1, v4.Frame.Height); // 1 because is Dim.DimAbsolute
 

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 399 - 414
UnitTests/View/Text/AutoSizeTrueTests.cs


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно