How can I calculate the current size of a Screen frame?

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
SypherZent
Veteran
Posts: 331
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Soundcloud: Chrysopoeist
Location: Puerto Rico
Contact:

How can I calculate the current size of a Screen frame?

#1 Post by SypherZent » Sat Jan 04, 2020 12:04 am

I have a screens code, like this:

Code: Select all


screen New_screen():

    frame:
        background None
        align (0.5,0.5)
        xmaximum 300

        text "This is a long string of text confined to a small frame and I want to know the exact height of the resulting frame, given font and text size."

   # I want to retrieve the height of that frame on this line of code, and store it in a variable


How can I calculate the height of that frame? Is it possible to give it an ID and call it in the same screen somehow?

Thanks.

-SZ

strayerror
Regular
Posts: 154
Joined: Fri Jan 04, 2019 3:44 pm
Contact:

Re: How can I calculate the current size of a Screen frame?

#2 Post by strayerror » Sat Jan 04, 2020 6:52 am

Really depends what you need it for, and hope to do with it. I strongly advise against using this in anything outside of debugging and/or toy projects, but here is one possible way to get that information:

Code: Select all

label start:
    show screen New_screen()
    '[frame_size] var not available until next interaction'
    'frame size: [frame_size]'
    return

init python:
    def save_size(f):
        store.frame_size = f.window_size

screen New_screen():
    frame as myframe:
        background None
        align (0.5,0.5)
        xmaximum 300
        text "This is a long string of text confined to a small frame and I want to know the exact height of the resulting frame, given font and text size."

    timer .00001 action Function(save_size, myframe) # window_size isn't set until after render, so cheese it with a timer

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]