Fix bug where vertically aligned text would creep downward

This commit is contained in:
Sasha Koshka 2024-05-05 02:34:32 -04:00
parent a54d40b52c
commit a1bd411e43

View File

@ -100,6 +100,7 @@ func (setter *TypeSetter) needAlignedLayout () {
setter.alignVertically()
}
// should only be called from within setter.needAlignedLayout
func (setter *TypeSetter) alignHorizontally () {
if len(setter.lines) == 0 { return }
@ -120,6 +121,7 @@ func (setter *TypeSetter) alignHorizontally () {
}
}
// should only be called from within setter.needAlignedLayout
func (setter *TypeSetter) alignVertically () {
if setter.height == 0 { return }
if len(setter.lines) == 0 { return }
@ -129,20 +131,27 @@ func (setter *TypeSetter) alignVertically () {
}
// determine how much to shift lines
topOffset := 0
topOffset := fixed.I(0)
contentHeight := setter.layoutBoundsSpace.Dy()
if setter.vAlign == AlignMiddle {
topOffset += (setter.height - contentHeight) / 2
topOffset += fixed.I((setter.height - contentHeight) / 2)
} else if setter.vAlign == AlignEnd {
topOffset += setter.height - contentHeight
topOffset += fixed.I(setter.height - contentHeight)
}
// we may be re-aligning already aligned text. if the text is shifted
// away from the origin, account for that.
if len(setter.lines) > 0 {
topOffset -= setter.lines[0].Y
}
// shift lines
for index := range setter.lines {
setter.lines[index].Y += fixed.I(topOffset)
setter.lines[index].Y += topOffset
}
}
// should only be called from within setter.alignVertically
func (setter *TypeSetter) justifyVertically () {
spaceCount := len(setter.lines) - 1
contentHeight := setter.layoutBoundsSpace.Dy()