Wish Designer - code generator

LucaMs

Expert
Licensed User
Because I'm too stupid to get from Designer what I want, I wish there was a Designer function which generates the code to set at runtime the dimensions of all views as percentages compared to the screen (layout).

Something like:

Button1.Width = 25%x
Button1.Height = 10%y
Button1.Left = ...%x
Button1.Top = ...%y
 
Last edited:

ShaneG30

Well-Known Member
Licensed User
I actually wish that's what the layout files were. Something like yours but like this:

B4X:
Dim MyButton As Button
MyButton.Initialize("Event")
MyButton.Text = "MyButton"
MyButton.Width = 100
MyButton.Height = 100
MyButton.Top = 10
MyButton.Left = 20
'Any other designer properties.
So instead of a bal or bil file being binary gibberish, it would be like a Visual Studio ".designer" file. (Would also be good for version control.)

@Erel - Your opinions?
 
Last edited:

NJDude

Expert
Licensed User
B4X:
Dim MyButton As Button
MyButton.Initialize("Event")
MyButton.Text = "MyButton"
MyButton.Width = 100
MyButton.Height = 100
MyButton.Top = 10
MyButton.Left = 20
'Any other designer properties.
Note that you MUST use DIP or your layouts will not scale properly on all devices.

For example:
B4X:
MyButton.Width = 100dip
 
Last edited:

ShaneG30

Well-Known Member
Licensed User
Note that you MUST use DIP or your layouts will not scale properly on all devices.

For example:
B4X:
MyButton.Width = 100dip
I was actually talking about the Bal/Bil files becoming like the displayed code. (Like Visual Studio's ".designer" files.)
 

NJDude

Expert
Licensed User
I was actually talking about the Bal/Bil files becoming like the displayed code. (Like Visual Studio's ".designer" files.)
Still, I was making a note to use DIP since is a common mistake.
 

ArminKH

Well-Known Member
+1
how ever this can be done by converting layouts to json or xml format and then write a good b4j desktop app for calculate all dimentions and then convert back to .bal format
this is just a suggestion
 

LucaMs

Expert
Licensed User
Why do you want to use percentage for your layout? In most cases this is not the correct way to implement a flexible layout.

You should instead use anchors with auto scale all.
Because, as you can see below, if I use anchors and autoscaleall only I don't get what I "need".
Why in that case I don't obtain a bigger or smaller panel (depending on difference between the layout dimensions and the device dimensions) and proportionate edge distances despite I used Autoscaleall?

I think: you use dips, so If you have 100dip, you get same misure on any device (misure in cm) but if you add autoscaleall this 100dip will be ... scaled.

upload_2015-7-5_9-28-27.png
 

Attachments

Last edited:

LucaMs

Expert
Licensed User
+1
how ever this can be done by converting layouts to json or xml format and then write a good b4j desktop app for calculate all dimentions and then convert back to .bal format
this is just a suggestion
I tried but it is very difficult to "trace" all views (and names!) with all of their relationships using this method.

[Furthermore, the .bal structure could change in the future]
 

LucaMs

Expert
Licensed User
upload_2015-7-5_9-58-45.png

(I should use this script testing before the screen orientation, if it is landscape, and I should use percentages for all views)

upload_2015-7-5_10-0-35.png
 

LucaMs

Expert
Licensed User
The first step is to comment all the designer script.
The second step is to set the vertical and horizontal anchors to BOTH.

So it is perfect, thank you, Erel.

Now I have to investigate if I should set all the views in the same way (I fear it would be too simple :D)
 

LucaMs

Expert
Licensed User
It's too hot; I should sleep 25 hours/day, perhaps.

While I was trying (see previous post)...

upload_2015-7-5_16-42-55.png


As you can see, the panel is 170 Height, the layout 320... (320-170) / 2 = 75 and Top is 75 but the panel is not vertical centered.

Maybe after several attempts with anchors it has happened and then it is a bug... or it's too hot and I'm wrong these measures :D
 
Last edited:

LucaMs

Expert
Licensed User
You are confusing total height 320 and real height 320 - 50 = 270 !
(270 - 170) / 2 = 50 !

No, Klaus, thank you, because I unchecked Show Title and checked Full Screen, then 320 is the full free vertical space

upload_2015-7-5_17-11-25.png
 
Last edited:

LucaMs

Expert
Licensed User
... but checking/unchecking rechecking :D those parameters (Full Screen and Show Title) now with Top = 75 and Height = 170 (not changed) the panel is centered.

It is just a little bug (like "refresh" or reset some variable).
 
Top