Sub TextBubble(inPanel As B4XView, inTexts() As String, inFontSize As Float)
For Each v As B4XView In inPanel.GetAllViewsRecursive
v.RemoveViewFromParent
Next
If inTexts.Length = 0 Then Return
Dim Border As Float = 0dip 'StrokeWidth
Dim Edge As Float = 15dip 'Distance
Dim Canvas1 As B4XCanvas
Canvas1.Initialize(inPanel)
' ***********************************
#region measure text size
Dim width, height As Float
width = 0
height = 0
Dim FontHeight As Float
FontHeight = 1dip
For Each t As String In inTexts
FontHeight = Max(FontHeight , Canvas1.MeasureText(t, XUI.CreateDefaultFont(DipToCurrent(inFontSize))).Height + 1dip) 'max. text row height
Next
For Each t As String In inTexts
width = Max(width , Canvas1.MeasureText(t, XUI.CreateDefaultFont(DipToCurrent(inFontSize))).Width) 'maximal with
height = height + FontHeight
Next
#end region
' ***********************************
#region bubble
'make it bigger for the border around
Dim width2, height2 As Float
width2 = width + Edge * 2.0
height2 = height + Edge * 2.0
Dim Rect1 As B4XRect
Rect1.Initialize(inPanel.Width / 2.0 - width2 / 2.0 , inPanel.Height / 2.0 - height2 / 2.0, inPanel.Width / 2.0 + width2 / 2.0, inPanel.Height / 2.0 + height2 / 2.0)
Dim Path1 As B4XPath
Path1.Initialize(Rect1.Left + Edge, Rect1.Top)
Path1.LineTo(Rect1.Right ,Rect1.Top)
Path1.LineTo(Rect1.Right ,Rect1.Bottom)
Path1.LineTo(Rect1.Right - Rect1.Width * 0.5, Rect1.Bottom)
Path1.LineTo(Rect1.Right - Rect1.Width * 0.5, Rect1.Bottom + Edge * 3.0) 'peak
Path1.LineTo(Rect1.Right - Rect1.Width * 0.75, Rect1.Bottom)
Path1.LineTo(Rect1.Left ,Rect1.Bottom)
Path1.LineTo(Rect1.Left ,Rect1.Top + Edge)
'math corner left, top
Dim a As Float,x As Float,y As Float
For a = 0.0 To 90.0 Step 10.0
x = -CosD(a) * Edge
y = -SinD(a) * Edge
Path1.LineTo(Rect1.Left + Edge + x ,Rect1.Top + Edge + y)
Next
Canvas1.DrawPath(Path1, XUI.Color_RGB(0,128,0), True, 1)
Canvas1.DrawPath(Path1, XUI.Color_White, False, Border)
#end region
' ***********************************
#region draw text
Dim Rect1 As B4XRect
Rect1.Initialize(inPanel.Width / 2.0 -width / 2.0, inPanel.Height / 2.0 - height / 2.0, inPanel.Width / 2.0 + width / 2.0, inPanel.Height / 2.0 + height / 2.0)
'test rect
' Canvas1.DrawRect( Rect1, XUI.Color_Black, False, 1dip) 'check size
Dim y As Float = Rect1.Top
Dim h As Float = 0
For Each t As String In inTexts
h = FontHeight
y = y + h
Canvas1.DrawText(t, Rect1.Left, y - FontHeight * 0.1, XUI.CreateDefaultFont(inFontSize), XUI.Color_Yellow, "LEFT")
Next
Canvas1.Invalidate
#end region
End Sub