Files
MujicaUI/messaging/video_call_grid.go
T
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

111 lines
3.3 KiB
Go

package messaging
import (
"math"
"strings"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/display"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/internal"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/media"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
)
// CallParticipant supplies identity, frames and call state.
type CallParticipant struct {
ID, Name string
// Frame is their video; nil shows their avatar.
Frame ui.ImageSource
Image *ui.Bitmap
Muted bool
CameraOff bool
Speaking bool
}
// VideoCallGridOptions configure a VideoCallGrid.
type VideoCallGridOptions struct {
// Columns fixes the column count; zero fits a near-square grid.
Columns int
}
// VideoCallGrid displays participant frames and speaker marks.
func VideoCallGrid(c *ui.Context, people []CallParticipant, opts VideoCallGridOptions) ui.Element {
if opts.Columns < 0 {
panic("mujica: VideoCallGrid Columns must not be negative")
}
seen := map[string]bool{}
for _, p := range people {
if p.ID == "" || p.Name == "" || seen[p.ID] {
panic("mujica: VideoCallGrid participants need unique IDs and names: " + p.ID)
}
seen[p.ID] = true
}
cols := opts.Columns
if cols == 0 {
cols = max(1, int(math.Ceil(math.Sqrt(float64(len(people))))))
}
k := core.Tokens(c)
u := core.Density(c).Unit()
tracks := make([]ui.Track, cols)
for i := range tracks {
tracks[i] = ui.Fr(1)
}
grid := ui.Box(c).Grid().ColumnTracks(tracks...).Gap(u * 2).FocusGroup(ui.Horizontal | ui.Vertical).
Role(ui.RoleGroup).Label(core.Msg(c, "video_call_grid.label"))
grid.Children(func() {
for _, p := range people {
callTile(c, k, p)
}
})
return grid
}
func callTile(c *ui.Context, k theme.Tokens, p CallParticipant) {
u := core.Density(c).Unit()
var notes []string
if p.Speaking {
notes = append(notes, core.Msg(c, "video_call_grid.speaking"))
}
if p.Muted {
notes = append(notes, core.Msg(c, "video_call_grid.muted"))
}
if p.CameraOff {
notes = append(notes, core.Msg(c, "video_call_grid.cameraOff"))
}
label := p.Name
if len(notes) > 0 {
label += ", " + strings.Join(notes, ", ")
}
tile := ui.Box(c.Key(p.ID)).AspectRatio(16.0 / 9).Radius(theme.CardRadius).Clip().Background(media.VideoBlack).Center().
Focusable().Role(ui.RoleImage).Label(label)
internal.Ring(tile, k.Focus, theme.CardRadius)
light := ui.Hex("#F2EBDD")
tile.Children(func() {
if p.Frame != nil && !p.CameraOff {
ui.Image(c, p.Frame).Fit(ui.Cover).Absolute().Left(0).Top(0).Right(0).Bottom(0)
} else {
display.Avatar(c, p.Name, display.AvatarOptions{Image: p.Image, Size: 56})
}
ui.Row(c).Absolute().Left(u*2).Bottom(u*2).Gap(u).AlignItems(ui.Center).Padding(2, u*1.5).
Radius(theme.ControlRadius).Background(ui.RGBA(0, 0, 0, 0.6)).TextColor(light).Children(func() {
if p.Muted {
ui.Icon(c, msgMicOff).Size(13, 13).TextColor(ui.Hex("#F0A1AA"))
}
if p.Speaking {
ui.Icon(c, msgSpeaking).Size(13, 13)
}
ui.Text(c, p.Name).FontSize(core.FontSize(c, theme.CaptionSize)).SingleLine()
})
})
if p.Speaking {
tile.DrawOver(func(pt *ui.Painter, r ui.Rect) {
pt.Stroke(ui.Rect{X: r.X + 1.5, Y: r.Y + 1.5, W: r.W - 3, H: r.H - 3}, k.AccentText, theme.CardRadius, 3)
if tile.FocusVisible() {
internal.FocusRing(pt, r, theme.CardRadius, k.Focus)
}
})
}
}