From f0adca5c37fba901cc7bf6900a613751e8f277a9 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 19 Sep 2024 08:31:21 -0400 Subject: [PATCH] Minimum size is calculated from extents instead of vice versa --- flow.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/flow.go b/flow.go index b678d65..e321aac 100644 --- a/flow.go +++ b/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 }