Fix LayoutBoundsSpace

This commit is contained in:
Sasha Koshka 2024-09-19 10:42:48 -04:00
parent ff8f86e034
commit ce21b34f86

41
flow.go
View File

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