>>
APLDN Home

>>
Events

>>
Trainings

>>
APL Books

>>
APLDN Links

>>
Discussion Groups

>>
Downloads

>>
Articles

>>
Library

>>
Learning Tools

>>
APLDN User IO

>>
APL2000.com




APL code discussion

Author Thread: Resizing Forms
brent.hildebrand
Resizing Forms
Posted: Wednesday, July 28, 2004 6:22 PM (EST)

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??


Comments:

Author Thread:
Michael.Hughes
Resizing Forms
Posted: Thursday, July 29, 2004 3:30 AM (EST)

I tend to build the forms on the fly with fixed control sizes so my resizing is usually an aspect of this.  I like most of my controls to remain the same size but a few like grid inputs etc I allow to float.

 

Therefore as part of the resizing I either set the size of the variable control(s) and build/resize the form around it or I adjust the variable controls to fit within the space left by the others in a resized form.

 

     

davin.church
Resizing Forms
Posted: Thursday, July 29, 2004 12:48 PM (EST)
I'm not too fond of all the manual settings required to get resizing to work with utilities like that.  I'd rather have a smart resizing utility that just "does the right thing" by itself, and allow some manual overrides to handle special cases.  I've been wanting to write such a thing for a long time, but I never get time to work on it.

     

brent.hildebrand
Resizing Forms
Posted: Thursday, July 29, 2004 1:14 PM (EST)
The beauty of the AutoResize function, is that resizing is simple and "built in". If you set all the odd values of {delta}where to 0, you have a fixed position control, just as if you set the 'where' property. Why build complicate resize handlers when you can just set the {delta}where once and all resizing is then automatic? I used to write complicated resize handlers, but have abandoned them except for special cases such as where the font needs to change with the Resize event. What other techniques are people using that is as simple as AutoResize? Are there any?

     

davin.church
Resizing Forms
Posted: Thursday, July 29, 2004 1:49 PM (EST)

"Why build complicate resize handlers when you can just set the {delta}where once and all resizing is then automatic?"

 

Well, because I don't want to have to set the ^where on every control of every screen I write.  I spend enough time on the GUI layout already.

 

Yes, such a routine would be terribly complicated to write, but don't misunderstand that I want to build such a thing for each separate screen.  I'd like to make one general utility that should (hopefully) work on all screens.  Then I'd never have to set a ^where again.

 

I know there are several resizing facilities floating around out there.  As I recall, Eric Lescasse has one built into his toolset, too.

     

brent.hildebrand
Resizing Forms
Posted: Thursday, July 29, 2004 4:29 PM (EST)

"Why build complicate resize handlers when you can just set the {delta}where once and all resizing is then automatic?"

 

Well, because I don't want to have to set the ^where on every control of every screen I write.  I spend enough time on the GUI layout already.

 

Hm - when you layout a GUI, do you use "where" and/or "size", right?  fine for fixed controls.  The only difference in using the AutoResize utility, is that you add the ability to have relative sizing and positioning.  To me is seems a natural extension.  You have already calculated absolutes, adding the relatives is a simple extension.  Use the relative position and size to keep buttons at the bottom of a form, or to make Edit controls or Listviews consume a majority of the clientarea.  I have a simple utility that creates a "splitter" where again, all objects easily and automatically resize when you move the splitter in each or the panes of the window. 

 

How would you write the simple form I suggested in the original post?  Are there any specific resize challenges that might not work well using the AutoResize utility?   

 

Again - I'm just exploring what how others do resizing.  I've already exposed my bias to AutoResize. 


 

     

Michael.Hughes
Resizing Forms
Posted: Friday, July 30, 2004 10:45 AM (EST)

As I said I usually construct my forms on the fly and usually encase my grouped controls in visible or invisible frames.  I allow the controls to arrange themselves within the frame and set the size of the container to be the smallest possible and effective pass the size of the frame to the next level.  At any level there are only a few "variable" size objects which are expanded or restricted to fill the remaing space.

 

This allows the form to resize itself sensibly without to much hard coding interference.  You just recurse up or down the tree arranging the frames.

 

 

     

brent.hildebrand
Resizing Forms
Posted: Friday, July 30, 2004 12:06 PM (EST)
Can you provide some sample code? You say you "allow the controls to arrange themselves within the frame". How do the controls arrange themselves? I'm not clear. Thanks.

     

fred.waid
Resizing Forms
Posted: Friday, July 30, 2004 2:59 PM (EST)

A few years ago we did a resize handler which automatically resizes and relocates controls on a form based on the geometry used in web browsers.

 

You do not have to set anything, it pretty much figures everything out by itself.  You can override the default behaviors or remove controls from the autoresizing all together.

 

It might have some code which could be useful.

 

A sample workspace is uploaded at:

 

http://apldn.apl2000.com/downloads/APLWI+Downloads/APLWIUF/881.aspx

 

 

     

anico
Resizing Forms
Posted: Friday, December 17, 2004 3:20 PM (EST)

Fred,

 

I tried your AutoResize routine with mixed success. It does resize the controls, but after a couple of resizings it looses track of the locations of objects, so that they begin to overlap each other.

 

It appears that a good deal of  customization of the "where" and "resize" controls is still necessary in order for it to work within a visual framework.

 

Thanks,

 

/mas

     

brent.hildebrand
Resizing Forms
Posted: Friday, December 17, 2004 3:31 PM (EST)
I would like to see the code you tried. I do not find any issue with AutoResize "loosing track" of the position of controls. Even on vary conplex forms. For many forms, I do not ever set the "where" property, and the onResize event is just AutoResize. It does require having a feel of how to set the {delta}where property. And there are some situations which just will not work with AutoResize. But for a most or my projects, it is perfect. So, give us some samples of forms which have presented problems for you, and perhaps we all can learn.

     

Adam.Kertesz
Resizing Forms
Posted: Friday, December 17, 2004 10:27 PM (EST)
Please, see winresize.zip in the partners' area. I have cleaned up, restructured and documented Fred Waid's original ws, with minor coding changes.

     

j.merrill
Resizing Forms
Posted: Monday, December 20, 2004 2:55 PM (EST)
Brent -- in reading the thread, I think the "loosing track" (sic) comment concerned Fred's AutoResize, not yours. If that's not the case, hopefully you'll get the "here's what I tried that didn't work" response you were after.

     

brent.hildebrand
Resizing Forms
Posted: Monday, December 20, 2004 6:50 PM (EST)
Jay - thanks - I have reread the thread, and yes I now believe it was not refering to "AutoResize", but to Fred's workspace. I have tried Fred's, and I'll stick with "AutoResize" which works quite well for most of my applications for now.

     



APL2000 Official Web Site

May the smile on your face Come straight from your heart
--- Anonymous

APLDN Home   |    |  Events   |  Trainings   |  APL Books   |  APLDN Links   |    |  Discussion Groups   |    |  Downloads   |  Articles   |  Library   |  Learning Tools   |  APLDN User IO   |  APL2000.com   |