I’m trying to get an even border on my button. While in theory easy, I run into a few problems that erk me.
Using scale. If I set the inner of my circle to 0.9, 0, 0.9, 0, yes it creates a nice even border around, but when I say use MouseEnter to increase the size of the original circle, the border becomes bigger (as it’s scaling to the parent object)
Solution, use Offset right? NO! Using an offset of say 14 once again, looks nice, and yes, increasing the size of the circle keeps the border the same size, it creates more problems when on small devices, such as mobile
So my solution/idea was to code in using the AbsoluteSize of the button to set the size of the inner, so it’s a constant size across every single platform
Normally, since the padding is relative to the outer-size, when you increase the outer-size, the padding will also increase to ensure that the ratio of padding to outer-size is conserved. More specifically, when the outer-size is scaled by a factor, the padding will also scale by the same factor:
To offset this, when we change the outer-size, we should inversely change the padding so that the absolute size of the padding stays constant, which can be done by simply scaling by the reciprocal of the scale factor:
From the padding, you can simply find the size of the inner circle by taking 2 padding away from 1 (which represents the full size of outer-size in Scale world):
Here’s what I got in the end kinda, it works for both circles, plus rectangular frames. It uses offset tho. Not sure if there’s a cleaner way to do this however, but it looks good on all screen sizes. Basically I get the players screen size to determine the appropriate border size (that was no matter what size/shape the frame is, the border is continuous amongst all UI elements) and then just take that number from the frames size and boom!
RoundNumber is used purely to turn the number into an even number (so no like 5, 7, 9, etc…) as odd numbers can’t be properly centered
return function(screen, parent)
local BorderSize = screen.AbsoluteSize.X / 100
return UDim2.new(0, RoundNumber(parent.AbsoluteSize.X - BorderSize), 0, RoundNumber(parent.AbsoluteSize.Y - BorderSize))
end
EDIT Nvm, I’m gonna get problems, as I edit the size of the parent frame, but the inner stays the same cause it’s offset anyway to make this with scale then