Pārlūkot izejas kodu

Merge branch 'v2_develop' into v2_fixes_2432_Dim_AutoSize

Tig 1 gadu atpakaļ
vecāks
revīzija
dc348335a4

+ 1 - 1
Terminal.Gui/Drawing/Thickness.cs

@@ -221,7 +221,7 @@ public class Thickness : IEquatable<Thickness>
                 Alignment = TextAlignment.Centered,
                 VerticalAlignment = VerticalTextAlignment.Bottom
             };
-            tf.Draw (rect, Application.Driver.CurrentAttribute, Application.Driver.CurrentAttribute, rect, false);
+            tf.Draw (rect, Application.Driver.CurrentAttribute, Application.Driver.CurrentAttribute, rect);
         }
 
         return GetInside (rect);

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

@@ -170,6 +170,13 @@ public class TextFormatter
         }
     }
 
+    /// <summary>
+    ///     Determines if the bounds width will be used or only the text width will be used,
+    ///     If <see langword="true"/> all the bounds area will be filled with whitespaces and the same background color
+    ///     showing a perfect rectangle.
+    /// </summary>
+    public bool FillRemaining { get; set; }
+
     /// <summary>Gets or sets the hot key. Fires the <see cref="HotKeyChanged"/> event.</summary>
     public Key HotKey
     {
@@ -297,7 +304,6 @@ public class TextFormatter
     /// <param name="normalColor">The color to use for all text except the hotkey</param>
     /// <param name="hotColor">The color to use to draw the hotkey</param>
     /// <param name="containerBounds">Specifies the screen-relative location and maximum container size.</param>
-    /// <param name="fillRemaining">Determines if the bounds width will be used (default) or only the text width will be used.</param>
     /// <param name="driver">The console driver currently used by the application.</param>
     /// <exception cref="ArgumentOutOfRangeException"></exception>
     public void Draw (
@@ -305,7 +311,6 @@ public class TextFormatter
         Attribute normalColor,
         Attribute hotColor,
         Rect containerBounds = default,
-        bool fillRemaining = true,
         ConsoleDriver driver = null
     )
     {
@@ -509,7 +514,7 @@ public class TextFormatter
                         continue;
                     }
 
-                    if (!fillRemaining && idx > runes.Length - 1)
+                    if (!FillRemaining && idx > runes.Length - 1)
                     {
                         break;
                     }

+ 1 - 1
Terminal.Gui/View/Adornment/Adornment.cs

@@ -141,7 +141,7 @@ public class Adornment : View
             }
         }
 
-        TextFormatter?.Draw (screenBounds, normalAttr, normalAttr, Rect.Empty, false);
+        TextFormatter?.Draw (screenBounds, normalAttr, normalAttr, Rect.Empty);
 
         //base.OnDrawContent (contentArea);
     }

+ 1 - 2
Terminal.Gui/View/ViewDrawing.cs

@@ -389,8 +389,7 @@ public partial class View
                                  BoundsToScreen (contentArea),
                                  HasFocus ? GetFocusColor () : GetNormalColor (),
                                  HasFocus ? ColorScheme.HotFocus : GetHotNormalColor (),
-                                 Rect.Empty,
-                                 false
+                                 Rect.Empty
                                 );
             SetSubViewNeedsDisplay ();
         }

+ 1 - 2
Terminal.Gui/Views/ProgressBar.cs

@@ -193,8 +193,7 @@ public class ProgressBar : View
                       BoundsToScreen (Bounds),
                       attr,
                       ColorScheme.Normal,
-                      SuperView?.BoundsToScreen (SuperView.Bounds) ?? default (Rect),
-                      false
+                      SuperView?.BoundsToScreen (SuperView.Bounds) ?? default (Rect)
                      );
         }
     }

+ 55 - 4
UnitTests/Text/TextFormatterTests.cs

@@ -419,7 +419,6 @@ ssb
                  new Attribute (ColorName.White, ColorName.Black),
                  new Attribute (ColorName.Blue, ColorName.Black),
                  default (Rect),
-                 true,
                  driver
                 );
         TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
@@ -427,6 +426,61 @@ ssb
         driver.End ();
     }
 
