Is it possible to set yalign of a button as "yalign of frame + 1"?

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
zeroTheHero
Regular
Posts: 28
Joined: Mon May 07, 2018 10:49 am
Contact:

Is it possible to set yalign of a button as "yalign of frame + 1"?

#1 Post by zeroTheHero » Sat Oct 13, 2018 2:35 am

I'm having trouble getting a textbutton to appear inside a frame. Right now, it always appears at the top left of wherever the frame is shown, and no amount of padding/margins is helping me budge it's position (maybe I'm just doing it wrong?...). Since the frame appears in a viewport, finding it's yalignment all the time is a major pain, so something along the lines of "yalign 'yalign_frame + 1' would be a big help...

My code looks like this:

Code: Select all

screen choice:
    frame background "gui/button/choice_background.png":
        top_margin 150
        hbox:
            textbutton "%s"%(choice1) style "choicez" action NullAction()
style choicez has more padding, margins, etc
The background looks like a rectangle with it's sides bent outwards...
Thanks!

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

Re: Is it possible to set yalign of a button as "yalign of frame + 1"?

#2 Post by Alex » Sat Oct 13, 2018 3:55 am

That happened 'cause frame changes its size to fit the content - in your sample it's just one button.

If you'd use

Code: Select all

background Frame("gui/button/choice_background.png") 
you'd see it.


So, try to set the size of your frame equal to the size of the background image.

Code: Select all

screen frame_scr():
    frame:
        xysize(800,400)
        align(0.5,0.1)
        vbox:
            align (0.5,0.5)
            textbutton "Test 1" action [[]]
            textbutton "Test 2" action [[]]
            
            
label start:
    "..."
    show screen frame_scr
    "?"
https://www.renpy.org/doc/html/screens.html#frame
https://www.renpy.org/doc/html/displayables.html#Frame
https://www.renpy.org/doc/html/style_pr ... rty-xysize

zeroTheHero
Regular
Posts: 28
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: Is it possible to set yalign of a button as "yalign of frame + 1"?

#3 Post by zeroTheHero » Sat Oct 13, 2018 11:55 pm

Alex wrote:
Sat Oct 13, 2018 3:55 am
That happened 'cause frame changes its size to fit the content - in your sample it's just one button.

If you'd use

Code: Select all

background Frame("gui/button/choice_background.png") 
you'd see it.


So, try to set the size of your frame equal to the size of the background image.

Code: Select all

screen frame_scr():
    frame:
        xysize(800,400)
        align(0.5,0.1)
        vbox:
            align (0.5,0.5)
            textbutton "Test 1" action [[]]
            textbutton "Test 2" action [[]]
            
            
label start:
    "..."
    show screen frame_scr
    "?"
https://www.renpy.org/doc/html/screens.html#frame
https://www.renpy.org/doc/html/displayables.html#Frame
https://www.renpy.org/doc/html/style_pr ... rty-xysize
Hey, sorry I couldn't get back sooner, and thanks for the reply!
textbutton background Frame("gui/button/choice_background.png") is a good idea, but the problem is I have more than one textbutton, and I'd like to fit them in the same frame.
So, try to set the size of your frame equal to the size of the background image.
Hmm...but if I do that won't my entire screen just be the rectangle frame?

The actual problem is that I want to align a textbutton inside a frame without using hard numbers like yalign 0.5, cuz in my game the frame can appear anywhere on the screen.

Your help is appreciated!

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

Re: Is it possible to set yalign of a button as "yalign of frame + 1"?

#4 Post by Alex » Sun Oct 14, 2018 6:09 am

textbutton background Frame("gui/button/choice_background.png") is a good idea
Well, actualy the idea was to set background for the frame to see its actual size.
If you do so you'll se that all your buttons are located in the center of the frame.
Hmm...but if I do that won't my entire screen just be the rectangle frame?
You can show an image of any shape onscreen and place a rectangle frame (with no background) over it to make it look like your frame isn't rectangle... Or as you do now - make a background for the frame as an image, but set the apropriate size for the frame to stretch it for the size of that image. You see, frame is just a container for some content (images, buttons, etc.) that easyly can be located on screen, so you won't need to calculate positions for each piece of content.
The actual problem is that I want to align a textbutton inside a frame without using hard numbers like yalign 0.5, cuz in my game the frame can appear anywhere on the screen.
Yes, that depnds of where you apply yalign: you can set the position for the frame itself, or set the position for vbox contained all the buttons inside this frame. So this yalign 0.5 is not the positioning the button itself in the middle of the screen.

zeroTheHero
Regular
Posts: 28
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: Is it possible to set yalign of a button as "yalign of frame + 1"?

#5 Post by zeroTheHero » Sun Oct 14, 2018 9:52 am

make a background for the frame as an image, but set the apropriate size for the frame to stretch it for the size of that image
This is also a very good idea, is this how one would do it?

Code: Select all

screen choice:
        vbox:
            textbutton "ttxxt" action NullAction() background Frame("choice_background.png", 720, 275)
This doesn't seem to work; while I can see the textbutton, the frame has disappeared! (PS my image background is 720 X 275 pixels and my game resolution is 720 X 1280 pixels)
Yes, that depnds of where you apply yalign: you can set the position for the frame itself, or set the position for vbox contained all the buttons inside this frame. So this yalign 0.5 is not the positioning the button itself in the middle of the screen.
Ah, so if I understand correctly, the yalign 0.5 if put inside the vbox will put the vbox in the middle of the frame and not in the middle of the screen?

Code: Select all

screen choice:
    frame background "choice_background.png":
        vbox:
            yalign 0.5
            textbutton "ttxxt" action NullAction()
If so, this is exactly what I want, but it is not working! The textbutton still appears on the top left of the frame...

Thanks for your time, it's really appreciated. I feel like I learned something new today, and a bit more knowledge will have this problem sorted

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

Re: Is it possible to set yalign of a button as "yalign of frame + 1"?

#6 Post by Alex » Sun Oct 14, 2018 4:32 pm

zeroTheHero wrote:
Sun Oct 14, 2018 9:52 am
...
This doesn't seem to work; while I can see the textbutton, the frame has disappeared! (PS my image background is 720 X 275 pixels and my game resolution is 720 X 1280 pixels)

...
As uncle Mugen said "long story short", try this 2 samples:

Code: Select all

screen choice:
    frame background Frame("choice_background.png", 5, 5):
        align(0.1,0.1)
        vbox:
            yalign 0.5
            textbutton "ttxxt" action NullAction()
and

Code: Select all

screen choice:
    frame background "choice_background.png":
        xysize(720,275)
        align(0.1,0.1)
        vbox:
            yalign 0.5
            textbutton "ttxxt" action NullAction()
Also note that choice screen is already exists - https://www.renpy.org/doc/html/screen_s ... tml#choice

zeroTheHero
Regular
Posts: 28
Joined: Mon May 07, 2018 10:49 am
Contact:

Re: Is it possible to set yalign of a button as "yalign of frame + 1"?

#7 Post by zeroTheHero » Wed Oct 17, 2018 1:42 am

Alex wrote:
Sun Oct 14, 2018 4:32 pm
zeroTheHero wrote:
Sun Oct 14, 2018 9:52 am
...
This doesn't seem to work; while I can see the textbutton, the frame has disappeared! (PS my image background is 720 X 275 pixels and my game resolution is 720 X 1280 pixels)

...
As uncle Mugen said "long story short", try this 2 samples:

Code: Select all

screen choice:
    frame background Frame("choice_background.png", 5, 5):
        align(0.1,0.1)
        vbox:
            yalign 0.5
            textbutton "ttxxt" action NullAction()
and

Code: Select all

screen choice:
    frame background "choice_background.png":
        xysize(720,275)
        align(0.1,0.1)
        vbox:
            yalign 0.5
            textbutton "ttxxt" action NullAction()
Also note that choice screen is already exists - https://www.renpy.org/doc/html/screen_s ... tml#choice
Heyyy thanks a lot!!! I got my choice screen working, and it's all cuz of you! I tested both your code samples and they work...just not in my game XD. But then I combined both, and voila now it works!! Thanks a ton, without you idk if I could ever make my way through all the xy sizes and aligns and stuff XD So thanks again!

Post Reply

Who is online

Users browsing this forum: No registered users