B4J Question Designer Script Extensions with buttons in panel

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I like the new Designer Script Extensions feature. It will make things easier to use.

What would be the best way to re-size the buttons like shown below if the buttons was in a panel using this new feature ?

I want to put the buttons in a panel and then re-size the buttons based on the panel size.

1655940338908.png
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
java_cOc8go6mgb.gif


Notes:
- The numpad panel is not anchored to both sides. This allows us to get the "preset" values on the first run. We take care of resizing it.
- DesignerArgs.Views will be available in the soon to be released beta (you can use DesignerArgs.ViewsNames + DesignerArgs.GetViewByName instead).
Designer script:
B4X:
DDD.CollectViewsData
B4XMainPage.ScaleNumpad

Code, which can be useful in similar cases:
B4X:
Private Sub ScaleNumpad(DesignerArgs As DesignerArgs)
    If DesignerArgs.FirstRun Then
        'store the preset values
        For Each view As B4XView In DesignerArgs.Views
            PresetValues.Put(view, Array As Int(view.Left, view.Top, view.Width, view.Height, IIf(view Is Button, view.TextSize, 0)))
        Next
    End If
    Dim MainParent As B4XView = dd.GetViewByName(DesignerArgs.Parent, "Pane1")
    Dim MainPreset() As Int = PresetValues.Get(MainParent)
    If DesignerArgs.ParentWidth < 5 Or DesignerArgs.ParentHeight < 5 Then Return
    Dim ScaleX As Float = DesignerArgs.ParentWidth / MainPreset(2)
    Dim ScaleY As Float = DesignerArgs.ParentHeight / MainPreset(3)
    Dim TextScale As Float = Min(ScaleX, ScaleY)
    MainParent.SetLayoutAnimated(0, 0, 0, MainPreset(2) * ScaleX, MainPreset(3) * ScaleY)
    For i = 0 To MainParent.NumberOfViews - 1
        Dim btn As B4XView = MainParent.GetView(i)
        Dim preset() As Int = PresetValues.Get(btn)
        btn.SetLayoutAnimated(0, preset(0) * ScaleX, preset(1) * ScaleY, preset(2) * ScaleX, preset(3) * ScaleY)
        btn.TextSize = preset(4) * TextScale
    Next
End Sub
 

Attachments

  • DSExample.zip
    4.3 KB · Views: 125
Upvote 0
Top