Elements are now pass-scoped value handles: tests that read bounds after a frame bind a ui.Handle. pixel tells frames apart by the build pass's root, since the Tester clock no longer moves on its own. Fix the regressions the upgrade brought: - Clipboard reads in input handlers go through c.Services(). - MyGo notes an overlay's opener after building it, so AutoFocus inside lost it; pixel.AutoFocus focuses through a Handle, and archtest bans the raw call. Dialogs hand the focus back again. - Elements around a press stay hovered: Tooltip tells a press-given focus by focus arriving under the pointer. - The web host moves the Tester clock with real time, at most 500 ms a call, and gives components the real clock. The gallery's source index also accepts CRLF checkouts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package chat
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type DateSeparatorOptions struct {
|
|
// Width is in dots; zero means 200.
|
|
Width int
|
|
}
|
|
|
|
// DateSeparator rules a line with TODAY, YESTERDAY or the date.
|
|
func DateSeparator(c *ui.Context, day time.Time, o DateSeparatorOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
now := k.Now()
|
|
// At midnight today becomes yesterday.
|
|
k.At(c, time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, now.Location()))
|
|
return rule(c, k, dayName(k, day.In(now.Location()), now), pixel.Or("DateSeparator Width", o.Width, 200), pixel.Faint, pixel.Edge)
|
|
}
|
|
|
|
// dayName is TODAY, YESTERDAY, or the locale's short date.
|
|
func dayName(k pixel.Kit, day, now time.Time) string {
|
|
same := func(a, b time.Time) bool { return a.Year() == b.Year() && a.YearDay() == b.YearDay() }
|
|
switch {
|
|
case same(day, now):
|
|
return k.Msg("today")
|
|
case same(day, now.AddDate(0, 0, -1)):
|
|
return k.Msg("yesterday")
|
|
}
|
|
wd, months := strings.Fields(k.Msg("days")), strings.Fields(k.Msg("months"))
|
|
return fmt.Sprintf(k.Msg("day_date"), wd[day.Weekday()], day.Day(), months[day.Month()-1], int(day.Month()))
|
|
}
|