Minimum size is calculated from extents instead of vice versa
This commit is contained in:
parent
56024caaf5
commit
f0adca5c37
20
flow.go
20
flow.go
@ -36,7 +36,7 @@ func reflow (
|
||||
lineMax, lineMaxSpace := calculateLineExtents (
|
||||
tokens[lastWord],
|
||||
tokens[lastToken])
|
||||
if lineMax > minimumSize.X { minimumSize.X = lineMax }
|
||||
if lineMax > extents.Max.X { extents.Max.X = lineMax }
|
||||
if lineMaxSpace > extentsSpace.Max.X { extentsSpace.Max.X = lineMaxSpace }
|
||||
}
|
||||
|
||||
@ -92,22 +92,32 @@ func reflow (
|
||||
alignLinesVertically(tokens, size.Y, minimumSize.Y, yAlign)
|
||||
|
||||
// calculate extents
|
||||
extentsOffset := fixed.Point26_6 { Y: metrics.Ascent - tokens[0].position.Y }
|
||||
extents.Max.X = minimumSize.X
|
||||
extentsVerticalOffset := fixed.Point26_6 { Y: metrics.Ascent - tokens[0].position.Y }
|
||||
extents.Max.Y = dot.Y + metrics.Descent
|
||||
extentsSpace.Max.Y = dot.Y + metrics.Descent
|
||||
extents = extents.Sub(extentsOffset)
|
||||
extentsSpace = extentsSpace.Sub(extentsOffset)
|
||||
minimumSize.X = fixedRectDx(extents)
|
||||
minimumSize.Y = fixedRectDy(extents)
|
||||
extents = extents.Sub(extentsVerticalOffset)
|
||||
extentsSpace = extentsSpace.Sub(extentsVerticalOffset)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func fixedRectDx (rect fixed.Rectangle26_6) fixed.Int26_6 {
|
||||
return rect.Max.X - rect.Min.X
|
||||
}
|
||||
|
||||
func fixedRectDy (rect fixed.Rectangle26_6) fixed.Int26_6 {
|
||||
return rect.Max.Y - rect.Min.Y
|
||||
}
|
||||
|
||||
func calculateLineExtents (lastWord, lastToken token) (lineMax, lineMaxSpace fixed.Int26_6) {
|
||||
if lastWord.kind == tokenKindWord {
|
||||
// the line had a word in it
|
||||
lineMax = lastWord.position.X + lastWord.width
|
||||
}
|
||||
lineMaxSpace = lastToken.position.X + lastToken.width
|
||||
// println(lineMax.String(), lineMaxSpace.String())
|
||||
return lineMax, lineMaxSpace
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user