Intermediate Horizontal
container breaks scrolling
#2697
-
This is best explained with an example. The following app works well: from textual.app import App, ComposeResult
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Label
class Scroller(App):
def compose(self) -> ComposeResult:
with VerticalScroll():
for i in range(100):
yield Label(str(i))
Scroller().run() Note the scrollbar and the correct order of the numbers: ![]() However, as soon as I put each label into a from textual.app import App, ComposeResult
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Label
class Scroller(App):
def compose(self) -> ComposeResult:
with VerticalScroll():
for i in range(100):
with Horizontal():
yield Label(str(i))
Scroller().run() ![]() Not only is the scrollbar entirely gone, but it seems to have randomly re-arranged the elements of the vertical layout! Textual DiagnosticsVersions
Python
Operating System
Terminal
Rich Console options
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
By default the height of a To get what you want with the code you have, you'd want to be telling from textual.app import App, ComposeResult
from textual.containers import Horizontal, VerticalScroll
from textual.widgets import Label
class Scroller(App):
CSS = """
Horizontal {
height: auto;
}
"""
def compose(self) -> ComposeResult:
with VerticalScroll():
for i in range(100):
with Horizontal():
yield Label(str(i))
Scroller().run() |
Beta Was this translation helpful? Give feedback.
By default the height of a
Horizontal
is1fr
. This means that all of theHorizontal
s that you yield are going to try and share out the same space as equally as possible. A way to view it is: if your terminal is 50 lines in height, those 100Horizontal
s are going to try and equally share the space, and they can't be 0.5 characters in height, so some will be 1 in height and some 0 in height. This is why you're seeing some missing (they're 0 in height) and there's no scrolling (they're all trying to stay within the vertical space of their container).To get what you want with the code you have, you'd want to be telling
Horizontal
to be a different height. A good choice might beauto
, which m…