diff --git a/docs/guide/app.md b/docs/guide/app.md index 8e924dc2b..9a807bea7 100644 --- a/docs/guide/app.md +++ b/docs/guide/app.md @@ -41,7 +41,7 @@ One such event is the *mount* event which is sent to an application after it ent !!! info - You may have noticed we use the term "send" and "sent" in relation to event handler methods in preference to "calling". This is because Textual uses a message passing system where events are passed (or *sent*) between components. We will cover the details in [events][./events.md]. + You may have noticed we use the term "send" and "sent" in relation to event handler methods in preference to "calling". This is because Textual uses a message passing system where events are passed (or *sent*) between components. We will cover the details in [events](./events.md). Another such event is the *key* event which is sent when the user presses a key. The following example contains handlers for both those events: @@ -80,7 +80,7 @@ Widgets are self-contained components responsible for generating the output for Widgets can be as simple as a piece of text, a button, or a fully-fledge component like a text editor or file browser (which may contain widgets of their own). -### Composing +### Composing To add widgets to your app implement a [`compose()`][textual.app.App.compose] method which should return a iterable of Widget instances. A list would work, but it is convenient to yield widgets, making the method a *generator*. @@ -103,7 +103,7 @@ While composing is the preferred way of adding widgets when your app starts it i Here's an app which adds the welcome widget in response to any key press: -```python title="widgets02.py" +```python title="widgets02.py" --8<-- "docs/examples/app/widgets02.py" ``` @@ -118,7 +118,7 @@ An app will run until you call [App.exit()][textual.app.App.exit] which will exi The exit method will also accept an optional positional value to be returned by `run()`. The following example uses this to return the `id` (identifier) of a clicked button. -```python title="question01.py" +```python title="question01.py" --8<-- "docs/examples/app/question01.py" ``` @@ -159,7 +159,7 @@ The following example sets the `css_path` attribute on the app: If the path is relative (as it is above) then it is taken as relative to where the app is defined. Hence this example references `"question01.css"` in the same directory as the Python code. Here is that CSS file: -```sass title="question02.css" +```sass title="question02.css" --8<-- "docs/examples/app/question02.css" ``` diff --git a/src/textual/_compositor.py b/src/textual/_compositor.py index 074154056..fc294f490 100644 --- a/src/textual/_compositor.py +++ b/src/textual/_compositor.py @@ -608,8 +608,9 @@ class Compositor: """Return True if the widget is (literally) visible by examining various properties which affect whether it can be seen or not.""" return ( - widget.visible - and not widget.is_transparent + widget.styles.visibility != "hidden" + and not widget.is_scrollable + and widget.styles.background.is_transparent and widget.styles.opacity > 0 ) diff --git a/src/textual/renderables/text_opacity.py b/src/textual/renderables/text_opacity.py index cc6845d9e..dffb5667b 100644 --- a/src/textual/renderables/text_opacity.py +++ b/src/textual/renderables/text_opacity.py @@ -60,24 +60,25 @@ class TextOpacity: """ _Segment = Segment - for segment in segments: - text, style, control = segment - if not style: - yield segment - continue + _from_color = Style.from_color + if opacity == 0: + for text, style, control in segments: + invisible_style = _from_color(bgcolor=style.bgcolor) + yield _Segment(cell_len(text) * " ", invisible_style) + else: + for segment in segments: + text, style, control = segment + if not style: + yield segment + continue - color = style.color - bgcolor = style.bgcolor - - if opacity > 0: + color = style.color + bgcolor = style.bgcolor if color and color.triplet and bgcolor and bgcolor.triplet: color_style = _get_blended_style_cached(bgcolor, color, opacity) yield _Segment(text, style + color_style) else: yield segment - else: - empty_text = cell_len(text) * " " - yield _Segment(empty_text, Style.from_color(bgcolor=bgcolor)) def __rich_console__( self, console: Console, options: ConsoleOptions