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>
91 lines
2.9 KiB
Go
91 lines
2.9 KiB
Go
package feedback
|
|
|
|
import (
|
|
"cmp"
|
|
"fmt"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/icons"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
|
|
)
|
|
|
|
// EmptyKind tells why there is nothing to show. The zero value is EmptyNoData.
|
|
type EmptyKind int
|
|
|
|
const (
|
|
// EmptyNoData: the collection itself is empty.
|
|
EmptyNoData EmptyKind = iota
|
|
// EmptyNoResults: a search or filter matched nothing.
|
|
EmptyNoResults
|
|
)
|
|
|
|
// EmptyStateOptions configure an EmptyState. Empty texts use the kind's built-in copy.
|
|
type EmptyStateOptions struct {
|
|
Kind EmptyKind
|
|
Title string
|
|
Description string
|
|
// Query, for EmptyNoResults, is named in the default description.
|
|
Query string
|
|
// Icon replaces the kind's icon (inbox or search); NoIcon shows none.
|
|
Icon *ui.SVG
|
|
NoIcon bool
|
|
// Action labels a button, such as "Clear search"; empty shows none.
|
|
Action string
|
|
}
|
|
|
|
// EmptyStateResult is what an EmptyState built and reported this frame.
|
|
type EmptyStateResult struct {
|
|
Element ui.Element
|
|
Action bool
|
|
}
|
|
|
|
// EmptyState explains an empty view and offers a next step.
|
|
func EmptyState(c *ui.Context, opts EmptyStateOptions) EmptyStateResult {
|
|
if opts.NoIcon && opts.Icon != nil {
|
|
panic("mujica: EmptyState with both Icon and NoIcon")
|
|
}
|
|
k := core.Tokens(c)
|
|
u := core.Density(c).Unit()
|
|
title, desc, icon := opts.Title, opts.Description, opts.Icon
|
|
switch opts.Kind {
|
|
case EmptyNoData:
|
|
if opts.Query != "" {
|
|
panic("mujica: EmptyState Query needs EmptyNoResults")
|
|
}
|
|
title = cmp.Or(title, core.Msg(c, "empty_state.no_data.title"))
|
|
desc = cmp.Or(desc, core.Msg(c, "empty_state.no_data.description"))
|
|
if icon == nil {
|
|
icon = icons.Must("inbox")
|
|
}
|
|
case EmptyNoResults:
|
|
title = cmp.Or(title, core.Msg(c, "empty_state.no_results.title"))
|
|
if desc == "" && opts.Query != "" {
|
|
desc = fmt.Sprintf(core.Msg(c, "empty_state.no_results.query"), opts.Query)
|
|
}
|
|
desc = cmp.Or(desc, core.Msg(c, "empty_state.no_results.description"))
|
|
if icon == nil {
|
|
icon = icons.Must("search")
|
|
}
|
|
default:
|
|
panic(fmt.Sprintf("mujica: unknown EmptyKind %d", int(opts.Kind)))
|
|
}
|
|
var res EmptyStateResult
|
|
res.Element = ui.Column(c).FillWidth().AlignItems(ui.Center).Gap(u*2).Padding(u*8, u*4).Role(ui.RoleGroup).Label(title)
|
|
res.Element.Children(func() {
|
|
if !opts.NoIcon {
|
|
ui.Icon(c, icon).Size(32, 32).TextColor(k.TextMuted).Margin(0, 0, u*2, 0)
|
|
}
|
|
ui.Text(c, title).Font(theme.SerifFont).FontSize(core.FontSize(c, theme.H3Size)).TextColor(k.Text).TextAlign(ui.Center)
|
|
ui.Text(c, desc).TextColor(k.TextMuted).TextAlign(ui.Center).MaxWidth(360).LineHeight(theme.LineHeight)
|
|
if opts.Action != "" {
|
|
ui.Box(c).Margin(u*2, 0, 0, 0).Children(func() {
|
|
res.Action = input.Button(c, opts.Action, input.ButtonOptions{Variant: input.Secondary}).Clicked()
|
|
})
|
|
}
|
|
})
|
|
return res
|
|
}
|