Actionscript 3
I have been wrecking my head most today on the best way of going about this, but i end up over complicating what i would believe to be a simple task.
I have some TextFields lined up next to each other all fixed width, i.e ( [ width ])
tf1 tf2 tf3 tf4 tf5
[ 80 ][ 50 ][ 50 ][ 50 ][ 70 ]
What i want to do is be able to select which detail i want to show, and then redistribute the width of the removed TextField to the rest (note you can only remove from the right), so if i was to show up to “tf3”, 120 (70+50) would need to be evenly distributed to the other boxes:
[ 80 + 50 + 50 = 180 ]
tf1
[80/180*120 + 80 = 133.3]
tf2
[50/180*120 + 50 = 83.3]
tf3
[50/180*120 + 50 = 83.3]
Then line them up again (x + width etc):
[ 133.3 ][ 83.3 ][ 83.3 ]
Any ideas of a better method, i sure there is some nice easy functions i can use to do this.
I probably have overcomplicated the question too now, but ill give it a try, anyone have any ideas?
So, let me get this straight, you have N text fields of differing widths and you want to remove 1 or more of them, rearranging the remaining M text fields, redistributing their widths proportionally (i.e. so if text field T1 was twice the width of text field T2, it would still be after they are rearranged)?
This isn’t actually a very simple problem, but I’ve taken a stab at it below. You pass it the array of your text fields (from left to right), the number you want to keep, and an optional X-offset.
Note: I haven’t done AS3 in months so consider the below to be pseudocode–you will have to edit it to make it work.
Note: This code doesn’t actually remove the “unkept” text fields from view; you’ll have to add that or do it elsewhere.