When I change my phones font size from default to large I see the expected increase in text size, except with strings generated by CSBuilder. CSBuilder strings don't change with the system setting, and consequently the resultant calculated height of a label are wrong. I've attached the code, and two screen images that show the problem. The font size is set to 18 for both labels. screen 1 shows default fonts, screen 2 shows "large" fonts. I use CSBuilder in order to have varied text size and colors in my app (not this quick demo).
As you can see, even with normal fonts there is a slightly different height result. With large fonts, it's exaggerated, but the CSBuilder strings also don't change size! I have the same problem on two tablets and my phone.
Any help is appreciated!
B4X:
Sub Globals
Dim Label1, Label2 As Label
Dim cs As CSBuilder
Dim txt As String
Dim su As StringUtils
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("labels")
txt = "Now is the time for all good men to come to my aid and bring beer and pretzels" & CRLF
cs.Initialize.Size(18).Color(Colors.White).Append(txt).PopAll
Label1.Text = txt
Label1.TextSize = 18
Label2.Text = cs
Label1.Height = su.MeasureMultilineTextHeight(Label1, Label1.Text)
Label2.Height = su.MeasureMultilineTextHeight(Label2, Label2.Text)
End Sub
Label.Text returns a String, not a CharSequence. This means that the style spans are lost in the call to MeasureMultilineTextHeight. You should instead pass cs as the second parameter.
Thanks Erel! Problem quickly solved... as usual! So, I take it that CharSequence's are intended to ignore user device settings of font size? Or is that a bug, Erel? Thanks.
I tried to explain why it happens in the previous post.
Label.Text returns an unformatted string object. This means that MeasureMultilineTextHeight will use the label's text size instead of the size you set with CharBuilder.
I understood what you said, and my label sizing code now works perfectly. But I apparently did not ask my 2nd question clearly, sorry. When I format text with CSBuilder and place it in a label, the size of the text as viewed on the screen doesn't change with the user's device font size (default, large, etc). Is that a bug, or is that it's intended behavior of CSBuilder?