mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
added render measure
This commit is contained in:
18
docs.md
Normal file
18
docs.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Documentation Workflow
|
||||
|
||||
* Ensure you're inside a *Python 3.10+* virtual environment
|
||||
* Run the live-reload server using `mkdocs serve` from the project root
|
||||
* Create new pages by adding new directories and Markdown files inside `docs/*`
|
||||
|
||||
## Commands
|
||||
|
||||
- `mkdocs serve` - Start the live-reloading docs server.
|
||||
- `mkdocs build` - Build the documentation site.
|
||||
- `mkdocs -h` - Print help message and exit.
|
||||
|
||||
## Project layout
|
||||
|
||||
mkdocs.yml # The configuration file.
|
||||
docs/
|
||||
index.md # The documentation homepage.
|
||||
... # Other markdown pages, images and other files.
|
||||
32
sandbox/will/scrolly.py
Normal file
32
sandbox/will/scrolly.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from rich.text import Text
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Static
|
||||
|
||||
text = "\n".join("FOO BAR bazz etc sdfsdf " * 20 for n in range(1000))
|
||||
|
||||
|
||||
class Content(Static):
|
||||
DEFAULT_CSS = """
|
||||
Content {
|
||||
width: auto;
|
||||
}
|
||||
"""
|
||||
|
||||
def render(self):
|
||||
return Text(text, no_wrap=False)
|
||||
|
||||
|
||||
class ScrollApp(App):
|
||||
CSS = """
|
||||
Screen {
|
||||
overflow: auto;
|
||||
}
|
||||
"""
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Content()
|
||||
|
||||
|
||||
app = ScrollApp()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
19
src/textual/render.py
Normal file
19
src/textual/render.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from rich.console import Console, RenderableType
|
||||
|
||||
|
||||
def measure(console: Console, renderable: RenderableType, default: int) -> int:
|
||||
"""Measure a rich renderable.
|
||||
|
||||
Args:
|
||||
console (Console): A console object.
|
||||
renderable (RenderableType): Rich renderable.
|
||||
default (int): Default width to use if renderable does not expose dimensions.
|
||||
|
||||
Returns:
|
||||
int: Width in cells
|
||||
"""
|
||||
get_console_width = getattr(renderable, "__rich_measure__", None)
|
||||
if get_console_width is not None:
|
||||
render_width = get_console_width(console, console.options).normalize().maximum
|
||||
return max(0, render_width)
|
||||
return default
|
||||
Reference in New Issue
Block a user