Add display components 041-065; move Icon into display; QR via rsc.io/qr
This commit is contained in:
41 files changed
+2152
-44
No files matched your search
@@ -4,6 +4,9 @@ import "fmt"
|
||||
|
||||
var bayer = [4][4]int{{0, 8, 2, 10}, {12, 4, 14, 6}, {3, 11, 1, 9}, {15, 7, 13, 5}}
|
||||
|
||||
// Bayer is the 4×4 ordered threshold, 0–15, at x, y.
|
||||
func Bayer(x, y int) int { return bayer[y&3][x&3] }
|
||||
|
||||
// Dither fills b below the level threshold, a elsewhere.
|
||||
func (g Canvas) Dither(x, y, w, h int, a, b Slot, level int) {
|
||||
checkLevel(level)
|
||||
|
||||
@@ -77,27 +77,6 @@ func WrapWidth(c *ui.Context, e *ui.Element) (int, func(r ui.Rect)) {
|
||||
}
|
||||
}
|
||||
|
||||
type IconOptions struct {
|
||||
Slot Slot
|
||||
Scale int
|
||||
// Label names the icon; empty hides it from assistive technology.
|
||||
Label string
|
||||
}
|
||||
|
||||
func Icon(c *ui.Context, sp *Sprite, o IconOptions) *ui.Element {
|
||||
k := K(c)
|
||||
scale := scaleOr1(o.Scale)
|
||||
e := ui.Box(c).Size(k.D(sp.W*scale), k.D(sp.H*scale))
|
||||
if o.Label != "" {
|
||||
e.Label(o.Label).Role(ui.RoleImage)
|
||||
} else {
|
||||
e.Role(ui.RoleNone)
|
||||
}
|
||||
return e.Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
k.Canvas(p, r).Sprite(0, 0, sp, 0, o.Slot, scale)
|
||||
})
|
||||
}
|
||||
|
||||
func scaleOr1(s int) int {
|
||||
if s == 0 {
|
||||
return 1
|
||||
|
||||
@@ -150,22 +150,6 @@ func TestTextElement(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIconElement(t *testing.T) {
|
||||
sp := pixel.MustSprite("aa\naa\naa")
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
pixel.Use(c, pixel.Settings{Palette: pixel.SpringDay, Dot: 2})
|
||||
pixel.Icon(c, sp, pixel.IconOptions{Scale: 3, Label: "block"})
|
||||
pixel.Icon(c, sp, pixel.IconOptions{})
|
||||
}, 100, 100)
|
||||
r, ok := tt.Find("block")
|
||||
if !ok || r.W != 2*3*2 || r.H != 3*3*2 {
|
||||
t.Fatalf("icon box %v found %v, want 12×18", r, ok)
|
||||
}
|
||||
if len(tt.Texts()) != 1 {
|
||||
t.Fatalf("unlabeled icon is visible to assistive technology: %q", tt.Texts())
|
||||
}
|
||||
}
|
||||
|
||||
func shellView(disabled *bool, clicks *int, st *pixel.State) func(c *ui.Context) {
|
||||
at := time.Unix(1_700_000_001, 250_000_000)
|
||||
return func(c *ui.Context) {
|
||||
|
||||
@@ -9,6 +9,9 @@ var messages = map[Locale]map[string]string{
|
||||
"search": "SEARCH", "empty": "NO ITEMS", "minimize": "MINIMIZE", "resize": "RESIZE",
|
||||
"scroll_up": "SCROLL UP", "scroll_down": "SCROLL DOWN",
|
||||
"up": "UP", "down": "DOWN", "left": "LEFT", "right": "RIGHT", "disabled": "DISABLED",
|
||||
"remove": "REMOVE", "online": "ONLINE", "away": "AWAY", "busy": "BUSY", "offline": "OFFLINE",
|
||||
"gold": "GOLD", "silver": "SILVER", "bronze": "BRONZE",
|
||||
"common": "COMMON", "uncommon": "UNCOMMON", "rare": "RARE", "epic": "EPIC", "legendary": "LEGENDARY",
|
||||
},
|
||||
Zh: {
|
||||
"ok": "确定", "cancel": "取消", "yes": "是", "no": "否", "close": "关闭",
|
||||
@@ -16,6 +19,9 @@ var messages = map[Locale]map[string]string{
|
||||
"search": "搜索", "empty": "空空如也", "minimize": "最小化", "resize": "调整大小",
|
||||
"scroll_up": "向上滚动", "scroll_down": "向下滚动",
|
||||
"up": "上", "down": "下", "left": "左", "right": "右", "disabled": "已禁用",
|
||||
"remove": "移除", "online": "在线", "away": "离开", "busy": "忙碌", "offline": "离线",
|
||||
"gold": "金", "silver": "银", "bronze": "铜",
|
||||
"common": "普通", "uncommon": "优秀", "rare": "稀有", "epic": "史诗", "legendary": "传说",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,16 @@ func microGlyph(r rune) [MicroHeight]uint8 {
|
||||
return g
|
||||
}
|
||||
|
||||
// MicroOK reports whether the micro font has all of s.
|
||||
func MicroOK(s string) bool {
|
||||
for _, r := range s {
|
||||
if _, ok := micro[unicode.ToUpper(r)]; !ok {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// MicroWidth returns the width of s in dots.
|
||||
func MicroWidth(s string) int {
|
||||
n := 0
|
||||
|
||||
@@ -31,6 +31,11 @@ const (
|
||||
|
||||
const Slots = 16
|
||||
|
||||
var slotNames = [Slots]string{"Ink", "Back", "Face", "Lit", "Shade", "Edge", "Faint", "Well",
|
||||
"Accent", "AccentLit", "AccentInk", "Good", "Warn", "Bad", "Info", "Magic"}
|
||||
|
||||
func (s Slot) String() string { return slotNames[s] }
|
||||
|
||||
type Season uint8
|
||||
|
||||
const (
|
||||
|
||||
Reference in new issue
Block a user