Text wrapping and button growth direction

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
FlipTopBin
Newbie
Posts: 15
Joined: Thu Apr 12, 2018 5:55 am
Contact:

Text wrapping and button growth direction

#1 Post by FlipTopBin »

I am messing around with choice button styles at the moment and have all my choices arranged in a nice horizontal line (hbox) now instead of the usual virtical list (vbox)

The problem I am having is that if the text for a particular choice wraps then its button grows both up and down to accomodate the text. What I would like is for it to grow up or down then I can position the choices bar correctly releative to the screen contants.

Is there any easy way to tell a choice button which direction to grow in?

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Text wrapping and button growth direction

#2 Post by Alex »

Check the code of your choice screen and instead of align set pos and anchor for your hbox.

FlipTopBin
Newbie
Posts: 15
Joined: Thu Apr 12, 2018 5:55 am
Contact:

Re: Text wrapping and button growth direction

#3 Post by FlipTopBin »

OK, looked at the docs and very confused by "anchor". Currently I have my screen defined as 2560x1440 and this for my choice box

Code: Select all

screen choice(items):
    style_prefix "choice"

    hbox:
        xalign 0.5
        yalign 0.9
        for i in items:
            textbutton i.caption action i.action
How would I alter this so it works the same except for the text growing down towards the bottom of the screen?

Sorry for being a bit thick

goldo
Regular
Posts: 127
Joined: Mon Jan 23, 2017 8:23 am
Contact:

Re: Text wrapping and button growth direction

#4 Post by goldo »

When you use 'align' or 'pos', it will not in fact target the whole widget: it will align one pixel and the rest will follow. Anchor set the coordinates of that pixel.

Let's say you are showing a simple picture: using 'xanchor 0.0 yanchor 0.0' will align the first pixel on the top left to the set coordinates, and the picture will be arranged to the right and down from there. Conversely, using 'xanchor 1.0 yanchor 1.0' will align the bottom right pixel and the picture will be displayed up and left from there. Using 'xanchor 0.5 yanchor 0.5' will center the picture on the aligned coordinates.

To make matters more confusing, I believe text within a textbutton also has its own anchor properties, which are accessed by using the 'text_' prefix.
So,

Code: Select all

textbutton text_xanchor 0.0 text_yanchor 0.0
will set the text anchor to the top left of the text.

TL/DR: Use 'text_yanchor 0.0' to make your text grow down within a textbutton.

FlipTopBin
Newbie
Posts: 15
Joined: Thu Apr 12, 2018 5:55 am
Contact:

[solved]Text wrapping and button growth direction

#5 Post by FlipTopBin »

Thanks for all the help guys. This worked for me:

Code: Select all

screen choice(items):
    style_prefix "choice"

    hbox:
        xalign 0.5
        yalign 0.9
        xanchor 0.5
        yanchor 0.0

        for i in items:
            textbutton i.caption action i.action

Post Reply

Who is online

Users browsing this forum: Bing [Bot]