tidbyt / pixlet

Build apps for pixel-based displays ✨
https://tidbyt.com
Apache License 2.0
756 stars 107 forks source link

Feature request: animation duration introspection #823

Closed mattbroussard closed 7 months ago

mattbroussard commented 1 year ago

It's currently not possible as far as I can tell for Starlark code to tell programmatically how long an animation will be. This is not a problem for most basic animations where the number of frames is deterministic and could be computed manually by the developer, but some are dynamic: namely Marquee and any other widget that contains one.

What I'm trying to do is have an applet that displays several pages of information using a Sequence, and each one contains a Marquee with text dynamically generated according to an API response. The length of the animation Marquee does can vary based on the text, from a single frame (if the text fits on screen) to any larger number depending on the length of the text. This makes it tough to ensure that each page is on screen long enough to read, because if the page is only a single frame, I want to duplicate it in the Sequence.

My suggested fix would be either to 1) expose the FrameCount method that exists on the Go side from Starlark or 2) expose a new widget with a behavior like "min duration".

For (2), I've been able to sort of hack this behavior using animation.Transformation and wait_for_child, but this is pretty inelegant IMO and there should be a simpler primitive for this.

def MinDuration(child, min_duration):
    return animation.Transformation(
        child = child,
        keyframes = [],
        duration = min_duration,
        wait_for_child = True
    )
mattbroussard commented 1 year ago

https://github.com/tidbyt/community/pull/1652 is the applet I've been working on that employs the workaround above.

dinosaursrarr commented 1 year ago

Saw this and created a PR to make a frame_count() method available on widgets from within starlark. It delegates to the relevant Go FrameCount() method. https://github.com/tidbyt/pixlet/pull/827

mattbroussard commented 7 months ago

Addressed by #827