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): def on_key(self, event):
if event.key.isdigit(): if event.key.isdigit():
self.styles.background = self.COLORS[int(event.key)] self.styles.background = self.COLORS[int(event.key)]
self.refresh()
self.bell() self.bell()

View File

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

View File

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

View File

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