This commit is contained in:
Will McGugan
2021-07-18 10:31:00 +01:00
parent 4cb9fe1b01
commit f737252911
13 changed files with 154 additions and 99 deletions

View File

@@ -1,7 +1,6 @@
from textual import events
from textual.app import App
from textual.reactive import Reactive
from textual.views import DockView
from textual.widgets import Footer, Placeholder
@@ -9,33 +8,29 @@ class SmoothApp(App):
"""Demonstrates smooth animation"""
async def on_load(self, event: events.Load) -> None:
await self.bind("q,ctrl+c", "quit")
await self.bind("x", "bang")
await self.bind("b", "toggle_sidebar")
"""Bing keys here."""
await self.bind("b", "toggle_sidebar", "Toggle sidebar")
await self.bind("q", "quit", "Quit")
show_bar: Reactive[bool] = Reactive(False)
async def watch_show_bar(self, show_bar: bool) -> None:
"""Called when show_bar changes."""
self.animator.animate(self.bar, "layout_offset_x", 0 if show_bar else -40)
async def action_toggle_sidebar(self) -> None:
"""Called when user hits b key."""
self.show_bar = not self.show_bar
async def on_startup(self, event: events.Startup) -> None:
view = await self.push_view(DockView())
"""Build layout here."""
footer = Footer()
self.bar = Placeholder(name="left")
self.bar.layout_offset_x = -40
footer.add_key("b", "Toggle sidebar")
footer.add_key("q", "Quit")
await view.dock(footer, edge="bottom")
await view.dock(self.bar, edge="left", size=40, z=1)
await view.dock(Placeholder(), Placeholder(), edge="top")
await self.view.dock(footer, edge="bottom")
await self.view.dock(self.bar, edge="left", size=40, z=1)
await self.view.dock(Placeholder(), Placeholder(), edge="top")
SmoothApp.run()