2
0
Эх сурвалжийг харах

Trying to debug @bdisp's About box issue

Tig 1 жил өмнө
parent
commit
6f9fb1a68d

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

@@ -580,11 +580,9 @@ public class TextFormatter
     public List<string> GetLines ()
     public List<string> GetLines ()
     {
     {
         string text = _text!;
         string text = _text!;
-        int width = _constrainToWidth.GetValueOrDefault ();
-        int height = _constrainToHeight.GetValueOrDefault ();
 
 
         // With this check, we protect against subclasses with overrides of Text
         // With this check, we protect against subclasses with overrides of Text
-        if (string.IsNullOrEmpty (Text) || width == 0 || height == 0)
+        if (string.IsNullOrEmpty (Text) || ConstrainToWidth is 0 || ConstrainToHeight is 0)
         {
         {
             _lines = [string.Empty];
             _lines = [string.Empty];
             NeedsFormat = false;
             NeedsFormat = false;
@@ -597,6 +595,9 @@ public class TextFormatter
             return _lines;
             return _lines;
         }
         }
 
 
+        int width = ConstrainToWidth ?? int.MaxValue;
+        int height = ConstrainToHeight ?? int.MaxValue;
+
         if (FindHotKey (_text!, HotKeySpecifier, out _hotKeyPos, out Key newHotKey))
         if (FindHotKey (_text!, HotKeySpecifier, out _hotKeyPos, out Key newHotKey))
         {
         {
             HotKey = newHotKey;
             HotKey = newHotKey;

+ 9 - 11
UICatalog/UICatalog.cs

@@ -382,17 +382,15 @@ internal class UICatalogApp
             _themeMenuBarItem = new ("_Themes", _themeMenuItems);
             _themeMenuBarItem = new ("_Themes", _themeMenuItems);
 
 
             _aboutMessage = new ();
             _aboutMessage = new ();
-            _aboutMessage.AppendLine (@"UI Catalog: A comprehensive sample library for");
-            _aboutMessage.AppendLine (
-                                      """
-                                       _______                  _             _   _____       _
-                                      |__   __|                (_)           | | / ____|     (_)
-                                         | | ___ _ __ _ __ ___  _ _ __   __ _| || |  __ _   _ _
-                                         | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
-                                         | |  __/ |  | | | | | | | | | | (_| | || |__| | |_| | |
-                                         |_|\___|_|  |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|
-                                      """);
-            _aboutMessage.AppendLine (@"");
+            _aboutMessage.AppendLine ($"UI Catalog: A comprehensive sample library for");
+            _aboutMessage.AppendLine (@"
+ _______                  _             _   _____       _
+|__   __|                (_)           | | / ____|     (_)
+   | | ___ _ __ _ __ ___  _ _ __   __ _| || |  __ _   _ _
+   | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
+   | |  __/ |  | | | | | | | | | | (_| | || |__| | |_| | |
+   |_|\___|_|  |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|
+");
             _aboutMessage.AppendLine (@"v2 - Pre-Alpha");
             _aboutMessage.AppendLine (@"v2 - Pre-Alpha");
             _aboutMessage.AppendLine (@"");
             _aboutMessage.AppendLine (@"");
             _aboutMessage.AppendLine (@"https://github.com/gui-cs/Terminal.Gui");
             _aboutMessage.AppendLine (@"https://github.com/gui-cs/Terminal.Gui");

+ 29 - 0
UnitTests/Text/TextFormatterTests.cs

@@ -7193,4 +7193,33 @@ B  ")]
     }
     }
 
 
     #endregion
     #endregion
+
+    [Fact]
+    public void UICatalog_AboutBox_Text ()
+    {
+        StringBuilder _aboutMessage = new ();
+        _aboutMessage.AppendLine ($"UI Catalog: A comprehensive sample library for");
+        _aboutMessage.AppendLine (@"
+ _______                  _             _   _____       _
+|__   __|                (_)           | | / ____|     (_)
+   | | ___ _ __ _ __ ___  _ _ __   __ _| || |  __ _   _ _
+   | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
+   | |  __/ |  | | | | | | | | | | (_| | || |__| | |_| | |
+   |_|\___|_|  |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|
+");
+        _aboutMessage.AppendLine (@"v2 - Pre-Alpha");
+        _aboutMessage.AppendLine (@"");
+        _aboutMessage.AppendLine (@"https://github.com/gui-cs/Terminal.Gui");
+
+        TextFormatter tf = new ()
+        {
+            Text = _aboutMessage.ToString(),
+            WordWrap = false,
+            MultiLine = true,
+            HotKeySpecifier = (Rune)0xFFFF
+        };
+
+        Size tfSize = tf.FormatAndGetSize ();
+        Assert.Equal (new Size (58, 13), tfSize);
+    }
 }
 }