Increase height by amount using OnClick of another widget

advanced-prototyping

#1

I’ve been trying to resize the background of my prototype by a certain amount (e.g. "Set Size of pageBg to [[pageBg.height]] + 150px) on a button click and reduce the size on another button click. I want to do this by amount, not by specific height. Is there a way to do this?


#2

Do you mean by a variable amount - i.e. 150 the first time, 100 the 2nd time, etc? Or a user configurable amount? Or a percentage?


#3

Set size of widget to height: [[This.height + 150]], width: [[this.width]]

This will increase the height of the targeted widget by 150 and leave the width the same. On your other button do the same but subtract 150 instead.


#5

I mean having the button add 150 pixels to my background and another to remove that 150 pixels without defining the size because I have one other button that will need to do the same.


#6

Unfortunately, this only made the background the same width as the button and 150px taller than the button that triggered the event. My background is set as pageBg so I set the same formula to [[pageBg.width +150]] which produced no results.


#7

You can use [[target.height + 150]] to add 150 to whatever the current height is. If you want it to always add 150 to whatever the original height was, you could store the original height as a variable and then set the height to [[variable + 150]].

Same for target.width if you don’t want to change the width.


#8

In the future it helps if you can post your file or an example, otherwise it’s had to guess what the structure of your file is or what widget do what. This is especially important when you question revolves around specifically that.


#9

Sorry about that. I’ve been looking here long enough to know better. I’ve attached my attempt, but it’s still not working. Thank you for having patience with me. background height test.rp (49.5 KB)


#10

The only thing you’re missing is a local variable. You can’t directly reference widgets by name (as names are not unique). Instead, open the expression editor for the height and add a new local variable. Change the name of the local variable to pageBg (so you don’t have to change the expression) then set the local variable to point to the pageBg widget (pageBg = widget pageBg). Then it should work.

Alternatively you don’t even need a local variable in this case because the widget whose height you’re using is the same one whose height you’re changing, so you can use Target instead and no need to even create a local variable. See UXProtoTyper’s response above.


#11

Thank you both for your help. This worked exactly as I needed it to!


closed #12

unlisted #13