background logic

This commit is contained in:
Will McGugan
2022-08-19 17:51:30 +01:00
parent b3feec1ef9
commit 5d8fafc74d
4 changed files with 10 additions and 12 deletions

View File

@@ -22,6 +22,7 @@ class ExampleApp(App):
def on_key(self, event):
if event.key.isdigit():
self.styles.background = self.COLORS[int(event.key)]
self.refresh()
self.bell()

View File

@@ -127,8 +127,8 @@ class App(Generic[ReturnType], DOMNode):
CSS = """
App {
background: $surface;
color: $text-surface;
background: $background;
color: $text-background;
}
"""
@@ -614,7 +614,7 @@ class App(Generic[ReturnType], DOMNode):
self.screen.refresh(layout=True)
def render(self) -> RenderableType:
return Blank()
return Blank(self.styles.background)
def get_child(self, id: str) -> DOMNode:
"""Shorthand for self.screen.get_child(id: str)

View File

@@ -11,12 +11,8 @@ class Blank:
"""Draw solid background color."""
def __init__(self, color: Color | str = "transparent") -> None:
background = color if isinstance(color, Color) else Color.parse(color)
self._style = (
Style()
if background.is_transparent
else Style.from_color(None, background.rich_color)
)
background = Color.parse(color)
self._style = Style.from_color(bgcolor=background.rich_color)
def __rich_console__(
self, console: Console, options: ConsoleOptions

View File

@@ -33,8 +33,6 @@ class Screen(Widget):
CSS = """
Screen {
background: $background;
color: $text-background;
layout: vertical;
overflow-y: auto;
}
@@ -71,7 +69,10 @@ class Screen(Widget):
pass
def render(self) -> RenderableType:
return Blank()
background = self.styles.background
if background.is_transparent:
return self.app.render()
return Blank(background)
def get_offset(self, widget: Widget) -> Offset:
"""Get the absolute offset of a given Widget.