'# GBEDialog = B4XDialog. Changed Private Buttonwidth to public
'# added measure text sub to B4XDialog code
'# code is called after creation of pane and loading layout for custom dialog
public Sub adjustButtons(dlg As GBEDialog,p As Object,y As String, n As String, c As String)
' adjust buttons
Dim bw As Int=0
Dim bt As Int = 0
#if B4J
Dim p1 As Pane = p.As(Pane)
#else if B4A
Dim p1 As Panel = p.as(panel)
#End If
If c <> "" Then
bt=bt+1
bw = dlg.MeasureTextWidth(c,dlg.ButtonsFont) * 1.5
If dlg.ButtonWidth < bw Then dlg.ButtonWidth=bw
End If
If n <> "" Then
bt=bt+1
bw = dlg.MeasureTextWidth(n,dlg.ButtonsFont) * 1.5
If dlg.ButtonWidth < bw Then dlg.ButtonWidth=bw
End If
If y <> "" Then
bt=bt+1
bw = dlg.MeasureTextWidth(y,dlg.ButtonsFont) * 1.5
If dlg.ButtonWidth < bw Then dlg.ButtonWidth=bw
End If
#if B4J
If p1.PrefWidth < dlg.ButtonWidth * bt + 10dip Then
p1.PrefWidth = dlg.ButtonWidth * bt + 10dip
End If
#else if B4A
If p1.Width < dlg.ButtonWidth * bt + 10dip Then
p1.Width = dlg.ButtonWidth * bt + 10dip
End If
#end if
End Sub
public Sub MeasureTextWidth(Text As String, Font1 As B4XFont) As Int
#If B4A
Private bmp As Bitmap
bmp.InitializeMutable(2dip, 2dip)
Private cvs As Canvas
cvs.Initialize2(bmp)
Return cvs.MeasureStringWidth(Text, Font1.ToNativeFont, Font1.Size)
#Else If B4i
Return Text.MeasureWidth(Font1.ToNativeFont)
#Else If B4J
Dim jo As JavaObject
jo.InitializeNewInstance("javafx.scene.text.Text", Array(Text))
jo.RunMethod("setFont",Array(Font1.ToNativeFont))
jo.RunMethod("setLineSpacing",Array(0.0))
jo.RunMethod("setWrappingWidth",Array(0.0))
Dim Bounds As JavaObject = jo.RunMethod("getLayoutBounds",Null)
Return Bounds.RunMethod("getWidth",Null)
#End If
End Sub