Add text components 021-040 with demos and behavior tests

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 18:20:12 -04:00
1 parent 43098065bf
commit 59fde4096d
30 files changed
+1702 -7

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
package text
import (
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
var rainbow = []pixel.Slot{pixel.Bad, pixel.Warn, pixel.Good, pixel.Info, pixel.Magic}
type RainbowTextOptions struct {
// Band is zero for Bad, Warn, Good, Info, Magic.
Band []pixel.Slot
Scale int
}
// RainbowText gives each character the next slot of a band.
func RainbowText(c *ui.Context, s string, o RainbowTextOptions) *ui.Element {
k, sc := pixel.K(c), scale(o.Scale)
band := o.Band
if len(band) == 0 {
band = rainbow
}
return block(c, k, s, pixel.Measure(s)*sc, pixel.LineHeight*sc, func(g pixel.Canvas) {
cur := pixel.Cycle(band, g.Step(8))
each(s, sc, func(i int, r rune, x int) {
g.Text(x, 0, string(r), cur[i%len(cur)], sc)
})
})
}