optimized property

This commit is contained in:
Will McGugan
2022-07-29 15:45:24 +01:00
parent 9458ad73e1
commit 9aecc86152
2 changed files with 19 additions and 1 deletions

View File

@@ -93,7 +93,7 @@ class StylesCache:
Returns:
Lines: Rendered lines.
"""
base_background, _base_color, background, _color = widget.colors
base_background, background = widget.background_colors
padding = widget.styles.padding + widget.scrollbar_gutter
lines = self.render(
widget.styles,

View File

@@ -370,6 +370,24 @@ class DOMNode(MessagePump):
)
return style
@property
def background_colors(self) -> tuple[Color, Color]:
"""Get the background color and the color of the parent's background.
Returns:
tuple[Color, Color]: Tuple of (base background, background)
"""
base_background = background = Color(0, 0, 0, 0)
for node in reversed(self.ancestors):
styles = node.styles
if styles.has_rule("background"):
base_background = background
background += styles.background
return (base_background, background)
@property
def colors(self) -> tuple[Color, Color, Color, Color]:
"""Gets the Widgets foreground and background colors, and its parent's (base) colors.