• Create Account

### #Actualhaegarr

Posted 29 October 2013 - 08:26 AM

If I understand your code snippet correctly, then this part

                anchor = value;

// get the canvas resolution so we can recalc position
if (OnAnchorChanged != null)
res = OnAnchorChanged(this);

// recalc the pos units to keep the widget in the same location given this new anchor selection
int _x = XUnitsToPixels(res);
int _y = YUnitsToPixels(res);

// x & y are member variables that are in units
x = _SetPixelX(_x, res);
y = _SetPixelY(_y, res);


                // get the canvas resolution so we can recalc position
if (OnAnchorChanged != null)
res = OnAnchorChanged(this);

// recalc the pos units to keep the widget in the same location given this new anchor selection
int _x = XUnitsToPixels(res);
int _y = YUnitsToPixels(res);

anchor = value;

// x & y are member variables that are in units
x = _SetPixelX(_x, res);
y = _SetPixelY(_y, res);


in order to ensure that at the moment where the pixel position is calculated the now obsolete anchor is used. Just after that the anchor is allowed to be switched to the new one, and that one has to be used to re-calculate the new relative position.

However, make sure that an initial anchor is correctly set-up, or else the first invocation of the setter will fail.

### #1haegarr

Posted 29 October 2013 - 08:25 AM

If I understand your code snippet correctly, then this part

                anchor = value;

// get the canvas resolution so we can recalc position
if (OnAnchorChanged != null)
res = OnAnchorChanged(this);

// recalc the pos units to keep the widget in the same location given this new anchor selection
int _x = XUnitsToPixels(res);
int _y = YUnitsToPixels(res);

// x & y are member variables that are in units
x = _SetPixelX(_x, res);
y = _SetPixelY(_y, res);


                // get the canvas resolution so we can recalc position
if (OnAnchorChanged != null)
res = OnAnchorChanged(this);

// recalc the pos units to keep the widget in the same location given this new anchor selection
int _x = XUnitsToPixels(res);
int _y = YUnitsToPixels(res);

anchor = value;

// x & y are member variables that are in units
x = _SetPixelX(_x, res);
y = _SetPixelY(_y, res);


in order to ensure that at the moment where the pixel position is calculated the now obsolete anchor is used. Just after that the anchor is allowed to be switched to the new one, and that one has to be used to re-calculate the new relative position.

However, make sure that an initial anchor is correctly set-up, or else the first invocation of the setter will fail.

PARTNERS