Page 1 of 1

How to center text?

Posted: Sat May 09, 2020 7:40 am
by lykoia
Hey all, newbie here.
I wanted to center text in the about section but I don't know how. I tried to do:

Code: Select all

screen about():
    tag menu
    use game_menu(_("About"), scroll="viewport"):
        style_prefix "about"
        vbox:
            label "[config.name!t] v.[config.version!t]\n" xalign 0.5
            if gui.about:
                text "[gui.about!t]\n" xalign 0.5
            text _("Made with {a=https://www.renpy.org/}Ren'Py{/a} [renpy.version_only].\n\n[renpy.license!t]") xalign 0.5
I also tried replacing the 'xalign 0.5' with 'at truecenter' or just' center' but that didn't work either. It showed up at the right side of the screen.
I also want to center the text overall
like here
but I couldn't find any solution.
Is there even a way to center text in the about section? I'm pretty sure there is I just don't know how.

Thank you

Re: How to center text?

Posted: Sat May 09, 2020 7:51 am
by xavimat
xalign is always relative to the container.
Here you have label and text inside a vbox. So your xalign 0.5 probably is working Ok: centering the elements inside the vbox. The vbox is not centered in its container. What is the vbox container? The vbox is inside another screen (see the "use"). So you need to go to the game_menu screen and see what container is the vbox in, and maybe what container is that container in... And so on.

Re: How to center text?

Posted: Sat May 09, 2020 8:08 am
by drKlauz
As xavimat said, but basically just add xalign 0.5 to vbox itself.

Re: How to center text?

Posted: Sat May 09, 2020 10:09 am
by lykoia
It's not working, where am I supposed to add xalign 0.5?

Re: How to center text?

Posted: Sat May 09, 2020 12:29 pm
by drKlauz

Code: Select all

vbox:
  xalign 0.5
  label "[config.name!t] v.[config.version!t]\n" xalign 0.5
  #etc...
Hm, ok, i was bit rushy, this code will work if external container take up screen area (either fixed or have xfill True) and not just big enough to contain this vbox.

Re: How to center text?

Posted: Sat May 09, 2020 3:21 pm
by lykoia
drKlauz wrote: Sat May 09, 2020 12:29 pm

Code: Select all

vbox:
  xalign 0.5
  label "[config.name!t] v.[config.version!t]\n" xalign 0.5
  #etc...
Hm, ok, i was bit rushy, this code will work if external container take up screen area (either fixed or have xfill True) and not just big enough to contain this vbox.
Is there also a way to center text
like this?

Re: How to center text?

Posted: Sat May 09, 2020 3:48 pm
by drKlauz
I'm not sure if i understand your question, but generally it is done like this:

Code: Select all

vbox:
  xfill True ## make vbox take all available horizontal space
  text "left"
  text "center" xalign 0.5 ## can be other value, not just in 0.0-1.0 range
  text "right" xalign 1.0
Also if you have large text and want to center every line of this text it is:

Code: Select all

  text "some long text ... some long text" xalign 1.0 text_align 0.5 ## text_align will align every line, can be different from xalign
Obligatory doc link: https://www.renpy.org/dev-doc/html/screens.html