Add feedback components 106-130; inert scope, focus return, two-step deploy
This commit is contained in:
87 files changed
+2492
-147
No files matched your search
+20
-5
@@ -92,15 +92,30 @@ type State struct{ Hover, Press, Focus, Disabled bool }
|
||||
func Shell(c *ui.Context, base func() *ui.Element) (shell, b *ui.Element, st State) {
|
||||
shell = ui.Box(c)
|
||||
shell.Children(func() { b = base().Fill().FocusRing(false) })
|
||||
off := b.IsDisabled()
|
||||
// MyGo keeps focus and keys on a newly disabled element.
|
||||
if off && b.Focused() {
|
||||
c.Root().Focus()
|
||||
own, inert := b.IsDisabled(), current(c).cur.Inert
|
||||
if inert {
|
||||
b.Disabled(true)
|
||||
}
|
||||
st = State{Hover: b.Hovered(), Press: b.Pressed() && !off, Focus: b.FocusVisible(), Disabled: off}
|
||||
off := own || inert
|
||||
// MyGo keeps focus and keys on a newly disabled element.
|
||||
parked := ui.Local(b, parkKey{}, func() bool { return false })
|
||||
switch {
|
||||
case off && b.Focused():
|
||||
c.Root().Focus()
|
||||
*parked = true
|
||||
case !off && *parked:
|
||||
// Focus comes back unless something else took it.
|
||||
if root := c.Root(); root.Focused() || !root.FocusWithin() {
|
||||
b.Focus()
|
||||
}
|
||||
*parked = false
|
||||
}
|
||||
st = State{Hover: b.Hovered(), Press: b.Pressed() && !off, Focus: b.FocusVisible(), Disabled: own}
|
||||
return shell, b, st
|
||||
}
|
||||
|
||||
type parkKey struct{}
|
||||
|
||||
// Hand is the pointing cursor of focus and menus.
|
||||
var Hand = MustSprite(`
|
||||
.eee......
|
||||
|
||||
@@ -13,6 +13,8 @@ var messages = map[Locale]map[string]string{
|
||||
"gold": "GOLD", "silver": "SILVER", "bronze": "BRONZE",
|
||||
"common": "COMMON", "uncommon": "UNCOMMON", "rare": "RARE", "epic": "EPIC", "legendary": "LEGENDARY",
|
||||
"hold": "HOLD TO CONFIRM", "del": "DEL", "end": "END", "lives": "+30 LIVES!",
|
||||
"retry": "RETRY", "stage_clear": "STAGE CLEAR!", "level_up": "LEVEL UP!", "achievement": "ACHIEVEMENT UNLOCKED",
|
||||
"combo": "COMBO!", "saving": "SAVING", "saved": "SAVED", "go": "GO!", "wait": "PLEASE WAIT",
|
||||
},
|
||||
Zh: {
|
||||
"ok": "确定", "cancel": "取消", "yes": "是", "no": "否", "close": "关闭",
|
||||
@@ -24,6 +26,8 @@ var messages = map[Locale]map[string]string{
|
||||
"gold": "金", "silver": "银", "bronze": "铜",
|
||||
"common": "普通", "uncommon": "优秀", "rare": "稀有", "epic": "史诗", "legendary": "传说",
|
||||
"hold": "长按确认", "del": "删", "end": "完", "lives": "命数 +30!",
|
||||
"retry": "重试", "stage_clear": "过关!", "level_up": "升级!", "achievement": "成就解锁",
|
||||
"combo": "连击!", "saving": "存档中", "saved": "已存档", "go": "开始!", "wait": "请稍候",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@ type Settings struct {
|
||||
Locale Locale
|
||||
// Now replaces the frame clock, for tests.
|
||||
Now func() time.Time
|
||||
// Inert controls take no input, as under a busy veil.
|
||||
Inert bool
|
||||
}
|
||||
|
||||
// Kit is one frame's settings, captured by components.
|
||||
@@ -131,3 +133,14 @@ func theme(p *Palette) *ui.Theme {
|
||||
t.Selection, t.Focus, t.Scrollbar, t.Radius = c[AccentLit], c[Accent], ui.Transparent, 0
|
||||
return t
|
||||
}
|
||||
|
||||
// Or is v, or def for zero; negatives panic.
|
||||
func Or(name string, v, def int) int {
|
||||
if v < 0 {
|
||||
panic(fmt.Sprintf("pixel: %s %d is negative", name, v))
|
||||
}
|
||||
if v == 0 {
|
||||
return def
|
||||
}
|
||||
return v
|
||||
}
|
||||
Reference in new issue
Block a user