Let’s say you have a TextButton and you want to add an icon next to it.
Example in the devforum:
In this tutorial i’ll show you how to do it.
Right here i have a basic TextButton in the center of my screen
Let’s add a ImageLabel in the TextButton
Now Set the following Properties (! is required and nothing is optional):
- !SizeConstraint: YY (the default XX distorts the image)
- Size: {0, 32},{0, 32} (set to {1, 0},{1, 0} to cover the whole box)
- !BackgroundTransparency: 1
- Image: rbxassetid://9880531433 (it’s a plus icon, you may change it)
- !AnchorPoint: 1, 0.5 (i’ll explain later why it’s 1, 0.5 and not 0.5, 0.5)
- !Position: {0.5, 0},{0.5, 0} (centers the image)
After applying the properties you should have this
As you can see it’s not perfect yet.
Now let’s look into the TextButton’s properties
TextBounds? What’s that?
TextBounds is the width and the height of the text.
Here is a line with a length 36 pixels (the first number in text bounds)
How is that relevant?
Since we want to put the icon on the left side of the text.
We can use the TextBounds to get our desired position for the icon
The Middle of Text - Half the width of the Text = Left side of the Text
Therefore we need to put our icon 18 px to the left of the middle of the text
The AnchorPoint is set to 1, 0.5 because if we used 0.5, 0.5 it would give us this at the end
The “Last” Step is to set the position of the icon to
{0.5, -18},{0.5, 0}
(The -18 put sour icon 18 px to the left of the middle of the text)
The “Final” Result:
But does it look a little too close?
No Problem just change the position to one of the following:
{0.5, -23},{0.5, 0} (5 pixel more left)
{0.5, -28},{0.5, 0} (10 pixel more left)
{0.5, -33},{0.5, 0} (15 pixel more left)
It also works with padding and TextScaled
But make sure to set PaddingLeft to the width of your icon