I'm making some kind of system to navigate through pages, looks like the image below.

When trying to anchor everything to be responsible to screen size and work on tablets with different resolutions (which is what I need) I found out that anchoring each object to it's parent and setting the anchor to 'Set to Current Position' works fine.
What I would like to know is if there's any kind of way to imitate UIWidget's anchor's 'Set to Current Position' functionality by code, as most of the elements are created dynamically calling a function that does that would be really helpfull.
I've digged the code and ended up in UIRectEditor at this point:
// "Set to Current" choice
if (newOrigin == 4)
{
newOrigin = 3;
Vector3[] sides = targetRect.GetSides(myRect.cachedTransform);
float f0, f1;
if (IsHorizontal[index])
{
f0 = sides[0].x;
f1 = sides[2].x;
}
else
{
f0 = sides[3].y;
f1 = sides[1].y;
}
// Final position after both relative and absolute values are taken into consideration
float final = Mathf.Floor(0.5f + Mathf.Lerp(0f, f1 - f0, rel.floatValue) + abs.intValue);
rel.floatValue = final / (f1 - f0);
abs.intValue = 0;
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
}
But I don't know how to turn it into a method I can use.