Replies: 4 comments 2 replies
-
I've not yet managed to get to the bottom of all the strange behaviour in your app - but it looks like animation does work for modal screens using a basic example: from textual.app import App
from textual.screen import ModalScreen
class FadeInRed(ModalScreen):
DEFAULT_CSS = """
FadeInRed {
opacity: 0%;
background: red;
}
"""
def on_mount(self) -> None:
self.styles.animate("opacity", value=1.0, duration=2.0)
class TestApp(App):
def on_mount(self) -> None:
self.push_screen(FadeInRed())
if __name__ == "__main__":
app = TestApp()
app.run() This line in your example |
Beta Was this translation helpful? Give feedback.
-
Definitely some strange behaviour once you try adding any widgets to the screen though! from textual.app import App, ComposeResult
from textual.screen import ModalScreen
from textual.widgets import Static
class FadeInWidget(Static):
DEFAULT_CSS = """
FadeInWidget {
width: auto;
opacity: 0%;
background: purple;
}
"""
def on_mount(self) -> None:
self.styles.animate("opacity", value=1.0, duration=2.0)
class FadeInScreen(ModalScreen):
DEFAULT_CSS = """
FadeInScreen {
align: center middle;
opacity: 0%;
background: red;
}
FadeInScreen #builtin {
opacity: 0%;
width: auto;
background: green;
}
"""
def compose(self) -> ComposeResult:
yield Static("Builtin widget composed in screen", id="builtin")
yield FadeInWidget("Custom widget with animation on mount")
def on_mount(self) -> None:
widget = self.query_one("#builtin", Static)
widget.styles.animate("opacity", value=1.0, duration=2.0)
class TestApp(App):
def on_mount(self) -> None:
self.push_screen(FadeInScreen())
if __name__ == "__main__":
app = TestApp()
app.run() |
Beta Was this translation helpful? Give feedback.
-
I think there is an issue with setting opacity to 0% on screens. @xyxz-web You probably want to set the background color to transparent. Try animating "background" to "transparent". Bear in mind that the terminal can't do true transparency. It is limited to blending foreground and background colors. |
Beta Was this translation helpful? Give feedback.
-
@willmcgugan: This still doesn't fade in / fade out the modal dialog though. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm trying to fade in a modal screen once it is pushed.
I've made a minimal example:
And here is the CSS:
I've tested the result in PowerShell.
There are some problems with this attempt:
Is something wrong with my attempt, or is animating Screens not supported?
Beta Was this translation helpful? Give feedback.
All reactions