PDA

View Full Version : Help with horizontal auto-sizing of controls



darrenan
August 13th, 2018, 18:17
I want to have four stringcontrol's arranged on the same line, and have their width autosize to fill the available horizontal space when the containing windowinstance is resized. I tried messing around with the onSizeChanged event a little last night with no success. Can someone point me to some examples of something similar I can look at before I start asking dumb questions? Thanks.

Moon Wizard
August 13th, 2018, 20:10
There are not a lot of examples of this, since the logic is more complex. I tend to not implement multiple auto-sizing fields on a line, or use static widths and base off a center anchor (many examples of this in the built-in rulesets code).

The onSizeChanged event is the one that you would be using. Then, you would need to use window.getSize(); and set the individual field left/right anchors at the 0/25/50/75/100 marks as appropriate.

Regards,
JPG

darrenan
August 13th, 2018, 21:24
Ok, I was on the right track then, thanks.

darrenan
August 13th, 2018, 21:45
WindowControl.setStaticBounds is the appropriate function for this? I think I was trying to use one of the setAnchoredxxx functions, maybe that was my problem.

Moon Wizard
August 13th, 2018, 23:30
Using setStaticBounds is probably the easiest solution.

The other option (if you wanted to do more complex stuff, or had multiple lines doing the same thing) would be to create generic anchor controls whose position got set using setStaticBounds; then have the string fields use the horizontal anchor controls as anchor points.

Regards,
JPG