Scandinavian Layout Issues #2085
-
Consider any Scandinavian flag with the left 1/3 composed of two vertical blocks and the right 2/3 composed of 1 large block. With context managers, you might do it this way: with Horizontal():
with Vertical():
yield Static("One", classes="left")
yield Static("Two", classes="left", id="two")
yield Static("Three", classes="right") The box labeled "Three" will not show up on the screen. However, if you yield box Three first, placing it instead on the left-hand side, it will show as advertised: with Horizontal():
yield Static("Three", classes="right")
with Vertical():
yield Static("One", classes="left")
yield Static("Two", classes="left", id="two") I believe that this will make the Swedes very unpleasant, but I cannot say for certain as I am not Scandinavian. I've included a complete example at the bottom. Maybe this is a limitation of the containers that I didn't see in the documentation?
Failing example: from textual.app import App, ComposeResult
from textual.containers import Horizontal, Vertical
from textual.widgets import Static
from textual.widgets import Header
my_css = """
Static {
content-align: center middle;
layout: horizontal;
}
.left {
background: blue;
height: 1fr;
width: 33%;
}
#two {
background: yellow;
}
.right {
background: white;
height: 1fr;
width: 66%;
}
"""
class SwedishFlag(App):
CSS_PATH = "test.css"
BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]
def compose(self) -> ComposeResult:
"Create the layout"
yield Header(show_clock=True)
with Horizontal():
yield Static("Three", classes="right")
with Vertical():
yield Static("One", classes="left")
yield Static("Two", classes="left", id="two")
if __name__ == "__main__":
app = SwedishFlag()
app.run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I'm slightly confused by this description as the flags you mention don't appear to match the layout you say you're going for (you seem to mention 3 blocks, but a cross would suggest 4 blocks), but I'm going to go with the layout description and assume 2 blocks to the left, stacked vertically, with one block to the right, with a 1/3 to 2/3 split. If I were to do that I'd probably start out like this: from textual.app import App, ComposeResult
from textual.containers import Horizontal, Vertical
from textual.widgets import Header, Footer, Static
class ExampleLayout( App[ None ] ):
CSS = """
Static {
border: round white;
height: 1fr;
width: 1fr;
}
#left {
width: 1fr;
}
#right {
width: 2fr;
}
"""
def compose( self ) -> ComposeResult:
yield Header()
with Horizontal():
with Vertical( id="left" ):
yield Static( "Top Left" )
yield Static( "Bottom Left" )
yield Static( "Right", id="right" )
yield Footer()
if __name__ == "__main__":
ExampleLayout().run() |
Beta Was this translation helpful? Give feedback.
I'm slightly confused by this description as the flags you mention don't appear to match the layout you say you're going for (you seem to mention 3 blocks, but a cross would suggest 4 blocks), but I'm going to go with the layout description and assume 2 blocks to the left, stacked vertically, with one block to the right, with a 1/3 to 2/3 split.
If I were to do that I'd probably start out like this: