From 47854f318fe3b02646320649c151f45b889b55af Mon Sep 17 00:00:00 2001 From: Efruit <602406+Efruit@users.noreply.github.com> Date: Sun, 19 Dec 2021 06:55:24 -0500 Subject: [PATCH] UserInterface/TextLayout: Ignore spaces at the start of a soft break --- Robust.Client/UserInterface/TextLayout.cs | 33 ++++++++++++----------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Robust.Client/UserInterface/TextLayout.cs b/Robust.Client/UserInterface/TextLayout.cs index 8c7e2ccb6af..9fd3022df1a 100644 --- a/Robust.Client/UserInterface/TextLayout.cs +++ b/Robust.Client/UserInterface/TextLayout.cs @@ -149,12 +149,14 @@ int lnh blank: () => new () { lnrem = w, maxPri = 1, wds = new List(), gaps = new List() } ); - var flib = fonts.StartFont(fclass); var lastAlign = TextAlign.Left; // Since we edit this one, we need to make a copy. var wdq = text.ShallowClone(); + // forced newline, disables skipping leading spaces + var fnl = false; + // Calculate line boundaries for (var i = 0; i < wdq.Count; i++) { @@ -162,11 +164,17 @@ int lnh var wd = wdq[i]; var sec = src[wd.section]; var hz = sec.Alignment.Horizontal(); - var sf = flib.Update(sec.Style, sec.Size); (int gW, int adv) = TransitionWeights(lastAlign, hz); + + if (!fnl && wd.wt == WordType.Space && lw.Work.wds.Count == 0) + continue; + + fnl=false; + if (wd.wt == WordType.LineBreak) { lw.Flush(); + fnl=true; } else if (lw.Work.lnrem < wd.w) { @@ -217,6 +225,8 @@ int lnh else { lw.Flush(); + if (wd.wt == WordType.Space) + continue; } } @@ -232,7 +242,7 @@ int lnh } lw.Flush(true); - flib = fonts.StartFont(fclass); + var flib = fonts.StartFont(fclass); int py = flib.Current.GetAscent(scale); int lnnum = 0; foreach (var (ln, gaps, lnrem, sptot, maxPri, tPri, lnh) in lw.Done) @@ -385,21 +395,14 @@ public static List Split( var runec=0; foreach (var r in sec.Content.EnumerateRunes()) { - if (r == (Rune) '\n') + WordType cr = Classify(r); + if (wq.Work.wt != cr || cr == WordType.LineBreak) { wq.Flush(); - wq.Work.wt = WordType.LineBreak; - } - else if (Rune.IsSeparator(r)) - { - if (wq.Work.wt != WordType.Space) - { - wq.Flush(); - wq.Work.wt = WordType.Space; - } + wq.Work.wt = cr; + if (cr == WordType.LineBreak) + wq.Flush(); } - else if (wq.Work.wt != WordType.Normal) - wq.Flush(); var cm = fnt.GetCharMetrics(r, scale, !nofb); if (!cm.HasValue)