make pumkin alllll better!

This commit is contained in:
2023-09-15 15:22:44 -04:00
parent 14deec24f5
commit 92cb318972
2 changed files with 44 additions and 37 deletions
+11 -16
View File
@@ -8,12 +8,11 @@ import "golang.org/x/image/math/fixed"
type Align int
const (
// AlignLeft aligns the start of each line to the beginning point
// of each dot.
AlignLeft Align = iota
AlignRight
AlignCenter
AlignJustify
// X | Y
AlignStart Align = iota // left | top
AlignMiddle // center | center
AlignEnd // right | bottom
AlignEven // justified | evenly spaced
)
// RuneLayout contains layout information for a single rune relative to its
@@ -150,11 +149,7 @@ func DoLine (text []rune, face font.Face, wrap bool, width fixed.Int26_6) (line
// set the width of the line's content.
line.ContentWidth = lastWord.X + lastWord.Width
if wrap {
line.Width = width
} else {
line.Width = line.ContentWidth
}
line.Width = width
line.SpaceAfter = lastWord.SpaceAfter
return
}
@@ -174,17 +169,17 @@ func (line *LineLayout) Length () int {
// method.
func (line *LineLayout) Align (align Align) {
if len(line.Words) == 0 { return }
if align == AlignJustify {
if align == AlignEven {
line.justify()
return
}
leftOffset := -line.Words[0].X
if align == AlignCenter {
if align == AlignMiddle {
leftOffset += (line.Width - line.ContentWidth) / 2
} else if align == AlignRight {
} else if align == AlignEnd {
leftOffset += line.Width - line.ContentWidth
}
@@ -195,7 +190,7 @@ func (line *LineLayout) Align (align Align) {
func (line *LineLayout) justify () {
if len(line.Words) < 2 {
line.Align(AlignLeft)
line.Align(AlignStart)
return
}