Skip to content

Commit

Permalink
add Root.show_full_animation for overriding app cycle speed (#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
matslina authored Jan 10, 2023
1 parent e6db987 commit 5ec2fa5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |



Expand Down
10 changes: 6 additions & 4 deletions encode/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
24 changes: 24 additions & 0 deletions encode/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
9 changes: 5 additions & 4 deletions render/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions runtime/modules/render_runtime/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5ec2fa5

Please sign in to comment.