add image inside scalable buttons (and windows)

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.
Message
Author
User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: add image inside scalable buttons (and windows)

#16 Post by Kia »

I know how to do that, one of first things I learned ^_^. but I'm after something like watermark in the middle or rather the solution to give me freedom to do more things like that.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: add image inside scalable buttons (and windows)

#17 Post by trooper6 »

I've done more experimentation and not come up with anything yet...so I put up a query in the Development thread.
I'm currently convinced the key lies in the layout.py file and adjusting fit_first
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
orz
Regular
Posts: 126
Joined: Tue Apr 21, 2015 10:19 pm
Contact:

Re: add image inside scalable buttons (and windows)

#18 Post by orz »

I was trying to work on this today myself. I got to about the same point trooper6 got, in that the image needs to go on bottom, but fit_first will be based on the first child which needs to be text.

(a side-note to trooper6, for some reason I didn't think button: accepted a fixed: as a child explicitly until now. Silly me.)

A CDD may fix it but that's a lot of effort. Another thought off the top of my head is to take whatever text string, turn it into a displayable, grab the width/height from that, and use that variable to plug into a fixed or a LiveComposite, so you can then put the image first and *then* the text.

I do recall renpytom mentioning that a "global" zorder system is in consideration (and that would easily fix stuff like this), but it'd take a revamping of the layers system that renpy has currently.

For what it's worth, this is what I had:

Code: Select all

button:
    action action
    style "menu_choice_button"
    fixed:
        fit_first True    
        text caption style "menu_choice"
        add ("w1.png") xalign 0.5 yalign 0.5

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: add image inside scalable buttons (and windows)

#19 Post by trooper6 »

Orz, I had your idea, too. I couldn't get it to work right. I think the easiest thing would be if we could get a new property in the layout.py that sets the fixed's xymaximum based on the maximum width and height of all the elements in the fixed. this way you can still have the image listed first and therefore rendered behind the text.

I don't think it would be too hard...but I've never messed with those files before...it makes me nervous.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: add image inside scalable buttons (and windows)

#20 Post by PyTom »

Note that for choice buttons it's almost always the case that you want to include the image as either the background or the foreground of the button itself, and just add some left_padding to move the text to the right of the image. The alternative - using an hbox - is often more complicated, and has to be repeated with each button.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: add image inside scalable buttons (and windows)

#21 Post by trooper6 »

PyTom wrote:Note that for choice buttons it's almost always the case that you want to include the image as either the background or the foreground of the button itself, and just add some left_padding to move the text to the right of the image. The alternative - using an hbox - is often more complicated, and has to be repeated with each button.
I tried putting the image in the background, and the only problem I ran into was that this approach involves hand coding the padding for each button through a lot of trial and error and Kia wanted to have buttons with variable length texts...which doesn't seem efficient the background image way. If the dimensions of the fixed could be set to the longest height/width of all the elements in the fixed, then an align of 0.5, 0.5 gets everything centered regardless of how long the text displayable is.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

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

Re: add image inside scalable buttons (and windows)

#22 Post by Kia »

foreground ^_^ I learned another sweet trick that may come handy somewhere and I need to read documentation thoroughly.
now another bonus question: is it possible to make frames scale only in one direction? for example

Code: Select all

background Frame("ui/w0.png", 60, None)
or

Code: Select all

background Frame("ui/w0.png", 60, 0) ysize = 50

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: add image inside scalable buttons (and windows)

#23 Post by PyTom »

Close. If you do:

Code: Select all

background Frame("ui/w0.png", 60, 0, ysize=50) 
you should get a fixed height frame.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

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

Re: add image inside scalable buttons (and windows)

#24 Post by Kia »

thanks Tom, Those properties where always tricky with me, whenever I try to add them it's always in the wrong place and wrong format >_< but I'm getting used to it.
I guess this topic reached it's expiration date, I learned some neat tricks and this little handicap is known and can be fixed in future. thanks for help everybody.

Post Reply

Who is online

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