Initial implementation of visibility

This commit is contained in:
Darren Burns
2022-01-18 12:48:30 +00:00
parent d7bcd00938
commit 88ec4ba19d
3 changed files with 45 additions and 19 deletions

View File

@@ -8,6 +8,7 @@ class BasicApp(App):
def on_load(self):
"""Bind keys here."""
self.bind("tab", "toggle_class('#sidebar', '-active')")
self.bind("a", "toggle_class('#header', '-no-header')")
def on_mount(self):
"""Build layout here."""

19
src/textual/blank.py Normal file
View File

@@ -0,0 +1,19 @@
from __future__ import annotations
from rich.console import Console, ConsoleOptions
from rich.segment import Segment
from rich.style import StyleType
class Blank:
def __init__(self, style: StyleType, width: int | None = None, height: int | None = None):
self.style = style
self.width = width
self.height = height
def __rich_console__(self, console: Console, console_options: ConsoleOptions):
render_width = self.width or console_options.max_width
render_height = self.height or console_options.height or console_options.max_height
style = console.get_style(self.style)
for _ in range(render_height):
yield Segment(" " * render_width + "\n", style)

View File

@@ -14,11 +14,13 @@ from typing import (
import rich.repr
from rich import box
from rich.align import Align
from rich.console import Console, RenderableType
from rich.console import Console, RenderableType, ConsoleOptions
from rich.measure import Measurement
from rich.panel import Panel
from rich.padding import Padding
from rich.pretty import Pretty
from rich.style import Style
from rich.segment import Segment
from rich.style import Style, StyleType
from rich.styled import Styled
from rich.text import Text, TextType
@@ -27,6 +29,7 @@ from . import errors
from ._animator import BoundAnimator
from ._border import Border, BORDER_STYLES
from ._callback import invoke
from .blank import Blank
from .dom import DOMNode
from ._context import active_app
from .geometry import Size, Spacing, SpacingDimensions
@@ -158,28 +161,31 @@ class Widget(DOMNode):
renderable = self.render()
styles = self.styles
parent_text_style = self.parent.text_style
text_style = styles.text
renderable_text_style = parent_text_style + text_style
if renderable_text_style:
renderable = Styled(renderable, renderable_text_style)
if styles.has_padding:
renderable = Padding(
renderable, styles.padding, style=renderable_text_style
)
if styles.visibility == "hidden":
renderable = Blank(parent_text_style)
else:
text_style = styles.text
renderable_text_style = parent_text_style + text_style
if renderable_text_style:
renderable = Styled(renderable, renderable_text_style)
if styles.has_border:
renderable = Border(renderable, styles.border, style=renderable_text_style)
if styles.has_padding:
renderable = Padding(
renderable, styles.padding, style=renderable_text_style
)
if styles.has_margin:
renderable = Padding(renderable, styles.margin, style=parent_text_style)
if styles.has_border:
renderable = Border(renderable, styles.border, style=renderable_text_style)
if styles.has_outline:
renderable = Border(
renderable, styles.outline, outline=True, style=renderable_text_style
)
if styles.has_margin:
renderable = Padding(renderable, styles.margin, style=parent_text_style)
if styles.has_outline:
renderable = Border(
renderable, styles.outline, outline=True, style=renderable_text_style
)
return renderable