Skip to content

Commit

Permalink
UserInterface/TextLayout: Ignore spaces at the start of a soft break
Browse files Browse the repository at this point in the history
  • Loading branch information
Efruit committed Dec 19, 2021
1 parent a7e9d26 commit 47854f3
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Robust.Client/UserInterface/TextLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,32 @@ int lnh
blank: () => new () { lnrem = w, maxPri = 1, wds = new List<Offset>(), gaps = new List<int>() }
);

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++)
{
restart:
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)
{
Expand Down Expand Up @@ -217,6 +225,8 @@ int lnh
else
{
lw.Flush();
if (wd.wt == WordType.Space)
continue;
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -385,21 +395,14 @@ public static List<Offset> 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)
Expand Down

0 comments on commit 47854f3

Please sign in to comment.