prompt-toolkit: aligning children of a VSplit

213 Views Asked by At

How can I align these elements?

header = VSplit(                                                            
    children=[                                                              
        Label("LEFT ", 
              dont_extend_width=True),             
        Label("  CENTER  ",
              dont_extend_width=True),
        Label(" RIGHT RIGHT RIGHT RIGHT",
              dont_extend_width=True),
    ],
    padding=Dimension(weight=99),                                                   
    padding_char="-",                                                       
    align="CENTER",                                                         
)

enter image description here

CENTER is centered between LEFT and RIGHT, not centered on the container. And RIGHT is only on the right edge because of padding. If I remove the padding everything left-aligns with no gap.

There is probably something basic I'm missing here but I've been stalled on this for hours.

1

There are 1 best solutions below

0
On

I found I could resolve this using FloatContainer with CENTER as its background element, and LEFT and RIGHT as Floats:

header = FloatContainer(
    content=Window(
        FormattedTextControl("  CENTER  "),
        align=WindowAlign.CENTER,
        height=1,
        char="-",
    ),
    floats=[
        Float(Label("LEFT "), left=0),
        Float(Label(" RIGHT RIGHT RIGHT RIGHT"), right=0),
    ],
)

Center is centered