Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose widget frame count #827

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ A quick note about colors. When specifying colors, use a CSS-like
hexdecimal color specification. Pixlet supports "#rgb", "#rrggbb",
"#rgba", and "#rrggbbaa" color specifications.

For animated widgets like Marquee, you can also call `frame_count()`
to work out how many frames are required to display the whole
animation. You can also call `size()` on dynamically-sized widgets
like Text to get the width and height.


## Animation
Animations turns a list of children into an animation, where each
Expand Down
5 changes: 5 additions & 0 deletions runtime/gen/docs/render.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ A quick note about colors. When specifying colors, use a CSS-like
hexdecimal color specification. Pixlet supports "#rgb", "#rrggbb",
"#rgba", and "#rrggbbaa" color specifications.

For animated widgets like Marquee, you can also call `frame_count()`
to work out how many frames are required to display the whole
animation. You can also call `size()` on dynamically-sized widgets
like Text to get the width and height.

{{range .}}{{if .Documentation}}{{$name := .GoName}}
## {{.GoName}}
{{.Documentation}}
Expand Down
24 changes: 24 additions & 0 deletions runtime/gen/type.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type {{.GoName}} struct {
{{if .HasSize}}
size *starlark.Builtin
{{end}}
{{if .GoWidgetName}}
frame_count *starlark.Builtin
{{end}}
}

func new{{.GoName}}(
Expand Down Expand Up @@ -44,6 +47,9 @@ func new{{.GoName}}(
{{if .HasSize}}
w.size = starlark.NewBuiltin("size", {{.GoName|ToLower}}Size)
{{end}}
{{if .GoWidgetName}}
w.frame_count = starlark.NewBuiltin("frame_count", {{.GoName|ToLower}}FrameCount)
{{end}}

{{if .HasInit}}
if err := w.Init(); err != nil {
Expand Down Expand Up @@ -93,6 +99,10 @@ func (w *{{.GoName}}) Attr(name string) (starlark.Value, error) {
{{if .HasSize}}
case "size":
return w.size.BindReceiver(w), nil
{{end}}
{{if .GoWidgetName}}
case "frame_count":
return w.frame_count.BindReceiver(w), nil
{{end}}
default:
return nil, nil
Expand Down Expand Up @@ -126,3 +136,17 @@ func {{.GoName|ToLower}}Size(
}

{{end}}
{{if .GoWidgetName}}
func {{.GoName|ToLower}}FrameCount(
thread *starlark.Thread,
b *starlark.Builtin,
args starlark.Tuple,
kwargs []starlark.Tuple) (starlark.Value, error) {

w := b.Receiver().(*{{.GoName}})
count := w.FrameCount()

return starlark.MakeInt(count), nil
}

{{end}}
38 changes: 38 additions & 0 deletions runtime/modules/animation_runtime/generated.go

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

Loading