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

+26
View File
@@ -0,0 +1,26 @@
package text
import (
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type KbdOptions struct {
Pressed bool
}
// Kbd is a keycap with depth; Pressed sinks it.
func Kbd(c *ui.Context, label string, o KbdOptions) *ui.Element {
k := pixel.K(c)
face := pixel.LineHeight + 2
return block(c, k, label, pixel.Measure(label)+10, face+3, func(g pixel.Canvas) {
top := 0
if o.Pressed {
top = 2
}
g.Frame(0, 2, g.W, face+1, pixel.Flat, pixel.Shade)
g.Frame(0, top, g.W, face, pixel.Raised, pixel.Face)
g.Text(5, top+1, label, pixel.Ink, 1)
})
}