How do I put an icon after a dynamic textlabel?

I need an icon to be placed after (on the right of) someone’s username on a playerlist. I’ve looked at using textbounds but it returns 0 and GetTextSize returns the same value every time even if the username is 10000000 letters long.

Example:
image

can’t you just manually align it? then clone that template for every player?

No, as the username isn’t always 5 letters, it would overlap the username.

Why not use TextScaled for that?

I am using textscaled, but some names are shorter and won’t reach the icon.

Set the TextXAlignment to “Right”, it does a cool thing where it won’t go out of the text label, it sizes differently

I need the username left-alligned to be on the left side.
image

1 Like

I don’t think this could be avoided without using scripts? not an expert in UI’s so I’m not sure if there’s an Instance for UI that can help you, but you can probably use a script to calculate the text’s current size then try to offset the Icon on the end?

I am using scripts for it, just wondering how to go about doing that. That’s why the category is Scripting Support haha.

Ah, anyways I suck at math myself :skull:, but there’s a TextBounds property that you can maybe start with.

As said in the thread original post I’ve tried using it to no success

Actually I just tried and it wasn’t that complicated at all, you just set the x position of the Icon to the TextBounds.X of the textlabel.

3 Likes

Will try that, thank you very much!

1 Like

Hi,

Here’s a solution, that you could use.

Have a ParentFrame.
Insert a UIList object.
Inside that ParentFrame, insert the TextLabel that contains the name of the player, and the Icon.
Set the TextLabel LayoutOrder to be 1, and the icon LayoutOrder to be 2.

The icon should align itself correctly all the time.

2 Likes