How to center text?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
lykoia
Newbie
Posts: 22
Joined: Tue Apr 14, 2020 11:15 am
Contact:

How to center text?

#1 Post 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

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: How to center text?

#2 Post 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.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: How to center text?

#3 Post by drKlauz »

As xavimat said, but basically just add xalign 0.5 to vbox itself.
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

lykoia
Newbie
Posts: 22
Joined: Tue Apr 14, 2020 11:15 am
Contact:

Re: How to center text?

#4 Post by lykoia »

It's not working, where am I supposed to add xalign 0.5?

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: How to center text?

#5 Post 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.
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

lykoia
Newbie
Posts: 22
Joined: Tue Apr 14, 2020 11:15 am
Contact:

Re: How to center text?

#6 Post 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?

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: How to center text?

#7 Post 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
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

Post Reply

Who is online

Users browsing this forum: Bing [Bot], henne