mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
* log * tests * snapshot tests * change to richlog * keep raw lines * disable highlighting by default * simplify * superfluous test * optimization * update cell length * add refresh * write method * version bump * doc fix link * makes lines private * docstring * relax dev dependancy * remove superfluous code [skip ci] * added FAQ [skipci] * fix code in faq [skipci] * fix typo * max lines fix
55 lines
1.1 KiB
Python
55 lines
1.1 KiB
Python
from rich.text import Text
|
|
|
|
from textual.app import App, ComposeResult
|
|
from textual.containers import VerticalScroll
|
|
from textual.widget import Widget
|
|
from textual.widgets import RichLog
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
RichLog {
|
|
width:13;
|
|
height:10;
|
|
}
|
|
|
|
VerticalScroll {
|
|
width:13;
|
|
height: 10;
|
|
overflow: scroll;
|
|
overflow-x: auto;
|
|
}
|
|
|
|
MyWidget {
|
|
width:13;
|
|
height:auto;
|
|
}
|
|
"""
|
|
|
|
def compose(self) -> ComposeResult:
|
|
yield RichLog()
|
|
yield VerticalScroll(MyWidget())
|
|
|
|
def on_ready(self) -> None:
|
|
self.query_one(RichLog).write("\n".join(f"{n} 0123456789" for n in range(20)))
|
|
self.query_one(VerticalScroll).scroll_end(animate=False)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = ScrollViewApp()
|
|
app.run()
|