Font metrics for shortening/ellipsis?

kcorey

Member
Licensed User
Longtime User
Hi All,

Just bought b4a. Quite impressed with the performance, but still very much trying to wrap my head around the syntax and where to find things.

One app that I'd like to deploy has a bunch of buttons on the screen at one time (120 or so). Think 'keyboard'.

Each key in this keyboard will have a word and a picture.

The word is fairly likely to not fit on the button. The word 'at' would fit, but the word 'industrialisation' would not. I would like to display 'indus...ation' instead (or whatever will fit). Also, I'd like it to be on one line because the picture is the main draw for the button...not the text upon it.

So, I started looking for font metrics. No immediate joy.

I found Button.textSize. I'm just guessing here as it's not explained in the manual, but it seems to be the effective point size on the given device, right?

So anyone know how to accomplish this form of shortening with B4A?

Thanks,

-Ken
 

kcorey

Member
Licensed User
Longtime User
Solution StringUtils?

I just found StringUtils, and though it seems quite the long way around, one possibility might be to add the desired text letter by letter until you get an increase in su.MeasureMultilineTextHeight...but what do I use for the 'label' argument?

Hrm...

-Ken
 
Upvote 0

kcorey

Member
Licensed User
Longtime User
You can use Reflection library to call setEllispize: http://www.b4x.com/forum/basic4andr...g-reflection-set-marquee-label.html#post89480

This way the text will be truncated automatically.

Indeed! That was it.

Tricky bit for me: a Button is a descendant of TextView, so I tried all sorts of things before I realised all I had to do was pass the btn to setEllipsize, and "MIDDLE" as the second argument, like this:

B4X:
Dim btn As Button
btn.Initialize("Btn")
btn.Text = wr.word
SetEllipsize(btn, "MIDDLE")

The next tricky thing was in wondering what to do when you're trying to field events for anonymous objects like this. Of course for this example the answer is:

B4X:
Sub Btn_click
end sub

Simple when you know how.

Thanks!

-Ken
 
Upvote 0
Top