Page 1 of 1

Scale Edit Box Help

Posted: Fri Nov 14, 2014 2:17 am
by Perfect Human Interface
I'm trying to make an edit box scale to the width of the module it's in. To do so I simply took the modules width from the MGUI and brought it into the Ruby code block in the edit box (as "mWidth"). You can see how I've made simple changes in the Ruby code to adjust with that variable in two places. One is in drawing the background to the edit box ("def draw"), and one is in scaling the edit/text area ("def viewSize"). The former works fine, but the latter doesn't update as the top-most module is resized. If you resize, then open the Ruby code block and type something in there (like a space), it will update correctly. So what I need to know is how to make this update as the module is resized. Of course, I don't know Ruby very well.

Any help is appreciated!

Re: Scale Edit Box Help

Posted: Fri Nov 14, 2014 2:49 am
by TheOm
You have to output the new Area when mWidth changes.

Re: Scale Edit Box Help

Posted: Fri Nov 14, 2014 3:27 am
by Perfect Human Interface
Ah ok, I thought it might need to be wrapped into the event method but I wasn't sure how to. So the viewSize method is called in the event block.

Code: Select all

def event i,v
   viewSize(nil, nil, nil, getViewSize(0)[1]) if i == "mWidth"
   redraw 0
end


I didn't understand the arguments at first, but I've figured it out now. The array "a" is being defined without using x,y,or w, so you've just set those to nil. And getViewSize(0) returns an array of width, height of view on input 0, and you've taken just the height value from the array (index 1) as the h argument.

Never would have figured that out on my own. Thanks. :)