This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Added test code for Textualize/textual#1897
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""https://github.com/Textualize/textual/issues/1897""" | ||
|
||
from rich.segment import Segment | ||
from textual.app import App, ComposeResult | ||
from textual.widgets import Header, Footer | ||
from textual.scroll_view import ScrollView | ||
from textual.geometry import Size | ||
from textual.strip import Strip | ||
|
||
class ScrollViewTest( ScrollView, can_focus=True ): | ||
|
||
def __init__( self, height: int ) -> None: | ||
super().__init__() | ||
self.virtual_size = Size( 0, height ) | ||
|
||
def render_line( self, y: int ) -> Strip: | ||
return Strip( [ | ||
Segment( f"{self.scroll_offset.y + y:10}" ), | ||
Segment( f"{y:10}" ), | ||
*( | ||
[ Segment( f"{' ' * 10}scroll_offset.y == {self.scroll_offset.y}") ] | ||
if y == 0 else [] | ||
) | ||
] ) | ||
|
||
class ScrollTestApp( App[ None ] ): | ||
|
||
def compose( self ) -> ComposeResult: | ||
yield Header() | ||
yield ScrollViewTest( 1000 ) | ||
yield Footer() | ||
|
||
def on_mount( self ) -> None: | ||
self.query_one( ScrollViewTest ).focus() | ||
|
||
if __name__ == "__main__": | ||
ScrollTestApp().run() | ||
|
||
### scroll_api_test.py ends here |