Files
ZacharyZhang-NYandClaude Opus 5.5 bcce34cda1 Upgrade MyGo to v0.5.5
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>
2026-10-17 01:37:54 -04:00

105 lines
3.6 KiB
Go

package messaging
import (
"fmt"
"log/slog"
"strings"
"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/input"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
)
// ThreadPanelOptions configure a ThreadPanel.
type ThreadPanelOptions struct {
// Width is the panel's width; zero means 360.
Width float32
Disabled bool
}
// ThreadPanelResult is the panel's element and this frame's events.
type ThreadPanelResult struct {
Element ui.Element
// Sent is a reply the user sent; empty is none.
Sent string
}
type threadState struct {
list chat.MessageListState
draft string
}
type threadKey struct{}
// ThreadPanel displays a root message, replies and an editor.
func ThreadPanel(c *ui.Context, open *bool, root ChatEntry, replies []ChatEntry, opts ThreadPanelOptions) ThreadPanelResult {
var r ThreadPanelResult
if opts.Width < 0 {
panic("mujica: ThreadPanel Width must not be negative")
}
w := opts.Width
if w == 0 {
w = 360
}
ww, _ := c.Size()
w = min(w, ww)
k := core.Tokens(c)
u := core.Density(c).Unit()
panel := ui.Column(c).Width(w).FillHeight().Shrink(0).Background(k.Surface).BorderWidth(0, 0, 0, 1).
BorderColor(k.Border).Role(ui.RoleGroup).Label(core.Msg(c, "thread_panel.title")).Disabled(opts.Disabled)
if panel.IsDisabled() {
*open = false
}
if !*open {
panel.Invisible()
return r
}
core.OverlayStyle(c, panel, core.OverlayEnter(c, panel))
panel.BorderWidth(0, 0, 0, 1).BorderColor(k.Border)
r.Element = panel
st := ui.Local(panel, threadKey{}, func() *threadState { return &threadState{} })
s := *st
panel.Children(func() {
ui.Row(c).Padding(u*3, u*3, u*2, u*4).AlignItems(ui.Center).Children(func() {
ui.Text(c, core.Msg(c, "thread_panel.title")).Font(theme.SerifFont).FontSize(core.FontSize(c, theme.H3Size)).FontWeight(600).Grow(1)
if core.IconAction(c, msgClose, core.Msg(c, "thread_panel.close")).Clicked() {
*open = false
}
})
ui.Scroll(c).MaxHeight(160).Shrink(1).Padding(0, u*2).Children(func() { ChatMessage(c, root, ChatMessageOptions{}) })
ui.Row(c).Gap(u*2).Padding(u*2, u*4).AlignItems(ui.Center).Children(func() {
ui.Text(c, fmt.Sprintf(core.Msg(c, "thread_panel.replies"), len(replies))).FontSize(core.FontSize(c, theme.CaptionSize)).
TextColor(k.TextMuted).SingleLine()
ui.Box(c).Height(1).Grow(1).Background(k.Border)
})
chat.MessageList(c, &s.list, len(replies), chat.MessageListOptions{
ID: func(i int) string { return replies[i].ID },
Label: func(i int) string { return replies[i].Author + ": " + replies[i].Text },
}, func(i int) {
ChatMessage(c, replies[i], ChatMessageOptions{Continued: i > 0 && ChatContinues(replies[i-1], replies[i])})
})
ui.Row(c).Gap(u*2).Padding(u*3).AlignItems(ui.Center).BorderWidth(1, 0, 0, 0).BorderColor(k.Border).Children(func() {
in := input.TextInput(c, &s.draft, input.TextInputOptions{Placeholder: core.Msg(c, "thread_panel.reply"), Label: core.Msg(c, "thread_panel.reply"), Disabled: opts.Disabled})
in.Element.Grow(1)
send := input.IconButton(c, msgSend, core.Msg(c, "thread_panel.send"), input.IconButtonOptions{Disabled: strings.TrimSpace(s.draft) == ""})
if (in.Submitted() || send.Clicked()) && strings.TrimSpace(s.draft) != "" && !panel.IsDisabled() {
r.Sent, s.draft = strings.TrimSpace(s.draft), ""
s.list.ScrollToEnd()
}
})
})
if !panel.IsDisabled() && panel.Shortcut(0, ui.KeyEscape) {
*open = false
}
switch {
case r.Sent != "":
slog.Debug("mujica: thread_panel send", "len", len(r.Sent))
case !*open:
slog.Debug("mujica: thread_panel close")
}
return r
}