Home Technical Talk

Easier FormLayout (MEL)

caner_ozdemir
polycounter lvl 9
Offline / Send Message
caner_ozdemir polycounter lvl 9
I have written a script which makes to manage FormLayouts easier.
I want to share this if anyone could be interested.
The FormLayout control is the most powerful but less accessible one as it requires more size, offset and ratio management codes.
This script is designed to use FormLayouts as easy as PaneLayouts.
With this script you can create complex and dynamically resizing GUI layouts easily.

So why would you use a FormLayout for this purpose ?
1 - PaneLayouts are limited with 4 panels by horizontal4, vertical4 and quad. With this script, you can have unlimited panels.
2 - PaneLayouts are limited with one static layout in one panel. With this script, you can mix unlimited static and dynamic layouts in one panel.
3 - PaneLayouts add ugly and movable separators which can not be disabled or unvisibled and could be distracting or easy to be clicked by mistake which leads to change layout ratios.
4 - It may be slightly faster since it does not deal with separator move events.
Are there any disadvantages ?
1 - You can not create movable separators for now.

USAGE
1 - Download and put the script in the right directory.
2 - Add 'source SharedUDForm' in the beginning of your mel code.
3 - Use the following function after showWindow command.

SharedUD_FormLayout(string $form, string $type, int $sep, int $ratio[])
form = name of the formlayout
type = "hor" or "ver" which takes for horizontal and vertical
sep = separator width or height
ratio = percentage of dynamic space for controls, use 0 for fixed size

EXAMPLE
source SharedUDForm;<br><br>window<br>&nbsp;&nbsp; &nbsp;-width 256<br>&nbsp;&nbsp; &nbsp;-height 256<br>myCustomWindow;<br><br>formLayout<br>myCustomForm0;<br><br>&nbsp;&nbsp; &nbsp;formLayout<br>&nbsp;&nbsp; &nbsp;myCustomForm1;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "1a" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "2a" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "3a" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "4a" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "5a" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "6a" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "7a" -width 16;<br>&nbsp;&nbsp; &nbsp;setParent..;<br><br>&nbsp;&nbsp; &nbsp;formLayout<br>&nbsp;&nbsp; &nbsp;myCustomForm2;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "1b" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "2b" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "3b" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "4b" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "5b" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "6b" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "7b" -width 16;<br>&nbsp;&nbsp; &nbsp;setParent..;<br><br>&nbsp;&nbsp; &nbsp;formLayout<br>&nbsp;&nbsp; &nbsp;myCustomForm3;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "1c" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "2c" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "3c" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "4c" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "5c" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "6c" -width 16;<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;button -label "7c" -width 16;<br>&nbsp;&nbsp; &nbsp;setParent..;<br><br>setParent..;<br><br>showWindow myCustomWindow;<br><br>SharedUD_FormLayout("myCustomForm0", "ver", 1, {50, 0, 50});<br>SharedUD_FormLayout("myCustomForm1", "hor", 1, {20, 20, 0, 20, 0, 20, 20});<br>SharedUD_FormLayout("myCustomForm2", "hor", 1, {30, 10, 0, 20, 0, 10, 30});<br>SharedUD_FormLayout("myCustomForm3", "hor", 1, {10, 30, 0, 20, 0, 30, 10});


3a 5a 3b 5b 3c 5c are fixed width
b line is fixed height
others are dynamic width and height defined by ratios

MORE INFORMATION
1 - The sum of ratios must be 100.
2 - The min separator width or height is 1.
3 - To avoid floating point errors which could result 1 pixel dislocated separators, give same size to elements which will be aligned.

DOWNLOAD
http://www.mediafire.com/file/x2dcxbuxurd2d4w/SharedUDForm.mel

UPDATE
I will put this script in the next version of ToolSeq UD which will be found in "_SharedUD_" folder.
So you can watch updates in there.
https://canerozdemirportfolio.wordpress.com/script/

!!! ENJOY !!!


Replies

Sign In or Register to comment.