From ce21b34f8631acc5a9d78e3c66953ee4faf7bf21 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 19 Sep 2024 10:42:48 -0400 Subject: [PATCH] Fix LayoutBoundsSpace --- flow.go | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/flow.go b/flow.go index 35b7d8b..d1a9001 100644 --- a/flow.go +++ b/flow.go @@ -19,15 +19,15 @@ func reflow ( var dot fixed.Point26_6 const notSeen = -1 - firstWord := notSeen - lineStart := 0 - lineEnd := 0 - lastWord := 0 - lastToken := 0 - nLines := 0 - firstLine := true + firstWord := notSeen + lineStart := 0 + lineEnd := 0 + lastWord := 0 + lastNonLineBreak := notSeen + nLines := 0 + firstLine := true - newline := func () { + newline := func (wrapped bool) { // if the line isn't empty if lineStart != lineEnd { // align line @@ -46,12 +46,16 @@ func reflow ( } lastWordTok := tokens[lastWord] - lastTokenTok := tokens[lastToken] if lastWordTok.kind == tokenKindWord { // the line had a word in it lineMax = lastWordTok.position.X + lastWordTok.width } - lineMaxSpace = lastTokenTok.position.X + lastTokenTok.width + if wrapped || lastNonLineBreak == notSeen { + lineMaxSpace = lineMax + } else { + lastTokenTok := tokens[lastNonLineBreak] + lineMaxSpace = lastTokenTok.position.X + lastTokenTok.width + } // println(lineMax.String(), lineMaxSpace.String()) if lineMin < extents.Min.X || firstLine { extents.Min.X = lineMin } @@ -66,9 +70,10 @@ func reflow ( dot.X = 0 // update indices, counts - lineStart = lineEnd - lastWord = lineEnd - firstWord = notSeen + lineStart = lineEnd + lastWord = lineEnd + lastNonLineBreak = notSeen + firstWord = notSeen nLines ++ } @@ -78,7 +83,9 @@ func reflow ( for index, token := range tokens { lineEnd = index updateIndices := func () { - lastToken = index + if token.kind != tokenKindLineBreak { + lastNonLineBreak = index + } if token.kind == tokenKindWord { lastWord = index if firstWord == notSeen { @@ -89,7 +96,7 @@ func reflow ( // demarcate lines if sawLineBreak { - newline() + newline(false) sawLineBreak = false } if token.kind == tokenKindLineBreak { @@ -102,7 +109,7 @@ func reflow ( token.kind == tokenKindWord && dot.X + token.width > size.X if needWrap { - newline() + newline(true) } updateIndices() tokens[index].position = dot @@ -110,7 +117,7 @@ func reflow ( } } lineEnd ++ // make lineEnd equal to len(tokens) - newline() + newline(false) minimumSize.Y = metrics.Height * fixed.Int26_6(nLines) + metrics.Descent // second, vertical alignment pass