added grid layout

This commit is contained in:
Will McGugan
2021-07-08 21:43:49 +01:00
parent 9c150152df
commit 111f596911
5 changed files with 202 additions and 4 deletions

36
examples/grid.py Normal file
View File

@@ -0,0 +1,36 @@
from textual.app import App
from textual import events
from textual.view import View
from textual.widgets import Placeholder
from textual.layouts.grid import GridLayout
class GridTest(App):
async def on_load(self, event: events.Load) -> None:
await self.bind("q,ctrl+c", "quit", "Quit")
async def on_startup(self, event: events.Startup) -> None:
layout = GridLayout()
view = await self.push_view(View(layout=layout))
layout.add_column(fraction=1, name="left", minimum_size=20)
layout.add_column(size=30, name="center")
layout.add_column(fraction=1, name="right")
layout.add_row(fraction=1, name="top")
layout.add_row(fraction=2, name="middle")
layout.add_row(fraction=1, name="bottom")
layout.add_area("area1", "left", "top")
layout.add_area("area2", "center", "middle")
layout.add_area("area3", ("left-start", "right-end"), "bottom")
layout.add_area("area4", "right", ("top-start", "middle-end"))
await view.mount(layout.add_widget(Placeholder(name="area1"), "area1"))
await view.mount(layout.add_widget(Placeholder(name="area2"), "area2"))
await view.mount(layout.add_widget(Placeholder(name="area3"), "area3"))
await view.mount(layout.add_widget(Placeholder(name="area4"), "area4"))
GridTest.run(title="Grid Test")