-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistview_scrolls_to_focus.py
More file actions
40 lines (30 loc) · 1.03 KB
/
listview_scrolls_to_focus.py
File metadata and controls
40 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from textual.app import App, ComposeResult
from textual.widgets import ListItem, ListView, Static
class ListViewScrollApp(App[None]):
BINDINGS = [("h", "scroll()", "Home")]
CSS = """
#banner {
text-align: center;
text-style: bold;
padding: 1 2;
}
ListView {
height: auto;
}
ListItem {
padding: 1 2;
}
"""
def compose(self) -> ComposeResult:
yield Static("ACME Scrolling Test!", id="banner")
items = [ListItem(Static(f"Item {i}")) for i in range(1, 21)]
yield ListView(*items)
def on_mount(self) -> None:
self.screen.scroll_to_widget(self.query_one("#banner"))
def action_scroll(self) -> None:
# self.screen.scroll_home()
self.screen.scroll_to_widget(self.query_one("#banner"))
def on_list_view_highlighted(self, event: ListView.Highlighted) -> None:
self.screen.scroll_to_widget(event.item)
if __name__ == "__main__":
ListViewScrollApp().run()