B4J Question Layout Visual Designer - align and size objects?

SparkOut

Member
In the Visual Designer, having added views, is there a simple way to align them, make them all the same width/height and spread them out?
I have easily used the Designer Script to size/position/align the views proportionally according to the pane size, but once that script is run, saving the layout doesn't retain those new positions.
It's not a big deal, but it just looks a mess when I open the Visual Designer, and there are too many fiddly views for me to try and do this all by manually editing the properties of each one.
If there's a way to save the size/positions of the views after the script has placed them that would be great. (Also a wish would be to have Designer Script loops to be able to iterate over a list of views and space them evenly, instead of having to specify each view individually in the script.)
 

aeric

Expert
Licensed User
Longtime User
It is better if you could upload an example of what you try to achieve.

You can use variables in Designer Script.
e.g
Width1 = 50dip
pnl01.Width = Width1
pnl02.Width = Width1
' or
' pnl02.Width = pnl01.Width

Let say you want to add a gap between 2 views, you can write:
gap = 5dip
pnl02.Left = pnl01.Right + gap

To preview the layout for the script, you have to click the Run button.

1768060274654.png


Let say you want to spread 5 buttons horizontally, you can calculate the width of the button by subtract the total gap and divide by the number of views
gap + button1.width + gap + button2.width + gap + button3.width + gap + button4.width + gap + button5.width + gap

5 x button width
6 x gap

gap = 10dip
Button1.Width = ( 100%x - (6* gap) ) / 5

If there's a way to save the size/positions of the views
Sure the position and size defined in the script are saved inside the layout file.

If you want to iterate a common layout then you may consider using CustomListView.
 
Upvote 0

SparkOut

Member
Thanks, I have got the script to lay out the views without problem. (It would be nice if you could iterate over the controls in a loop (psuedo) ("Button" + i).Width = ( 100%x - (6* gap) ) / 5
But that's not a big deal. Nor is it really a big deal to leave the layout to the script to arrange. It just rankles me that having scripted the layout, I can't then save the new positions, every time I reopen the layout in the Visual Designer the views all shift back to their original position and size, where they were placed by manually dragging around. It looks ugly to me in the designer, but nobody's going to see it except me. The script runs before anyone would ever see the original scattered layout.
 
Upvote 0

SparkOut

Member
The script lays everything out fine, but no matter how many times I save, the views all revert to the version from the unscripted, messy layout. If that's to be expected, then I can move on, no problem. I just hoped there was a way to have the new properties saved back to the .bjl file - if only to make it tidier for me to see.
 

Attachments

  • LayoutBeforeScript.png
    LayoutBeforeScript.png
    67 KB · Views: 13
  • LayoutAfterScript.png
    LayoutAfterScript.png
    89.6 KB · Views: 13
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
The script is saved with the layout and aplied (runnef) when the layout is loaded...
But I get what you are asking...
This is psrt of a series of whishes made about the designer, such as VAlign, HAlign, view freeze, Z-order by menu (you can reorder then along the views list, thus changing the z-order), amongst a few other wishes...
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Do you click the Run button?
 
Upvote 0

SparkOut

Member
Yes of course.
On first opening the designer, the layout shows the messy views, with the position, sizes and alignment as originally placed by dragging in the designer.
The script runs and everything is placed as desired.
The new positioning as made by script is not then possible to save as the default for when the designer opens ithe layout again.
This is not a deal breaker.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I also mentioned about CustomListView.
You may take a look on it.
 
Upvote 0
Top