How to center text in a textbutton [Solved]

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
User avatar
oatnoodles
Regular
Posts: 47
Joined: Tue Aug 03, 2021 6:26 pm
Projects: Samuda Interval
Organization: Tomuwa Entertainment
Deviantart: oatnoodles
Github: oatnoodles
itch: oatnoodles
Discord: oatnoodles#0099
Contact:

How to center text in a textbutton [Solved]

#1 Post by oatnoodles » Sat Jan 08, 2022 7:00 pm

I'm replacing some of my imagebuttons with text buttons. However, I can't figure out how to get the TEXT in the textbutton centered. The button itself is placed where I want it, but it's left-aligned and I want it centered. xalign 0.5 doesn't work anywhere I've tried putting it.

Here's my code:

Code: Select all

vbox:
        spacing 24
        ypos 309

        #Inventory: (703, 309, 513, 88)
        textbutton "Inventory":
            xpos 703
            xminimum 513
            text_color "#414141"
            text_hover_color "#D1CCC9"
            action ShowMenu("inventory"), With(Dissolve(0.5))
Last edited by oatnoodles on Tue Jan 11, 2022 8:36 pm, edited 2 times in total.
Ren'py amateur looking to learn as much as possible! Please be patient with me.

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How to center text in a textbutton

#2 Post by Ocelot » Sat Jan 08, 2022 7:18 pm

Style property controlling text placement within displayable is called text_align. I am not sure if it will work as is, or you will have to prepend text_ to it. Try both.
< < insert Rick Cook quote here > >

User avatar
oatnoodles
Regular
Posts: 47
Joined: Tue Aug 03, 2021 6:26 pm
Projects: Samuda Interval
Organization: Tomuwa Entertainment
Deviantart: oatnoodles
Github: oatnoodles
itch: oatnoodles
Discord: oatnoodles#0099
Contact:

Re: How to center text in a textbutton

#3 Post by oatnoodles » Sat Jan 08, 2022 7:58 pm

I tried adding both text_align 0.5 and align 0.5... text_align 0.5 does absolutely nothing, and align 0.5 gets an error.

Code:

Code: Select all

vbox:
        spacing 20
        ypos 309

        #Inventory: (703, 309, 513, 88)
        textbutton "Inventory":
            xpos 703
            xminimum 513
            text_color "#414141"
            text_align 0.5
            text_hover_color "#D1CCC9"
            action ShowMenu("inventory"), With(Dissolve(0.5))
Ren'py amateur looking to learn as much as possible! Please be patient with me.

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How to center text in a textbutton

#4 Post by Ocelot » Sat Jan 08, 2022 8:16 pm

As I suspected, you need to prepend text_ to it.
And you need to set minimum width for text displayable, because it tries to teke up as little space as possible:

Code: Select all

    textbutton "Inventory":
        text_min_width 513
        text_text_align 0.5
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: No registered users