`UDim` `Scale` and `Offset`, order of operations

I can’t find the specification of the order of the operations of scaling and offsetting for UDim. I suspect it might be left to the client Instance to choose. I could test this but that’s no guarantee it would hold true for all components.

Is the order of the Scale and Offset specified somewhere?

For example, consider the resulting width of a sub component in a Frame of 500 pixels:

local height = 100
UDim2.new(0.8, -20, 0, height - 20)

This would be 380 pixels if the scale operation applied before the offset.

If the offset applied first, then we’d have 0.8 * 480 pixels = 384. A subtle difference that would be easy to overlook, initially.

1 Like

If I’m interpreting your question correct:

Scale is calculated first, then offset is added afterwards (hence why it is an offset)

width_in_pixels = scale * parent_width_in_pixels + offset = offset + scale * parent_width_in_pixels, so order doesn’t matter.

400 - 20 = 380
-20 + 400 = 380

same thing

1 Like

That was not what I asked and demonstrated:

width_in_pixels = scale * parent_width_in_pixels + offset

380 = 0.8 * 500 - 20

vs

width_in_pixels = scale * (parent_width_in_pixels + offset)

384 = 0.8 * (500 - 20)

A solution is to make scaling and offset distinct operations with distinct GUI elements for each.

If I need an offset from an 80% frame size, then I must add an otherwise invisible and useless 80% scaled frame, then I can take an offset from that using full scaling (of 1). That way I know my offset is always what I expect:

offset * 1 == offset

If I need an offset by 20 pixels (eg a 9-slice fixed border) and then need to apply scaling for, eg a “rage meter”. Then I make a frame with the 20 pixel offset and use percentage scaling in its child image(label).

Algebra and maintenance no longer a problem :melting_face:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.