Fix content width (#1910)

* fix calculation for scrollbars

* added snapshot

* fix for name change

* snapshot

* fix for textual colors

* remove logs

* scrollbar logic

* scroll logic

* remove dead code

* snapshot tests

* scrollbar mechanism

* tidy

* demo tweak

* preset window size

* no need for repaint

* Restore repaint

* wait for idle on pause

* colors tweak

* remove wait for idle

* snapshot

* small sleep

* change stabilizer

* debug tweaks

* remove debug

* remove debug

* snapshot test

* docstring

* changelog

* add pause
This commit is contained in:
Will McGugan
2023-03-02 14:39:31 +00:00
committed by GitHub
parent 88a0349cb6
commit 41003e356c
16 changed files with 437 additions and 202 deletions

View File

@@ -0,0 +1,54 @@
from rich.text import Text
from textual.app import App, ComposeResult
from textual.containers import Vertical
from textual.widget import Widget
from textual.widgets import TextLog
class MyWidget(Widget):
def render(self):
return Text(
"\n".join(f"{n} 0123456789" for n in range(20)),
no_wrap=True,
overflow="hidden",
justify="left",
)
class ScrollViewApp(App):
CSS = """
Screen {
align: center middle;
}
TextLog {
width:13;
height:10;
}
Vertical{
width:13;
height: 10;
overflow: scroll;
overflow-x: auto;
}
MyWidget {
width:13;
height:auto;
}
"""
def compose(self) -> ComposeResult:
yield TextLog()
yield Vertical(MyWidget())
def on_ready(self) -> None:
self.query_one(TextLog).write("\n".join(f"{n} 0123456789" for n in range(20)))
self.query_one(Vertical).scroll_end(animate=False)
if __name__ == "__main__":
app = ScrollViewApp()
app.run()