Designer Script - calling B4X code

Alexander Stolte

Expert
Licensed User
Longtime User
DDD.SpreadControlsHorizontally(Pane1, 200dip, 5dip) DDD.SetText(Button1, "Sunday", "Sun", "Su", "S") DDD.SetText(Button2, "Monday", "Mon", "Mo", "M") DDD.SetText(Button3, "Tuesday", "Tue", "Tu", "T") DDD.SetText(Button4, "Wednesday", "Wed", "We", "W") DDD.SetText(Button5, "Thurdsay", "Thu", "Th", "T") DDD.SetText(Button6, "Friday", "Fri", "Fr", "F") DDD.SetText(Button7, "Saturday", "Sat", "Sa", "S")
And multilingual? 🤔
 

ilan

Expert
Licensed User
Longtime User
Now try to do everything in the the resize event
you really want me to try? :rolleyes:

(which doesn't exist in B4A)
in b4a the resize code could be called each time a layout is loaded to update all text according to the screen size so no need for a resize_event

you will end up writing several pages of complex code
:oops:

i guess a lot more code (not all code is visible in your example) but NOT several Pages... (even for a noob like me)


B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private CustomListView1 As CustomListView
    Private vpW, vpH As Float 'ignore
    Private dayNames As List = Array As String("Sunday","Monday","Tuesday","Wednesday","Thurdsay","Friday","Saturday")
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    vpW = MainForm.RootPane.Width
    vpH = MainForm.RootPane.Height
   
    For i = 1 To 100
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, MainForm.RootPane.Width, 200dip)
        p.LoadLayout("item")
        CustomListView1.Add(p, "")
    Next
   
    updateButtonText 'call at start for all ide's
End Sub

Private Sub MainForm_Resize (Width As Double, Height As Double)
    updateButtonText
End Sub

Private Sub updateButtonText
    For i = 0 To CustomListView1.Size-1
        Dim p As B4XView = CustomListView1.GetPanel(i)
        For Each n As Node In p.GetAllViewsRecursive
            If n Is Button Then
                Dim b As Button = n
                b.Text = getTextAccordingToSize(b.Tag.As(Int), b.Width)
            End If
        Next
    Next
End Sub

Private Sub getTextAccordingToSize(day As Int, size As Float) As String
    If size < vpW*0.1 Then
        Return dayNames.Get(day-1).As(String).SubString2(0,1)
    else if size < vpW*0.15 Then
        Return dayNames.Get(day-1).As(String).SubString2(0,2)
    else if size < vpW*0.2 Then
        Return dayNames.Get(day-1).As(String).SubString2(0,3)
    Else
        Return dayNames.Get(day-1)
    End If
End Sub
 

Attachments

  • resize.zip
    4.1 KB · Views: 86

aeric

Expert
Licensed User
Longtime User
I am facing an issue with my POS system where I need to hide the logo in the print preview based on user's change settings and need to readjust the content panel's top position when the logo is hidden. If I understand correctly what this feature is all about, it will be useful or make things easier for me. I want to try it out when it is available.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I am facing an issue with my POS system where I need to hide the logo in the print preview based on user's change settings and need to readjust the content panel's top position when the logo is hidden. If I understand correctly what this feature is all about, it will be useful or make things easier for me. I want to try it out when it is available.
The new feature might be useful for this case. I'm not 100% sure as it depends on how it is implemented.

One thing I don't understand here is, inside the Designer Script, the code accepts 3 function arguments while the B4X code has only 1 function parameter.
Good catch. The signature of "designer callable" subs is a single DesignerArgs parameter. This object holds all kinds of important details including a list with the parameters.
i guess a lot more code (not all code is visible in your example) but NOT several Pages... (even for a noob like me)
As I wrote the main advantage of the new feature is that all or most of the layout related implementation is encapsulated in the layout file. Think of a large project with many layouts that are added and removed. As the project grows it becomes more and more complicated to manage the state. Especially when the same layout can be loaded in different places.
Anyway there is no reason to argue about it. This is an optional tool, which I'm sure that it will be useful in many cases and like any tool, it is the developer who chooses what to use and what not to use.
 

ilan

Expert
Licensed User
Longtime User
Anyway there is no reason to argue about it.
i am sorry, it was not my intention to argue i just wanted to understand how and when this feature could be useful. now everything is clear. thank you for your great work and effort Erel 🙏
 

LucaMs

Expert
Licensed User
Longtime User
I can only comment !
Wait and see :) !
waiting-for-mailman-DM7ANY.jpg



Waiting_room_icon.svg.png
 

aeric

Expert
Licensed User
Longtime User
The demo is like creating responsive website with Bootstrap but in B4X apps instead. Really good for creating cross platform app with different screen size. I think my numpad layout designer script for my POS system can be more simplified. I don’t need to assign the button size and left and top position for each button with 3 lines of code but can accomplish with 1 line of code only.
 
Top