Customer Control Designer - Code Generator

kanaida

Active Member
Licensed User
Longtime User
I just had an epiphany :D
basically you already have the designer right. It already generates code to create the layout properties etc... so why not let us design custom controls the way we make the activity layout. Except by clicking a button have it generate the code to create the controls exactly as we designed them as a sub

eg:
1) Design a new type of listview item, lets say a panel with a label or 2, maybe a picture or checkbox
2) save it with some nickname like CheckBoxListViewItem
3) press generate sub and get an output something like this:

B4X:
Sub ProcessGlobals()
TYPE CheckBoxListViewItem(P1 as Panel, L1 as label)
TYPE CheckBoxListViewItemInitArgs(PanelEvent as string, LabelEvent as string)
End sub

Sub NewCheckBoxListViewItem(InitArgs as CheckBoxListViewItemInitArgs) as TYPE
Dim NewControl as CheckBoxListViewItem
NewControl.P1.Initialize(InitArgs.PanelEvent)
NewControl.l1 as label : NewControl.l1.initialize(InitArgs.LabelEvent) : NewControl.l1.text = "something"
NewControl.p1.addview(l1,xxxxxxxx)
'Whatever stuff is defined in the layout visually
return NewControl 
End Sub

So now we can just programmatically multiply the height * the number of items we're adding to a new panel on our main activity etc... but we didn't have to do all this stuff in such a verbose manner :) So really it acts sort of like a user control does in vb.

So now we can handle events by passing the strings in the init args as well.

Taking it one step further, actually letting us create subs in place of what would normally be properties, but attached to that type would be awesome to do stuff like CheckBoxListViewItem1.SetTheme(1) or CheckBoxListViewItem1.Disable()

As for the type definitions, probably throw those into a code module called CustomControls or something, along with the pseudo properties.

We'd probably have to make the sub inside each activity we want, in order to let the events work correctly, but that's pretty minor i'd say. Event Better if you let us init like this to avoid this: Initialize("ActivityName.EventHandlerPrefix")
 
Last edited:
Top