From 5ec2fa5aa8d6649f7c05a0ad99824873db049c4b Mon Sep 17 00:00:00 2001 From: Mats Linander Date: Tue, 10 Jan 2023 12:44:29 -0500 Subject: [PATCH] add Root.show_full_animation for overriding app cycle speed (#558) --- docs/widgets.md | 1 + encode/encode.go | 10 +++++---- encode/encode_test.go | 24 +++++++++++++++++++++ render/root.go | 9 ++++---- runtime/modules/render_runtime/generated.go | 16 ++++++++++---- 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/docs/widgets.md b/docs/widgets.md index 19edfa6d2e..0c47f321c1 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -328,6 +328,7 @@ displaying stale data in the event of e.g. connectivity issues. | `child` | `Widget` | Widget to render | **Y** | | `delay` | `int` | Frame delay in milliseconds | N | | `max_age` | `int` | Expiration time in seconds | N | +| `show_full_animation` | `bool` | Request animation is shown in full, regardless of app cycle speed | N | diff --git a/encode/encode.go b/encode/encode.go index 4c53da0d36..aa9607cef7 100644 --- a/encode/encode.go +++ b/encode/encode.go @@ -26,10 +26,11 @@ const ( ) type Screens struct { - roots []render.Root - images []image.Image - delay int32 - MaxAge int32 + roots []render.Root + images []image.Image + delay int32 + MaxAge int32 + ShowFullAnimation bool } type ImageFilter func(image.Image) (image.Image, error) @@ -47,6 +48,7 @@ func ScreensFromRoots(roots []render.Root) *Screens { if roots[0].MaxAge > 0 { screens.MaxAge = roots[0].MaxAge } + screens.ShowFullAnimation = roots[0].ShowFullAnimation } return &screens } diff --git a/encode/encode_test.go b/encode/encode_test.go index c9d45d0804..bf769d76a3 100644 --- a/encode/encode_test.go +++ b/encode/encode_test.go @@ -227,3 +227,27 @@ func TestScreensFromRoots(t *testing.T) { assert.Equal(t, int32(4711), s.delay) assert.Equal(t, int32(42), s.MaxAge) } + +func TestShowFullAnimation(t *testing.T) { + requestFull := ` +load("render.star", "render") +def main(): + return render.Root(show_full_animation=True, child=render.Box()) +` + app := runtime.Applet{} + require.NoError(t, app.Load("test.star", []byte(requestFull), nil)) + roots, err := app.Run(map[string]string{}) + assert.NoError(t, err) + assert.True(t, ScreensFromRoots(roots).ShowFullAnimation) + + dontRequestFull := ` +load("render.star", "render") +def main(): + return render.Root(child=render.Box()) +` + app = runtime.Applet{} + require.NoError(t, app.Load("test.star", []byte(dontRequestFull), nil)) + roots, err = app.Run(map[string]string{}) + assert.NoError(t, err) + assert.False(t, ScreensFromRoots(roots).ShowFullAnimation) +} diff --git a/render/root.go b/render/root.go index 0f780bae73..404aaa6df8 100644 --- a/render/root.go +++ b/render/root.go @@ -37,11 +37,12 @@ const ( // DOC(Child): Widget to render // DOC(Delay): Frame delay in milliseconds // DOC(MaxAge): Expiration time in seconds -// +// DOC(ShowFullAnimation): Request animation is shown in full, regardless of app cycle speed type Root struct { - Child Widget `starlark:"child,required"` - Delay int32 `starlark:"delay"` - MaxAge int32 `starlark:"max_age"` + Child Widget `starlark:"child,required"` + Delay int32 `starlark:"delay"` + MaxAge int32 `starlark:"max_age"` + ShowFullAnimation bool `starlark:"show_full_animation"` maxParallelFrames int maxFrameCount int diff --git a/runtime/modules/render_runtime/generated.go b/runtime/modules/render_runtime/generated.go index 9c06b67df3..fc8068d81f 100644 --- a/runtime/modules/render_runtime/generated.go +++ b/runtime/modules/render_runtime/generated.go @@ -1174,9 +1174,10 @@ func newRoot( ) (starlark.Value, error) { var ( - child starlark.Value - delay starlark.Int - max_age starlark.Int + child starlark.Value + delay starlark.Int + max_age starlark.Int + show_full_animation starlark.Bool ) if err := starlark.UnpackArgs( @@ -1185,6 +1186,7 @@ func newRoot( "child", &child, "delay?", &delay, "max_age?", &max_age, + "show_full_animation?", &show_full_animation, ); err != nil { return nil, fmt.Errorf("unpacking arguments for Root: %s", err) } @@ -1215,6 +1217,8 @@ func newRoot( return nil, err } + w.ShowFullAnimation = bool(show_full_animation) + return w, nil } @@ -1224,7 +1228,7 @@ func (w *Root) AsRenderRoot() render.Root { func (w *Root) AttrNames() []string { return []string{ - "child", "delay", "max_age", + "child", "delay", "max_age", "show_full_animation", } } @@ -1243,6 +1247,10 @@ func (w *Root) Attr(name string) (starlark.Value, error) { return starlark.MakeInt(int(w.MaxAge)), nil + case "show_full_animation": + + return starlark.Bool(w.ShowFullAnimation), nil + default: return nil, nil }