UI editor calculates size and position incorrectly

When you select a piece of UI in studio it highlights it such that it shows you guide numbers representing the absolute position (relative to its parent) and the absolute size.

These numbers are wrong. If we take a screenshot of this same image and put it into a photo editor we’ll see that the top right corner starts at (358, 257) and the size is (308, 510).

If you want to reproduce the exact screenshot: The dimensions of the white frame are UDim2.fromScale(0.3, 0.499) centered in an “Actual resolution” 1024 x 1024 emulated device.

Expected behavior

I believe the calculation is simply flooring the values, but as far as I can tell it’s a little more complex than that. Instead, this is how I believe it actually should work.

local function rectFromAbs(position: Vector2, size: Vector2)
	local px = math.round(position.X)
	local py = math.round(position.Y)

	local sx = math.ceil(math.floor(position.X) + size.X - px)
	local sy = math.ceil(math.floor(position.Y) + size.Y - py)

	return Rect.new(px, py, px + sx, py + sy)
end
2 Likes