Pinpointing the absolute position of a certain letter/point within the text property of a wrapped TextLabel

For further explaining on what I mean by the title. My issue is as follows; I want to be able to find the absolute position of a certain point within a wrapped text label in which I can then place something such as an emoji in the blank spot I parse into the message. Here’s a simple example of what I mean:

I want to put an emoji for example into the blank spot on the 2nd line. Like I said in the image above, it’s not a problem if it’s only 1 line and this is why:
The current process I go through for determining what the absolute position of that space is in order to place something there is this: I get the font size, I calculate the size in pixels for a space with that font size and font, I determine the needed number of spaces (Font size / Space size [x]), then I search within the text to find thing such as :happy: or :sad:, from that we get the start and end indexes for the first found result, it then get’s the textlabel’s TextBounds and sets the position of the emoji like so:
Emoji.Position = UDim2.new(0, Bounds.X, 0, Bounds.Y - fontSize)
And finally, it get’s the first part of the message, adds in the number of spaces calculated earlier onto the first part and then adds on the end which leaves you with a message that has replaced the :happy: (for example) with enough space for an emoji and an emoji has been placed in those spaces. This works only if the text doesn’t wrap. But I want the text to wrap so if TextBounds doesn’t get the job done then what do I do. This is where I got stumped and couldn’t figure out a way to do it since if I use TextBounds if it’s on the 2nd+ line of text then it simply just places the emoji all the way to the right, completely misplaced because it can’t calculate it correctly since it’s 2 lines. Hopefully you understand what I’m trying to say and even more hopefully you can think of a solution/work around for this. I’ve tried a few things but nothing has worked out. Is there a better way to find the absolute position of a certain letter/point within a wrapped textlabel’s text property?

(Basically a fancy way of asking, "how do I properly embed things into a TextLabel's text property?")

What I did is make an individual TextLabel inside a Frame (which holds the whole message) for each word. This allows you to change the size of it if you want to replace the word with an image or something else- and gives you more control of what the chat looks like.

Of course this would require you to do your own text wrapping, but in the end I think it is very much worth it.

1 Like

Ehh, I’m looking for a more “hacky” solution so that I can still have it just as 1 TextLabel.

2 Likes

Could you not make use a of a long string to achieve this?

local emojiInString = [[This is a long string, I would like the emoji to be the first character of the next newline
🤡 just like that!]]
1 Like

bumping this question. Anyone have a solution for this?

Been looking around into overhauling my chat system to add custom emojis, and I’m still unsure about going the route of “one text per label”, Has anyone looked into this?