Sub CreateJsonfromDesign() 'As JSON
Dim Design As Map
Design.Initialize
Dim assignedTypes As List
assignedTypes.Initialize
Dim whatassign As Map
whatassign.Initialize
'Label Item --> citem01
whatassign.put("B4XDesigner","citem01") 'B4XDesigner is our designer we are creating...
whatassign.put("JavaType",".LabelWrapper")
whatassign.put("DesignerType","Label")
assignedTypes.Add(whatassign)
'B4XFloatTextField --> citem02
whatassign.put("B4XDesigner","citem02")
whatassign.put("JavaType",".CustomViewWrapper")
whatassign.put("DesignerType","CustomView")
assignedTypes.Add(whatassign)
'B4XComboBox --> citem03
whatassign.put("B4XDesigner","citem03")
whatassign.put("JavaType",".CustomViewWrapper")
whatassign.put("DesignerType","CustomView")
assignedTypes.Add(whatassign)
Dim emptylayout As String= $"{
"MaterialIcons": false,
"Variants": [
{
"Scale": 1,
"Height": 600,
"Width": 600
}
],
"LayoutHeader": {
"Version": 5,
"DesignerScript": [
"'All variants script\n",
"'Variant specific script: 600x600,scale=1\n"
],
"GridSize": 10,
"ControlsHeaders": [
{
"JavaType": ".PaneWrapper$ConcretePaneWrapper",
"DesignerType": "Pane",
"Name": "Main"
}
],
"Files": []
},
"Data": {
"parent": "",
"borderColor": {
"ValueType": 6,
"Value": "0xFF000000"
},
"drawable": {
"color": {
"ValueType": 6,
"Value": "0xFFF0F8FF"
},
"csType": "Dbasic.Designer.Drawable.ColorDrawable",
"colorKey": "-fx-background-color",
"type": "ColorDrawable"
},
"orientation": "INHERIT",
"visible": true,
":kids": {},
"csType": "Dbasic.Designer.MetaMain",
"handleResizeEvent": true,
"type": ".PaneWrapper$ConcretePaneWrapper",
"title": "Form",
"enabled": true,
"variant0": {
"top": 0,
"left": 0,
"hanchor": 0,
"width": 200,
"vanchor": 0,
"height": 200
},
"cornerRadius": {
"ValueType": 7,
"Value": 0
},
"javaType": ".PaneWrapper$ConcretePaneWrapper",
"duration": 0,
"file": "",
"borderWidth": {
"ValueType": 7,
"Value": 0
},
"alpha": {
"ValueType": 7,
"Value": 1
},
"name": "Main",
"eventName": "MainForm",
"extraCss": "",
"tag": ""
},
"FontAwesome": false
}"$
Design=emptylayout.As(JSON).ToMap
Dim variants As List=Design.Get("Variants")
Dim variantlist As Map=variants.Get(0) 'Get list - only one row for my design
variantlist.Put("Height",Root.Height) 'replace with the size of mainpane
variantlist.Put("Width",Root.Width)
Dim LayoutHeader As Map=Design.Get("LayoutHeader")
LayoutHeader.put("GridSize",10) 'replace at the right map...
Dim Data As Map = Design.Get("Data")
Dim controls As List=LayoutHeader.Get("ControlsHeaders")
Dim kids As Map
kids.Initialize
Log(controls.Size)
Dim acontrolofthem As Map
acontrolofthem.initialize
'For k=0 To controls.Size-1 'may be start from 1 - because first object is the frame...
' Dim acontrolofthem As Map=controls.Get(k)
' Log (k & " " & acontrolofthem.Get("Name"))
'Next
Dim kid As Int = 0
Dim controlnames As List = Array As String("citem01","citem02","citem03")
For k = 0 To controlnames.Size -1
Dim whatis As String = controlnames.Get(k)
Dim whatassign As Map = assignedTypes.Get(k)
' For i = 0 To assignedTypes.Size -1
' Dim whatassign As Map=assignedTypes.Get(i)
' Log(whatassign)
' If whatassign.Get("B4XDesigner") = whatis Then 'B4XDesigner is our designer we are creating...
acontrolofthem.put("JavaType",whatassign.Get("JavaType"))
acontrolofthem.put("DesignerType",whatassign.Get("DesignerType"))
acontrolofthem.put("Name",controlnames.Get(k))
controls.Add(acontrolofthem)
Dim jp As JSONParser
jp.Initialize(File.ReadString(File.DirAssets, whatis & ".json"))
Dim currentkid As Map=jp.NextObject
currentkid.Put("name",controlnames.Get(k))
currentkid.Put("eventName",controlnames.Get(k))
'set other properties
kids.put(kid.As(String).Trim, currentkid)
'Log(currentkid.As(JSON).ToString)
kid=kid+1 'next kid
'Exit
' End If
' Next
Next
'Log(kids)
Data.Put(":kids",kids)
Design.Put("LayoutHeader", LayoutHeader)
Design.Put("Variants", variants)
Design.Put("Data", Data)
Design.Put("FontAwesome", False)
Design.Put("MaterialIcons", False)
Log(Design.As(JSON).ToString)
End Sub