[SOLVED] Expanding an object in an hbox without moving other items

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
Tess
Newbie
Posts: 23
Joined: Thu Aug 04, 2022 3:43 pm
Projects: The Songbird Guild
Organization: Yurisoft
Github: wainwt2
Discord: Tess#7782
Contact:

[SOLVED] Expanding an object in an hbox without moving other items

#1 Post by Tess » Sat Oct 15, 2022 4:49 pm

I have a series of buttons I'd like to put in an hbox and right now the transform they're all connected to sets their zoom based on whether they're idle, hovered, or selected. Simplified example:

Code: Select all

transform expand_button(member):
	fit "contain"
	on idle:
		Overshoot 0.25 zoom 1.0
	on hover:
        	Overshoot 0.25 zoom 1.1
    	on selected_idle,selected_hover:
        	Overshoot 0.25 zoom 1.35

screen party():
	hbox:
		align (0.5,1.0)
		spacing 20
		for member in current_party:
			imagebutton:
				auto member.portrait
				ysize 0.2
				xsize 1.0/(len(current_party)+1)
				at expand_button(member)
However, when the zoom increases, it pushes the other buttons away to preserve the spacing. Is there a way to prevent this from happening?
Last edited by Tess on Tue Oct 18, 2022 10:41 am, edited 1 time in total.

User avatar
_ticlock_
Veteran
Posts: 391
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: Expanding an object in an hbox without moving other items

#2 Post by _ticlock_ » Mon Oct 17, 2022 1:01 am

Tess wrote:
Sat Oct 15, 2022 4:49 pm
However, when the zoom increases, it pushes the other buttons away to preserve the spacing. Is there a way to prevent this from happening?
1) If the buttons don’t need to be overlapped when zooming to max zoom value you can simply put the buttons inside fixed and specify appropriate xsize for the fixed and xalign for the buttons:

Code: Select all

transform expand_button():
    on idle:
	zoom 1.0
    on hover:
        zoom 1.1
    on selected_idle,selected_hover:
        zoom 1.35

screen party():
    hbox:
	spacing 20
	    for member in current_party:
                fixed:
                    xsize 200     # This should be at least xsize of button with max zoom
		    imagebutton:
		        auto member.portrait
			xalign 0.5 yalign 0.5
			at expand_button()
Maybe also specify ysize for the fixed.

2) If buttons need to be overlapped when zooming, hbox cannot be used, since it distributes its children based on their size and properties of hbox. In this case, I suggest directly specify xcenter of each button:

Code: Select all

screen party():
    for i, member in enumerate(current_party):
        imagebutton:
            auto member.portrait
	    xcenter (i+0.5)*200
	    at expand_button()

User avatar
Tess
Newbie
Posts: 23
Joined: Thu Aug 04, 2022 3:43 pm
Projects: The Songbird Guild
Organization: Yurisoft
Github: wainwt2
Discord: Tess#7782
Contact:

Re: Expanding an object in an hbox without moving other items

#3 Post by Tess » Tue Oct 18, 2022 10:40 am

That's such a genius idea! Thank you so much!!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Dark12ose, Majestic-12 [Bot]