Преглед изворни кода

Sorta fixed vertical. Broke wide runes

Tig пре 1 година
родитељ
комит
c65596b2d0
2 измењених фајлова са 10 додато и 5 уклоњено
  1. 9 4
      Terminal.Gui/Text/TextFormatter.cs
  2. 1 1
      UnitTests/Text/TextFormatterTests.cs

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

@@ -304,6 +304,7 @@ public class TextFormatter
             {
                 if (isVertical)
                 {
+                    // BUGBUG:  This works with a very limited set of wide-char scenarios.
                     int runesWidth = runes.Length == 0 ? 0 : runes.Max (r => GetRuneWidth (r, TabWidth));
                     x = screen.Left + (screen.Width - _lines.Count - 1) + (runesWidth + line);
                     CursorPosition = screen.Width - runesWidth + (_hotKeyPos > -1 ? _hotKeyPos : 0);
@@ -319,8 +320,11 @@ public class TextFormatter
             {
                 if (isVertical)
                 {
-                    int runesWidth = runes.Length == 0 ? 0 : runes.Max (r => GetRuneWidth (r, TabWidth));
-                    x = screen.Left + runesWidth + line - 1;
+                    // BUGBUG: This works only if a) all lines have only single-wide chars and b) only one line has wide chars
+                    int runesWidth = line > 0
+                                         ? GetColumnsRequiredForVerticalText (linesFormatted, 0, line, TabWidth)
+                                         : 0;
+                    x = screen.Left + runesWidth;
                 }
                 else
                 {
@@ -333,8 +337,9 @@ public class TextFormatter
             {
                 if (isVertical)
                 {
-                    int runesWidth = runes.Length == 0 ? 0 : runes.Max (r => GetRuneWidth (r, TabWidth));
-                    x = screen.Left + (screen.Width / 2) - (_lines.Count  / 2) + (runesWidth + line - 1);
+                    // BUGBUG: This works with a very limited set of wide-char scenarios. 
+                    int runesWidth = GetColumnsRequiredForVerticalText (linesFormatted, tabWidth: TabWidth);
+                    x = screen.Left + line + (screen.Width - runesWidth) / 2;
 
                     CursorPosition = (screen.Width - runesWidth) / 2 + (_hotKeyPos > -1 ? _hotKeyPos : 0);
                 }

+ 1 - 1
UnitTests/Text/TextFormatterTests.cs

@@ -3482,7 +3482,7 @@ ssb
     [InlineData ("A", 2, false, "A")]
     [InlineData ("AB12", 5, false, "AB12")]
     [InlineData ("AB\n12", 5, false, "A1\nB2")]
-    [InlineData ("デモエ", 1, false, "")]
+    [InlineData ("", 1, false, "")]
 
     public void Draw_Vertical_TopBottom_LeftRight (string text, int width, bool autoSize, string expectedText)
     {