Resizing forms. How do you like to handle resizing issues?
I like the function, AutoResize from APL2000 that uses the user defined property, {delta}where to define the location and size of a control. It takes a little bit to understand, but I find it handles most of my resizing needs. I have modified the original APL2000 function to accept vectors instead of a matrix of values, and have modifications for MDI forms, and Picture and APLDraw objects, the latter 2 modifing the pixel size of the control. Also I've added {delta}width for CommandBar buttons.
The {delta}where property can have 4 or 8 elements. The first 4 define the location of the origin of the control, and the last 4 define the size. The parameters are in pairs, the first being a relative value from 0 to 1, where 1 is 100% of the size for the form. The second being an absolute which is either positive or negative and adds or subtracts from the total size after calculating the relative part first.
An example, suppose you want a form with an Edit control that consumes most of the client area, with a Button at the botton of the form, centered. On Resize, the button is to stay at the bottom and the Edit control expands or contracts to fill the area. The button I will make 1.5 character units high, and will allow 0.25 character units around it to give it a "pretty" border. The Edit control will then consume all the the height except for the bottom 2 characters units. 1.5 for the button, and .25 time 2 for the border area around the button.
The first 4 values of the {delta}where define the start location. The first 2 define the vertical, the second 2 the horizontal. A value of 0 0 0 0 would mean, start in the upper left corner with no absolute offsets. The next four values define the extents. The edit control will consume all the vertical except for the last 2 character units, so the vertical values would be 1,-2. 1 is the relative value meaning 100 percent. The -2 subtracts 2 character units from the extent. The horizontal will be 1 0, meaning 100 percent of the width with no offsets. The complete {delta}where value will be 0 0 0 0 1 ¯2 1 0
The button will be located at the bottom, with an offset of 1.5+.25, or 1.75 units. So the first 2 values of {delta}where will be 1,-1.75. The button will be centered on the Form, and since it is 8 characters wide, an offset of -4 characters from the center will put it in the center. So the next two values will be .5,-4. The size of the button will not change, so the relative values will be 0. The absolute size will be 1.5 characters high by 8 characters wide. So the size values will be 0 1.5 0 8. The complete {delta}where value will be 1 ¯1.75 .5 ¯4 0 1.5 0 8.
Seems a bit confusing, but then, I don't document like Colin!
Here is the sample form, with all resizing handled.
’ MakeForm
[1] 'f' Œwi 'Create' 'Form' ('onResize' 'AutoResize')
[2] 'f.ed' Œwi 'Create' 'Edit' ('‘where' 0 0 0 0 1 ¯2 1 0)
[3] 'f.bn' Œwi 'Create' 'Button' ('‘where' 1 ¯1.75 .5 ¯4 0 1.5 0 8)
[4] 'f' Œwi 'Resize'
’
Here is my current AutoResize function. Understand the not all the APL characters may be visible, such as the Match character. But copy and paste seems to bring them back.
’ AutoResize;c;w;s
[1] © Automatically resize the objects on a form
[2] © each object has a UDP ‘where
[3] © ‘where is either 2x2 or 4x2 matrix
[4] © Copyright 1998 APL2000 Inc.
[5] © Modified by Brent Hildebrand. Added ‘where to accept 4 or 8 element vectors and ‘clientwhere for MDIFor
m
[6] © Modified 9/1999. Added ‘width to handle object widths of a CommandButton.
[7]
[8] …(1=¯1†Œwarg)/0 © exit if minimizing
[9] s„2†Œwarg © new height and width
[10] :if 'MDIForm' Œwi 'class'
[11] w„Œwi '‘clientwhere'
[12] :if (,8)½w ª w„4 2½w ª :end
[13] :if (,4)†½w ª w„2 2½w ª :end
[14] :if (2 2½w)Ÿ(4 2½w)
[15] w[;Œio]„w[;Œio]×(†½w)½s
[16] w„+/w
[17] (2‡w)„0—2‡w
[18] Œwi 'clientwhere' w
[19] :endif
[20] :end
[21]
[22] :for c :in Œwi 'children'
[23] :if 'CommandButton' c Œwi 'class'
[24] w„,c Œwi '‘width'
[25] :if (2=½w)Ÿ(1=½w)
[26] w„w×(†½w)†(¯1†s),1
[27] w„+/w
[28] w„0—w
[29] c Œwi 'width' w
[30] :endif
[31] :end
[32]
[33] w„c Œwi '‘where'
[34] :if (,8)½w ª w„4 2½w ª :end
[35] :if (,4)½w ª w„2 2½w ª :end
[36] :if (2 2½w)Ÿ(4 2½w)
[37] w[;Œio]„w[;Œio]×(†½w)½s
[38] w„+/w
[39] (2‡w)„0—2‡w
[40] c Œwi 'where' w
[41]
[42] © :if 'Picture' c Œwi 'class'
[43] © c Œwi 'imagesize' (¯2†w)
[44] © :end
[45] © :if 'ActiveControl APL2000.Draw' c Œwi 'class'
[46] © c Œwi 'xImageHeight' (16×w[2+Œio])
[47] © c Œwi 'xImageWidth' (8×w[3+Œio])
[48] © :end
[49] :endif
[50] :endfor
’
One thing to know, is that you need to set the onResize for Frames to AutoResize just like you do for Forms, so that the resizing propogates to controls in the Frame.
How do you all do resizing??