+    [Fact]
+    [SetupFakeDriver]
+    public void FillRemaining_True_False ()
+    {
+        ((FakeDriver)Application.Driver).SetBufferSize (22, 5);
+
+        Attribute [] attrs =
+        {
+            Attribute.Default, new Attribute (ColorName.Green, ColorName.BrightMagenta),
+            new Attribute (ColorName.Blue, ColorName.Cyan)
+        };
+        var tf = new TextFormatter { Size = new Size (14, 3), Text = "Test\nTest long\nTest long long\n", MultiLine = true };
+
+        tf.Draw (
+                 new Rect (1, 1, 19, 3),
+                 attrs [1],
+                 attrs [2]);
+
+        Assert.False (tf.FillRemaining);
+
+        TestHelpers.AssertDriverContentsWithFrameAre (
+                                                      @"
+ Test          
+ Test long     
+ Test long long",
+                                                      _output);
+
+        TestHelpers.AssertDriverAttributesAre (
+                                               @"
+000000000000000000000
+011110000000000000000
+011111111100000000000
+011111111111111000000
+000000000000000000000",
+                                               null,
+                                               attrs);
+
+        tf.FillRemaining = true;
+
+        tf.Draw (
+                 new Rect (1, 1, 19, 3),
+                 attrs [1],
+                 attrs [2]);
+
+        TestHelpers.AssertDriverAttributesAre (
+                                               @"
+000000000000000000000
+011111111111111111110
+011111111111111111110
+011111111111111111110
+000000000000000000000",
+                                               null,
+                                               attrs);
+    }
+
     [Theory]
     [InlineData ("_k Before", true, 0, (KeyCode)'K')] // lower case should return uppercase Hotkey
     [InlineData ("a_k Second", true, 1, (KeyCode)'K')]
@@ -2010,7 +2064,6 @@ ssb
                  new Attribute (ColorName.White, ColorName.Black),
                  new Attribute (ColorName.Blue, ColorName.Black),
                  default (Rect),
-                 true,
                  driver
                 );
         TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
@@ -2049,7 +2102,6 @@ ssb
                  new Attribute (ColorName.White, ColorName.Black),
                  new Attribute (ColorName.Blue, ColorName.Black),
                  default (Rect),
-                 true,
                  driver
                 );
         TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);
@@ -2088,7 +2140,6 @@ ssb
                  new Attribute (ColorName.White, ColorName.Black),
                  new Attribute (ColorName.Blue, ColorName.Black),
                  default (Rect),
-                 true,
                  driver
                 );
         TestHelpers.AssertDriverContentsWithFrameAre (expected, _output, driver);

+ 3 - 7
UnitTests/Views/LabelTests.cs

@@ -179,7 +179,7 @@ Test
         tf1.Text = "This TextFormatter (tf1) without fill will not be cleared on rewritten.";
         Size tf1Size = tf1.Size;
 
-        var tf2 = new TextFormatter { Direction = TextDirection.LeftRight_TopBottom };
+        var tf2 = new TextFormatter { Direction = TextDirection.LeftRight_TopBottom, FillRemaining = true };
         tf2.Text = "This TextFormatter (tf2) with fill will be cleared on rewritten.";
         Size tf2Size = tf2.Size;
 
@@ -191,9 +191,7 @@ Test
         tf1.Draw (
                   new Rect (new Point (0, 1), tf1Size),
                   label.GetNormalColor (),
-                  label.ColorScheme.HotNormal,
-                  default (Rect),
-                  false
+                  label.ColorScheme.HotNormal
                  );
 
         tf2.Draw (new Rect (new Point (0, 2), tf2Size), label.GetNormalColor (), label.ColorScheme.HotNormal);
@@ -215,9 +213,7 @@ This TextFormatter (tf2) with fill will be cleared on rewritten.
         tf1.Draw (
                   new Rect (new Point (0, 1), tf1Size),
                   label.GetNormalColor (),
-                  label.ColorScheme.HotNormal,
-                  default (Rect),
-                  false
+                  label.ColorScheme.HotNormal
                  );
 
         tf2.Text = "This TextFormatter (tf2) is rewritten.";