mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #774 from Textualize/dont-render-zero-opacity-text
Minimise rendering when text-opacity/opacity is zero
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
Screen {
|
||||
layout: center;
|
||||
background: darkslategrey;
|
||||
}
|
||||
|
||||
.box1 {
|
||||
#box1 {
|
||||
background: darkmagenta;
|
||||
width: auto;
|
||||
padding: 4 8;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Static
|
||||
from textual.binding import Binding
|
||||
from textual.widgets import Static, Footer
|
||||
|
||||
|
||||
class JustABox(App):
|
||||
BINDINGS = [
|
||||
Binding(key="t", action="text_fade_out", description="text-opacity fade out"),
|
||||
Binding(key="o", action="widget_fade_out", description="opacity fade out"),
|
||||
]
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Static("Hello, world!", classes="box1")
|
||||
yield Static("Hello, world!", id="box1")
|
||||
yield Footer()
|
||||
|
||||
def action_text_fade_out(self) -> None:
|
||||
box = self.query_one("#box1")
|
||||
self.animator.animate(box.styles, "text_opacity", value=0.0, duration=1)
|
||||
|
||||
def action_widget_fade_out(self) -> None:
|
||||
box = self.query_one("#box1")
|
||||
self.animator.animate(box.styles, "opacity", value=0.0, duration=1)
|
||||
|
||||
|
||||
app = JustABox(watch_css=True, css_path="../darren/just_a_box.css")
|
||||
|
||||
Reference in New Issue
Block a user