Text bounds are now returned correctly
This commit is contained in:
@@ -111,7 +111,7 @@ type LineLayout struct {
|
||||
// wrap is set to true, this function will stop processing words once maxWidth
|
||||
// is crossed. The word which would have crossed over the limit will not be
|
||||
// processed.
|
||||
func DoLine (text []rune, face font.Face, wrap bool, maxWidth fixed.Int26_6) (line LineLayout, remaining []rune) {
|
||||
func DoLine (text []rune, face font.Face, wrap bool, width fixed.Int26_6) (line LineLayout, remaining []rune) {
|
||||
remaining = text
|
||||
x := fixed.Int26_6(0)
|
||||
lastWord := WordLayout { }
|
||||
@@ -122,9 +122,9 @@ func DoLine (text []rune, face font.Face, wrap bool, maxWidth fixed.Int26_6) (li
|
||||
word.X = x
|
||||
x += word.Width
|
||||
|
||||
// if we have gone over the maximum width, stop processing
|
||||
// if we have gone over the preferred width, stop processing
|
||||
// words (if wrap is enabled)
|
||||
if !isFirstWord && wrap && x > maxWidth {
|
||||
if !isFirstWord && wrap && x > width {
|
||||
break
|
||||
}
|
||||
|
||||
@@ -149,9 +149,13 @@ func DoLine (text []rune, face font.Face, wrap bool, maxWidth fixed.Int26_6) (li
|
||||
}
|
||||
|
||||
// set the width of the line's content.
|
||||
line.Width = maxWidth
|
||||
line.ContentWidth = lastWord.X + lastWord.Width
|
||||
line.SpaceAfter = lastWord.SpaceAfter
|
||||
if wrap {
|
||||
line.Width = width
|
||||
} else {
|
||||
line.Width = line.ContentWidth
|
||||
}
|
||||
line.SpaceAfter = lastWord.SpaceAfter
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user