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>
76 lines
2.4 KiB
Go
76 lines
2.4 KiB
Go
package messaging
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/chat"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
|
|
)
|
|
|
|
// PinnedMessagesResult is the list's element and this frame's events.
|
|
type PinnedMessagesResult struct {
|
|
Element ui.Element
|
|
// Jump requests navigation; Unpinned requests removing a pin.
|
|
Jump, Unpinned string
|
|
}
|
|
|
|
// PinnedMessagesOptions configure a PinnedMessages.
|
|
type PinnedMessagesOptions struct {
|
|
// Height caps the list; zero means 320.
|
|
Height float32
|
|
Disabled bool
|
|
}
|
|
|
|
// PinnedMessages virtualizes pins and emits navigation or removal requests.
|
|
func PinnedMessages(c *ui.Context, pins []ChatEntry, opts PinnedMessagesOptions) PinnedMessagesResult {
|
|
if opts.Height < 0 {
|
|
panic("mujica: PinnedMessages Height must not be negative")
|
|
}
|
|
h := opts.Height
|
|
if h == 0 {
|
|
h = 320
|
|
}
|
|
k := core.Tokens(c)
|
|
u := core.Density(c).Unit()
|
|
var r PinnedMessagesResult
|
|
col := ui.Column(c).Gap(u * 2).Role(ui.RoleGroup).Label(fmt.Sprintf(core.Msg(c, "pinned_messages.title"), len(pins))).
|
|
Disabled(opts.Disabled)
|
|
r.Element = col
|
|
col.Children(func() {
|
|
ui.Row(c).Gap(u * 2).AlignItems(ui.Center).Children(func() {
|
|
ui.Icon(c, msgPin).Size(16, 16).TextColor(k.Ornament)
|
|
ui.Text(c, fmt.Sprintf(core.Msg(c, "pinned_messages.title"), len(pins))).Font(theme.SerifFont).FontWeight(600)
|
|
})
|
|
if len(pins) == 0 {
|
|
ui.Text(c, core.Msg(c, "pinned_messages.empty")).TextColor(k.TextMuted)
|
|
return
|
|
}
|
|
state := ui.Local(col, "pinned.rows", func() ui.ListState { return ui.ListState{} })
|
|
state.Key = func(i int) any { return pins[i].ID }
|
|
ui.List(c, state, len(pins), func(i int) {
|
|
m := pins[i]
|
|
if m.ID == "" || m.Author == "" {
|
|
panic("mujica: PinnedMessages entries need ID and Author")
|
|
}
|
|
ui.Row(c).MinHeight(core.Density(c).ControlHeight()).Gap(u).AlignItems(ui.Center).Children(func() {
|
|
if chat.QuoteReply(c, m.Author, m.Text).Grow(1).MaxWidth(10000).Clicked() && !col.IsDisabled() {
|
|
r.Jump = m.ID
|
|
}
|
|
b := core.IconAction(c, msgPin, fmt.Sprintf(core.Msg(c, "pinned_messages.unpin"), m.Author))
|
|
if b.Clicked() && !b.IsDisabled() {
|
|
r.Unpinned = m.ID
|
|
}
|
|
})
|
|
}).Height(min(h, float32(len(pins))*core.Density(c).ControlHeight())).Gap(u * 2).FocusGroup(ui.Vertical)
|
|
|
|
})
|
|
if r.Jump != "" || r.Unpinned != "" {
|
|
slog.Debug("mujica: pinned_messages", "jump", r.Jump, "unpin", r.Unpinned)
|
|
}
|
|
return r
|
|
}
|