mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
background logic
This commit is contained in:
@@ -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()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
Reference in New Issue
Block a user