-
Regarding the following script: from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import Label
class TestApp(App):
CSS = """
#left {
background: blue;
dock: left;
}
#right {
background: darkred;
dock: right;
}
"""
def compose(self) -> ComposeResult:
left = Label('Left', id='left')
right = Label('Right', id='right')
yield Horizontal(left, right)
app = TestApp()
app.run() When run, the above displays only the It seems I’m not understanding something about how Textual CSS and/or |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
I believe the default width of a If we leave from textual.app import App, ComposeResult
from textual.containers import Horizontal
from textual.widgets import Label
class LabelAuto( App[ None ] ):
CSS = """
Horizontal {
border: solid blue;
height: auto;
}
Label {
border: solid red;
}
.width {
width: auto;
}
.height {
height: auto;
}
.one-fr {
width: 1fr;
}
"""
def compose(self) -> ComposeResult:
yield Horizontal(
Label( "Raw Label" ),
Label( "Raw Label" ),
Label( "Raw Label" ),
Label( "Raw Label" ),
Label( "Raw Label" )
)
yield Horizontal(
Label( "width: auto;", classes="width" ),
Label( "height: auto;", classes="height" ),
Label( "width: auto; height: auto;", classes="width height" )
)
yield Horizontal( Label( "width: auto;", classes="width" ) )
yield Horizontal( Label( "height: auto;", classes="height" ) )
yield Horizontal( Label( "width: auto; height: auto;", classes="width height" ) )
yield Horizontal(
Label( "width: auto;", classes="width" ),
Label( "width: auto;", classes="width" ),
Label( "width: auto;", classes="width" )
)
yield Horizontal(
Label( "width: 1fr;", classes="one-fr" ),
Label( "width: 1fr;", classes="one-fr" )
)
yield Horizontal(
Label( "width: 1fr;", classes="one-fr" ),
Label( "width: 1fr;", classes="one-fr" ),
Label( "width: 1fr;", classes="one-fr" ),
Label( "width: 1fr;", classes="one-fr" ),
Label( "width: 1fr;", classes="one-fr" ),
Label( "width: 1fr;", classes="one-fr" )
)
if __name__ == "__main__":
LabelAuto().run() giving this: You'll notice that with the first couple of |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
You're quite right that I don't need
Perhaps dock has a specialised meaning in Textual, in which case fair enough, but here's how I understand docking to work in the more general sense. If you have a container window with some child windows, one of which is docked, then I'd expect (in general, not specifically with reference to Textual - hence I'm using the term "window" rather than "widget")
This behaviour is what I observe, for example, when I dock the F12 "Developer tools" pane of either Chrome or Firefox to the main browser window. However, from what you're saying, Textual doesn't follow this scheme for docking. Is that by design, then? |
Beta Was this translation helpful? Give feedback.
-
In my description, docking left shouldn't affect the width of the widget (only its height), but it seemed to, from the images I posted. But perhaps that's not due to the docking per se, but the default width of full-container-width for a widget rather than based on content ( Thanks for your patience, I'm new to Textual and still feeling my way around. |
Beta Was this translation helpful? Give feedback.
I believe the default width of a
Label
, in a horizontal anyway, is the width of the container. Before I give an example of what I'm seeing, I would also highlight that you're throwingdock
into the mix too, which complicates matters. You may want to glance over the docking guide again to make sure this is what you want to be using. My understanding is that when you dock something you pretty much move it into its own isolated style space (for want of a better term) -- size and so on will be style in a way that isn't relative to other widgets. I would imagine this would explain why you're finding that1fr
isn't doing what you'd expect; you have oneLabel
dockedleft
, one dockedright
, and a…