[Label] When rendering, do not use byte count as the visible width, fixes https://github.com/migueldeicaza/gui.cs/issues/130

This commit is contained in:
miguel
2018-09-21 23:27:52 -04:00
parent 123df8657f
commit 4fcaf39088

View File

@@ -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);