How to make all items in vbox to have same xsize?

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
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

How to make all items in vbox to have same xsize?

#1 Post by Ocelot » Tue Aug 23, 2016 11:16 am

I have a vbox, which has a vpgrid. That grid manages own width just fine and I do not want to set it explicitely. After it I have viewport which uses another screen, containing ton of text, so, if I do not set width explicitely, it will atempt to fill rest of the screen.

I want second viewport to have the same width as first one. I could find exact width by trial and error, but I expect size of first vpgrid to change during development and maybe even ingame, so hardcoding width(s) is not something I want to do.

So, is there any way to get width of previous item or solve this problem in some other way?

Fragment of screen code (with almost-correct width set manually):

Code: Select all

vbox:
    spacing 8
    vpgrid:    
        ysize 500
        cols 4
        spacing 4
        mousewheel True
        scrollbars "vertical"
        for item in items:
            textbutton "{size=14}Button{/size}":
                xysize (96, 96) 
                action Return()
        
    viewport:
        mousewheel True
        scrollbars "vertical"
        xsize 400
        use item_info

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How to make all items in vbox to have same xsize?

#2 Post by kivik » Tue Aug 23, 2016 6:00 pm

Not sure if it's the right answer for precise sizing, but I find that "xfill True" seem to do the job for me.

User avatar
Kia
Eileen-Class Veteran
Posts: 1011
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: How to make all items in vbox to have same xsize?

#3 Post by Kia » Wed Aug 24, 2016 10:36 am

try: size_group
it is used in main menu and preferences if you want to see how it works

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 make all items in vbox to have same xsize?

#4 Post by Ocelot » Wed Aug 24, 2016 11:58 am

Sadly size_group didn't work for me: it seems to expand all widgets width to the width of largest one. I have opposite problem: "text" displayable tries to use as much width as possible before starting to wrap words to the next line. I want to limit it to the width of vpgrid defined before.

User avatar
Kia
Eileen-Class Veteran
Posts: 1011
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: How to make all items in vbox to have same xsize?

#5 Post by Kia » Wed Aug 24, 2016 12:02 pm

have you tried to put them in a frame and give the frame it's size a percentage of the screen? xsize 0.45

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 make all items in vbox to have same xsize?

#6 Post by Ocelot » Wed Aug 24, 2016 12:37 pm

I might not understood your proposal, but the problem is finding exact size. As I said, vpgrid width will change, and I do not want to hardcode sizes. For now I set second viewport size manually by inspecting vpgrid in Displayable Inspector and looking at its size, but I want more robust solution.

I found renpy.get_widget_properties function, which seems to be useful for me, but didn't find any examples on its usage.

Post Reply

Who is online

Users browsing this forum: No registered users