mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Inline some properties, pull condition outside loop
This commit is contained in:
@@ -41,7 +41,7 @@ One such event is the *mount* event which is sent to an application after it ent
|
|||||||
|
|
||||||
!!! info
|
!!! 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:
|
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:
|
||||||
|
|
||||||
|
|||||||
@@ -608,8 +608,9 @@ class Compositor:
|
|||||||
"""Return True if the widget is (literally) visible by examining various
|
"""Return True if the widget is (literally) visible by examining various
|
||||||
properties which affect whether it can be seen or not."""
|
properties which affect whether it can be seen or not."""
|
||||||
return (
|
return (
|
||||||
widget.visible
|
widget.styles.visibility != "hidden"
|
||||||
and not widget.is_transparent
|
and not widget.is_scrollable
|
||||||
|
and widget.styles.background.is_transparent
|
||||||
and widget.styles.opacity > 0
|
and widget.styles.opacity > 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,12 @@ class TextOpacity:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
_Segment = Segment
|
_Segment = Segment
|
||||||
|
_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:
|
for segment in segments:
|
||||||
text, style, control = segment
|
text, style, control = segment
|
||||||
if not style:
|
if not style:
|
||||||
@@ -68,16 +74,11 @@ class TextOpacity:
|
|||||||
|
|
||||||
color = style.color
|
color = style.color
|
||||||
bgcolor = style.bgcolor
|
bgcolor = style.bgcolor
|
||||||
|
|
||||||
if opacity > 0:
|
|
||||||
if color and color.triplet and bgcolor and bgcolor.triplet:
|
if color and color.triplet and bgcolor and bgcolor.triplet:
|
||||||
color_style = _get_blended_style_cached(bgcolor, color, opacity)
|
color_style = _get_blended_style_cached(bgcolor, color, opacity)
|
||||||
yield _Segment(text, style + color_style)
|
yield _Segment(text, style + color_style)
|
||||||
else:
|
else:
|
||||||
yield segment
|
yield segment
|
||||||
else:
|
|
||||||
empty_text = cell_len(text) * " "
|
|
||||||
yield _Segment(empty_text, Style.from_color(bgcolor=bgcolor))
|
|
||||||
|
|
||||||
def __rich_console__(
|
def __rich_console__(
|
||||||
self, console: Console, options: ConsoleOptions
|
self, console: Console, options: ConsoleOptions
|
||||||
|
|||||||
Reference in New Issue
Block a user