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

Enable animation of offset with a tuple #3028

Open
TomJGooding opened this issue Jul 29, 2023 · 3 comments · May be fixed by #3056
Open

Enable animation of offset with a tuple #3028

TomJGooding opened this issue Jul 29, 2023 · 3 comments · May be fixed by #3056

Comments

@TomJGooding
Copy link
Contributor

TomJGooding commented Jul 29, 2023

The docs say that "You can apply animations to styles such as offset to move widgets around the screen".

But how?

I found this discussion #1569 from back in January, which suggests this might be a bug?

from textual.app import App, ComposeResult
from textual.geometry import Offset
from textual.widgets import Footer, Static


class ExampleApp(App):
    BINDINGS = [("space", "animate_offset", "Animate Offet")]

    CSS = """
    Screen {
        align: center middle;
    }

    Static {
        background: red;
        width: auto;
        height: 3;
        content-align: center middle;
    }
    """

    def compose(self) -> ComposeResult:
        yield Static("Animate me!")
        yield Footer()

    def action_animate_offset(self) -> None:
        static = self.query_one(Static)
        static.styles.animate(
            attribute="offset",
            value=Offset(10, 10),  # crashes
            # value="10 10",  # crashes
            # value=(10, 10),  # crashes
            duration=0.5,
        )


if __name__ == "__main__":
    app = ExampleApp()
    app.run()
@github-actions
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@yuvalmo
Copy link
Contributor

yuvalmo commented Aug 3, 2023

The problem seems to be trying to animate a propery of type ScalarOffset (offset) with a type of Offset.
I changed value to be a ScalarOffset then it worked for me.

from textual.app import App, ComposeResult
from textual.css.scalar import ScalarOffset  # <-- Changed import
from textual.widgets import Footer, Static


class ExampleApp(App):
    BINDINGS = [("space", "animate_offset", "Animate Offet")]

    CSS = """
    Screen {
        align: center middle;
    }

    Static {
        background: red;
        width: auto;
        height: 3;
        content-align: center middle;
    }
    """

    def compose(self) -> ComposeResult:
        yield Static("Animate me!")
        yield Footer()

    def action_animate_offset(self) -> None:
        static = self.query_one(Static)
        static.styles.animate(
            attribute="offset",
            value=ScalarOffset.from_offset((10, 10)),  # <-- Changed here
            duration=0.5,
        )


if __name__ == "__main__":
    app = ExampleApp()
    app.run()

This still leaves a few problems:

  • The line I changed gets an error from the type checker, because value is expected to be str | float | Animatable.
  • Using a tuple or string still doesn't work.

P.S. I used textual version 0.32.0.

@willmcgugan
Copy link
Collaborator

I think it should work in the way Tom intuited. If the ScalarOffset that @yuvalmo suggested works, then that might be a good workaround for now. But in the future it should really be as simple as animating to the tuple of two values.

@willmcgugan willmcgugan changed the title Animate offset? Enable animation of offset with a tuple Aug 3, 2023
yuvalmo added a commit to yuvalmo/textual that referenced this issue Aug 3, 2023
yuvalmo added a commit to yuvalmo/textual that referenced this issue Aug 3, 2023
yuvalmo added a commit to yuvalmo/textual that referenced this issue Aug 3, 2023
@yuvalmo yuvalmo linked a pull request Aug 3, 2023 that will close this issue
3 tasks
yuvalmo added a commit to yuvalmo/textual that referenced this issue Aug 7, 2023
yuvalmo added a commit to yuvalmo/textual that referenced this issue Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants