added center layout

This commit is contained in:
Will McGugan
2022-08-07 15:00:21 +01:00
parent e7cfe88b02
commit 2a85049732
2 changed files with 60 additions and 0 deletions

48
sandbox/will/center2.py Normal file
View File

@@ -0,0 +1,48 @@
from textual.app import App
from textual.layout import Vertical, Center
from textual.widgets import Static
class CenterApp(App):
CSS = """
#sidebar {
dock: left;
width: 32;
height: 100%;
border-right: vkey $primary;
}
#bottombar {
dock: bottom;
height: 12;
width: 100%;
border-top: hkey $primary;
}
#hello {
border: wide $primary;
width: 40;
height: 16;
margin: 2 4;
}
Static {
background: $panel;
color: $text-panel;
content-align: center middle;
}
"""
def compose(self):
yield Static("Sidebar", id="sidebar")
yield Vertical(
Static("Bottom bar", id="bottombar"),
Center(
Static("Hello World!", id="hello"),
),
)
app = CenterApp()

View File

@@ -21,3 +21,15 @@ class Horizontal(Widget):
overflow: auto;
}
"""
class Center(Widget):
"""A container widget to align children in the center."""
CSS = """
Center {
layout: center;
overflow: auto;
}
"""