Snapshots: hide view until ReduceMotion applies; Spinner repaints when motion setting flips
This commit is contained in:
2 files changed
+8
-2
No files matched your search
+7
-1
@@ -20,11 +20,17 @@ var update = flag.Bool("update", false, "rewrite snapshots")
|
|||||||
func snapshot(t *testing.T, name string, w, h int, view func(c *ui.Context)) {
|
func snapshot(t *testing.T, name string, w, h int, view func(c *ui.Context)) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
for _, m := range []Mode{Light, Dark} {
|
for _, m := range []Mode{Light, Dark} {
|
||||||
|
ready := false
|
||||||
tt := ui.NewTester(func(c *ui.Context) {
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
Use(c, Settings{Mode: m})
|
Use(c, Settings{Mode: m})
|
||||||
view(c)
|
if ready {
|
||||||
|
view(c)
|
||||||
|
}
|
||||||
}, w, h)
|
}, w, h)
|
||||||
|
// Animations must not paint before ReduceMotion applies.
|
||||||
tt.SetPreferences(ui.Preferences{ReduceMotion: true, TextScale: 1})
|
tt.SetPreferences(ui.Preferences{ReduceMotion: true, TextScale: 1})
|
||||||
|
ready = true
|
||||||
|
tt.Frame()
|
||||||
got := encode(t, tt.Image())
|
got := encode(t, tt.Image())
|
||||||
path := filepath.Join("testdata", "snapshots", runtime.GOOS, name+"-"+strings.ToLower(m.String())+".png")
|
path := filepath.Join("testdata", "snapshots", runtime.GOOS, name+"-"+strings.ToLower(m.String())+".png")
|
||||||
if *update {
|
if *update {
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ func Spinner(c *ui.Context, opts SpinnerOptions) *ui.Element {
|
|||||||
still := c.Preferences().ReduceMotion
|
still := c.Preferences().ReduceMotion
|
||||||
row := ui.Row(c).Gap(Density(c).Unit() * 2).AlignItems(ui.Center).Role(ui.RoleProgress).Label(label)
|
row := ui.Row(c).Gap(Density(c).Unit() * 2).AlignItems(ui.Center).Role(ui.RoleProgress).Label(label)
|
||||||
row.Children(func() {
|
row.Children(func() {
|
||||||
ui.Box(c).Size(size, size).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) {
|
ui.Box(c).Key(still).Size(size, size).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) {
|
||||||
turn := 0.0
|
turn := 0.0
|
||||||
if !still {
|
if !still {
|
||||||
turn = float64(p.Now().UnixMilli()%1200) / 1200
|
turn = float64(p.Now().UnixMilli()%1200) / 1200
|
||||||
|
|||||||
Reference in new issue
Block a user