Sizing image automatically

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
RewindTheGame
Regular
Posts: 54
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Sizing image automatically

#1 Post by RewindTheGame »

I'm trying to display a background image in my say window which would automatically size to the width of the text - or if that's not possible, I'd be happy to specify the width of the image every time. The image is just a simple one pixel border to go around the text, so by resizing the width I'd avoid having a massive gap between the right of the text and the right hand border of the image. What I want is something like:

add "gui/saybackground.png" width=150

Any ideas? It seems fairly reasonable to want a border that precisely surrounds the text.

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

Re: Sizing image automatically

#2 Post by Ocelot »

add a frame around what text in say screen and assign Borders with your image to it. Frames resize to fit child automatically.
< < insert Rick Cook quote here > >

RewindTheGame
Regular
Posts: 54
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: Sizing image automatically

#3 Post by RewindTheGame »

Ooh, didn't know that. Thanks :)

RewindTheGame
Regular
Posts: 54
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: Sizing image automatically

#4 Post by RewindTheGame »

Could you please give me an example of how to do this, as I can't read the RenPy documentation to save my life. None of it resembles anything close to English.

Suppose I have an image called "gui/textbox2.png" which I want to display on the say screen with the "what" text inside it and the image stretched/shrunk to fit exactly around the text. What code would I actually add to do that? Borders appears to be a function, which throws me completely. I thought it would be as simple as:

if who!="Nobox":
text what id "what"
else:
frame:
add "gui/textbox2.png"
ypos 100
xpos 100
text what id "what"

but that doesn't work.Also, how do I display these examples as code - there's no button in the editor for that...

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

Re: Sizing image automatically

#5 Post by Ocelot »

Here is the say screen I used:

Code: Select all

screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if who is not None:
            window:
                id "namebox"
                style "namebox"
                text who id "who"

        frame:
            xpos gui.dialogue_xpos
            ypos gui.dialogue_ypos
            background Frame("gui/im_border.png", Borders(10, 10, 10, 10))
            padding (7, 7)
            text what id "what" pos (0, 0)
Here is the image I used:
Image

Here how is it looks:
Image
Image
RewindTheGame wrote: Thu Jul 29, 2021 2:09 pm how do I display these examples as code - there's no button in the editor for that...
Image
< < insert Rick Cook quote here > >

RewindTheGame
Regular
Posts: 54
Joined: Thu Dec 31, 2020 3:37 pm
Contact:

Re: Sizing image automatically

#6 Post by RewindTheGame »

This works perfectly, thank you so much.

Post Reply

Who is online

Users browsing this forum: No registered users