Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
✨ Added test code for Textualize/textual#1897
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Feb 28, 2023
1 parent 1e8eaa0 commit f0869f2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions scroll_api_test.py
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

0 comments on commit f0869f2

Please sign in to comment.