Android Question CSBuilder and AutoTextSizeLabel

cliv

Member
Licensed User
Longtime User
I do this with a label:
B4X:
Dim cs As CSBuilder
Dim lblPrecipitation As Label
cs.Initialize.Typeface(Typeface.FONTAWESOME).Color(Colors.LightGray).Append(Chr(0xF043)).Color(Colors.Gray).Append(" " & relative_humidity ).PopAll
lblPrecipitation.Text=cs

But ... can i use AutoTextSizeLabel and csBuilder instead of label?
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
I think AutoTextSizeLabel is effectively just a subclass of a Label isn't it? If so, you should be able to assign the cdBuilder to the .Text property. Have you tried it? If so, did you get an error?

- Colin.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Change the two subs code in the class to:
B4X:
Public Sub setText(value As Object)
   mLbl.Text = value
   Dim multipleLines As Boolean = mLbl.Text.Contains(CRLF)
   Dim size As Float
   For size = 2 To 80
     If CheckSize(size, multipleLines, value) Then Exit
   Next
   size = size - 0.5
   If CheckSize(size, multipleLines, value) Then size = size - 0.5
   mLbl.TextSize = size
End Sub

'returns true if the size is too large
Private Sub CheckSize(size As Float, MultipleLines As Boolean, Text As Object) As Boolean
   mLbl.TextSize = size
   If MultipleLines Then
     Return su.MeasureMultilineTextHeight(mLbl, Text) > mLbl.Height
   Else
     Return cvs.MeasureStringWidth(mLbl.Text, mLbl.Typeface, size) > mLbl.Width Or _
       su.MeasureMultilineTextHeight(mLbl, Text) > mLbl.Height
   End If
End Sub

Note that the width measurement ignores the custom styles.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…