Length of text in pixels [SOLUTION FOUND]

Is there a method, like in Game Maker, to get the length of a text in pixels?
I found a method to pick from a canvas with drawn emoticons, but for now, the text size must be 40.

Should I look further for a kind of emoticon picker outside the basic keyboard?

Remark 1:
The emoticons are stored as 2 characters each, shown as one emoticon each.
Remark 2:
The emoticons I use are not all accepted on Appetize.

I have not tried this, but I would try setting a Label Width to Automatic, then filling it with text, then checking its width in pixels a bit later, after it had a chance to redraw.

P.S. Thanks for the link to Appetize.io
I was able to upload AI2 .apk files and run them free online, without a local emulator or phone.
The AI2 Companion, however, did not ask for a rendezvous code in that environment.

PPS. My Automatic Width idea failed, I got a constant 160 pixels result regardless of .Text length.

At night, I came up with the idea to determine that text length for 10,20,40 and 80 as only possible Fontsizes but thanks to your idea of automatic width, I should be able to cover that full range (10-80) easily.

:question:

What happens to your approach (which is unclear to me) when FontScale (font/display size is changed in the device settings? I understand neither your "solution" nor the problem?

I was not so clear within the topic.
The solution based on text width I have used is not perfect: it needs some space on the screen.
I have published my code at https://rogonow.itch.io/snaptext.

By the way, I found also that some emoticons are not supported on older Android versions, which is shown as a kind of bug in my appilication, with a rectangle and a cross.

1 Like

It doesn't work on Android 4.3.

None of these can be selected:

(Btw, no colors - it's a real screenshot)

My response was intended to address the typographic problem of deciding whether or not a text string of a given font size would fit into a Label or TextBox without having to wordwrap it onto more than one line.

From what I see in the OP's posted code, he uses a Clock-driven Marquee to bypass the problem.

This problem does not exist for monospace fonts.

Here's what I tested

The hypothesis I tested was regarding the meaning of the Automatic Width attribute value, in regards to run time behavior.

Here's Textbox1, with Automatic Width and Height...

Button1 tests its Width

demo

As demonstrated, the Width value does not change at run time, so it must be determined at screen load time or earlier, dashing my hopes of using it to experiment with typographic features like kerning.

text_width.aia (1.5 KB)

1 Like

Android 4.3 is old. I don't know why you can't select one, although I had a serious bug to select the correct emoticon, which should be solved now for modern Android version(s).
In that Android 4.3, if the emoticon is not found, it shows a small space, unmatching the (invisible) grid to select one. 1 or more have also a smaller size, unmatching the grid too.
My plan is that the user can compose it's own icon grid.

I estimate that making a tutorial for emoticon picklist, isn't worth the effort.

For autowidth, I have used a label with auto Width. After the system was able to adapt the size of that label, I was then able to read that Width in pixels.
Unfortunately, I found a difference in width between my old Android and my new Android. :frowning:

You are right, using an Automatic Width Label with time delay worked.
demo
blocks


text_width.aia (2.0 KB)

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.