Regardless... if you add xfill True
to your vbox:
, that will sort it. I just wish I could explain why it does.
Because without it the
vbox implicitly created by
has vbox
have no size, and so have the size of what it contain.
Let's say that the
text is 100 pixels wide, then the
vbox will also be 100 pixels wide. And since the text take all the available space, it is centered... and also at the far left, as well as at the far right.
But when you add
xfill True
you give a size to the implicit
vbox. Precisely you ask it to be as wide as its container permit it, so here the width of the
frame, 500 pixels. And now that the
vbox is bigger than the
text, it's possible to perform some alignment.
Personally, I'd try to ditch the has vbox
line completely, but mainly only because I don't really understand what else it is doing.
It just tell that the
frame will act as a
vbox. It create a
vbox element but, as said above, it's an implicit one and people rarely give them properties ; why using something implicit when you want to treat it as something explicit ?
Therefore, something like your solution should be wrote :
Code:
screen pbr_test:
frame:
xsize 500
ysize 400
xalign 0.5
yalign 0.1
vbox:
spacing 2
xfill True
text "BATTLE REPORT":
xalign 0.5
Not that it effectively change something, but by making the /vbox/ explicit, it ease the understanding of the screen structure and, possibly, make it more easy to spot the problems.
This said, the elegant solution should be :
Python:
screen pbr_test:
frame:
# No size specified, let the content decide of this.
# The frame is aligned on the screen.
xalign 0.5
yalign 0.1
vbox:
# The /vbox/ is given the size of the /frame/, since it's where the
# The content will effectively be put.
# Like a container can NOT be smaller than what it contain, it will
# also become the width of the /frame/.
xsize 500
# Same for the height.
ysize 400
# Now the text will be aligned on a 500 pixels wide /vbox/,
# instead of being aligned on a /vbox/ that is of the exact size
# of the text.
text "BATTLE REPORT\n":
xalign 0.5
You should apply the style properties where they matter.
The only thing that matter for the frame is its position, so only align it. And the only thing that matter for the vbox is its size, since it's what will permit to align its content, so give the size to it ; this instead of reporting this size like your
xfill True
solution do.