mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
28
sandbox/will/center.py
Normal file
28
sandbox/will/center.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from textual.app import App
|
||||
from textual.widgets import Static
|
||||
|
||||
|
||||
class CenterApp(App):
|
||||
CSS = """
|
||||
|
||||
Screen {
|
||||
layout: center;
|
||||
overflow: auto auto;
|
||||
}
|
||||
|
||||
Static {
|
||||
border: wide $primary;
|
||||
background: $panel;
|
||||
width: 50;
|
||||
height: 20;
|
||||
margin: 1 2;
|
||||
content-align: center middle;
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
def compose(self):
|
||||
yield Static("Hello World!")
|
||||
|
||||
|
||||
app = CenterApp()
|
||||
55
sandbox/will/center2.py
Normal file
55
sandbox/will/center2.py
Normal file
@@ -0,0 +1,55 @@
|
||||
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;
|
||||
}
|
||||
|
||||
#sidebar.hidden {
|
||||
width: 0;
|
||||
}
|
||||
|
||||
Static {
|
||||
background: $panel;
|
||||
color: $text-panel;
|
||||
content-align: center middle;
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
def on_mount(self) -> None:
|
||||
self.bind("t", "toggle_class('#sidebar', 'hidden')")
|
||||
|
||||
def compose(self):
|
||||
yield Static("Sidebar", id="sidebar")
|
||||
yield Vertical(
|
||||
Static("Bottom bar", id="bottombar"),
|
||||
Center(
|
||||
Static("Hello World!", id="hello"),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
app = CenterApp(log_verbosity=3)
|
||||
Reference in New Issue
Block a user