MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:
- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
elements expire and Context methods are inert: read IsDisabled into a
local during the build, keep a ui.Handle for Focus, use c.Services()
for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
content builds, so same-frame autofocus lost focus restore on close.
It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
split button tooltip no longer reorders its open menu; disabled
menubar rows pass presses to the panel; Form defers blur-started
async checks so the growing message no longer moves Submit away
from the release; Combobox drops its disabled copy now that MyGo
blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
time.Sleep/time.Now and read element state inside the view. The web
mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.
Snapshot goldens are darwin-only and were not re-verified here.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
113 lines
3.5 KiB
Go
113 lines
3.5 KiB
Go
package account
|
|
|
|
import (
|
|
"reflect"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/feedback"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
|
|
)
|
|
|
|
// ShortcutGroup is a titled group of bindings in a KeyboardShortcutsList.
|
|
type ShortcutGroup struct {
|
|
Title string
|
|
Bindings []ShortcutBinding
|
|
}
|
|
|
|
// KeyboardShortcutsListOptions configure a KeyboardShortcutsList.
|
|
type KeyboardShortcutsListOptions struct {
|
|
// Label names the search field; empty uses the built-in one.
|
|
Label string
|
|
}
|
|
|
|
type shortcutsListRow struct{ group, binding int }
|
|
|
|
type shortcutsListState struct {
|
|
groups []ShortcutGroup
|
|
query string
|
|
rows []shortcutsListRow
|
|
ready bool
|
|
}
|
|
|
|
// KeyboardShortcutsList displays searchable, grouped shortcuts using visible rows.
|
|
func KeyboardShortcutsList(c *ui.Context, query *string, groups []ShortcutGroup, opts KeyboardShortcutsListOptions) ui.Element {
|
|
k := core.Tokens(c)
|
|
d := core.Density(c)
|
|
label := opts.Label
|
|
if label == "" {
|
|
label = core.Msg(c, "keyboard_shortcuts_list.search")
|
|
}
|
|
e := ui.Column(c).Gap(d.Unit() * 4).MinWidth(320)
|
|
st := ui.Local(e, "shortcuts", func() shortcutsListState { return shortcutsListState{} })
|
|
e.Children(func() {
|
|
input.SearchInput(c, query, input.SearchInputOptions{Placeholder: label, Label: label})
|
|
shortcutsListPlan(st, groups, strings.ToLower(strings.TrimSpace(*query)))
|
|
if len(st.rows) == 0 {
|
|
feedback.EmptyState(c, feedback.EmptyStateOptions{Kind: feedback.EmptyNoResults, Query: *query})
|
|
return
|
|
}
|
|
accountRows(c, len(st.rows), func(i int) any { return st.rows[i] }, func(i int) {
|
|
r := st.rows[i]
|
|
g := groups[r.group]
|
|
if r.binding < 0 {
|
|
ui.Text(c, g.Title).Font(theme.SerifFont).FontWeight(600).TextColor(k.Text).Padding(d.Unit()*2, 0).Role(ui.RoleGroup).Label(g.Title)
|
|
return
|
|
}
|
|
b := g.Bindings[r.binding]
|
|
ui.Row(c).MinHeight(d.ControlHeight()).AlignItems(ui.Center).Gap(d.Unit()*4).
|
|
BorderWidth(0, 0, theme.BorderWidth, 0).BorderColor(k.Border).Role(ui.RoleRow).
|
|
Label(b.Action + ", " + b.Shortcut.String()).Children(func() {
|
|
ui.Text(c, b.Action).Grow(1).MinWidth(0).Role(ui.RoleNone)
|
|
shortcutKbd(c, b.Shortcut)
|
|
})
|
|
})
|
|
})
|
|
return e
|
|
}
|
|
|
|
func shortcutsListPlan(st *shortcutsListState, groups []ShortcutGroup, q string) {
|
|
if st.ready && st.query == q && reflect.DeepEqual(st.groups, groups) {
|
|
return
|
|
}
|
|
st.ready, st.query = true, q
|
|
st.groups = slices.Clone(groups)
|
|
st.rows = st.rows[:0]
|
|
for gi, g := range groups {
|
|
st.groups[gi].Bindings = slices.Clone(g.Bindings)
|
|
header := false
|
|
for bi, b := range g.Bindings {
|
|
if b.Action == "" {
|
|
panic("mujica: KeyboardShortcutsList binding needs an Action")
|
|
}
|
|
if q != "" && !strings.Contains(strings.ToLower(b.Action), q) && !strings.Contains(strings.ToLower(b.Shortcut.String()), q) {
|
|
continue
|
|
}
|
|
if !header && g.Title != "" {
|
|
st.rows = append(st.rows, shortcutsListRow{gi, -1})
|
|
header = true
|
|
}
|
|
st.rows = append(st.rows, shortcutsListRow{gi, bi})
|
|
}
|
|
}
|
|
}
|
|
|
|
func accountRows(c *ui.Context, n int, key func(int) any, row func(int)) ui.Element {
|
|
if n <= 8 {
|
|
return ui.Column(c).Children(func() {
|
|
for i := range n {
|
|
ui.Column(c.Key(key(i))).Children(func() { row(i) })
|
|
}
|
|
})
|
|
}
|
|
site := ui.Column(c).MinHeight(0).Shrink(1)
|
|
st := ui.Local(site, "rows", func() ui.ListState { return ui.ListState{} })
|
|
st.Key = key
|
|
site.Children(func() { ui.List(c, st, n, row).Height(320).MinHeight(0).Shrink(1) })
|
|
return site
|
|
}
|