From 4fcaf39088227125746ce0a51f9bb0b7fcd490ac Mon Sep 17 00:00:00 2001 From: miguel Date: Fri, 21 Sep 2018 23:27:52 -0400 Subject: [PATCH] [Label] When rendering, do not use byte count as the visible width, fixes https://github.com/migueldeicaza/gui.cs/issues/130 --- Terminal.Gui/Views/Label.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Views/Label.cs b/Terminal.Gui/Views/Label.cs index db6a930e1..e7e1a93d0 100644 --- a/Terminal.Gui/Views/Label.cs +++ b/Terminal.Gui/Views/Label.cs @@ -96,10 +96,14 @@ namespace Terminal.Gui { static ustring ClipAndJustify (ustring str, int width, TextAlignment talign) { - int slen = str.Length; - if (slen > width) - return str [0, width]; - else { + int slen = str.RuneCount; + if (slen > width){ + var uints = str.ToRunes (width); + var runes = new Rune [uints.Length]; + for (int i = 0; i < uints.Length; i++) + runes [i] = uints [i]; + return ustring.Make (runes); + } else { if (talign == TextAlignment.Justified) { // TODO: ustring needs this var words = str.ToString ().Split (whitespace, StringSplitOptions.RemoveEmptyEntries);