final double definedElementX = styleSheet.getDoubleStyleProperty(ElementStyleKeys.POS_X, 0);
// this is where I want the element on a global scale...
final long targetPositionX = elementX[i] + dx;
final Element parent = element.getParentSection();
final CachedLayoutData parentData = ModelUtility.getCachedLayoutData(parent);
final long layoutedParentX = parentData.getX();
if (targetPositionX < layoutedParentX)
{
continue;
}
// this is what we used to apply to POS_X
final long computedPositionX;
if (definedElementX >= 0)
{
// absolute position; resolving is easy here
final long snapPosition = horizontalSnapModel.getNearestSnapPosition(targetPositionX, element.getObjectID());
if (Math.abs(snapPosition - targetPositionX) > SNAP_THRESHOLD)
{
computedPositionX = targetPositionX;
final long localXPosition = Math.max(0, targetPositionX - layoutedParentX);
final float position = (float) StrictGeomUtility.toExternalValue(localXPosition);
styleSheet.setStyleProperty(ElementStyleKeys.POS_X, new Float(position));
}
else
{
computedPositionX = snapPosition;
final long localXPosition = Math.max(0, snapPosition - layoutedParentX);
final float position = (float) StrictGeomUtility.toExternalValue(localXPosition);
styleSheet.setStyleProperty(ElementStyleKeys.POS_X, new Float(position));
}
}
else
{
final long parentBase = parentData.getWidth();
if (parentBase > 0)
{
// relative position; resolve the percentage against the width of the parent.
final long snapPosition = horizontalSnapModel.getNearestSnapPosition(targetPositionX, element.getObjectID());
if (Math.abs(snapPosition - targetPositionX) > SNAP_THRESHOLD)
{
computedPositionX = targetPositionX;
final long localXPosition = Math.max(0, targetPositionX - layoutedParentX);
// strict geometry: all values are multiplied by 1000
// percentages in the engine are represented by floats betwen 0 and 100.
final long percentage = localXPosition * (1000 * 100) / parentBase;
styleSheet.setStyleProperty(ElementStyleKeys.POS_X,
new Float(StrictGeomUtility.toExternalValue(-percentage)));
}
else
{
computedPositionX = snapPosition;
final long localXPosition = Math.max(0, snapPosition - layoutedParentX);
// strict geometry: all values are multiplied by 1000
// percentages in the engine are represented by floats betwen 0 and 100.
final long percentage = localXPosition * (1000 * 100) / parentBase;
styleSheet.setStyleProperty(ElementStyleKeys.POS_X,
new Float(StrictGeomUtility.toExternalValue(-percentage)));
}
}
else
{
// we cannot handle this element.
continue;
}
}
final double elementMinWidth = styleSheet.getDoubleStyleProperty(ElementStyleKeys.MIN_WIDTH, 0);
final long targetX2 = elementX[i] + elementWidth[i];
if (elementMinWidth >= 0)
{
final long localWidth = Math.max(0, targetX2 - computedPositionX);
final float position = (float) StrictGeomUtility.toExternalValue(localWidth);
styleSheet.setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(position));
}
else
{
final long parentBase = parentData.getWidth();
if (parentBase > 0)
{
final long localWidth = Math.max(0, targetX2 - computedPositionX);
// strict geometry: all values are multiplied by 1000
// percentages in the engine are represented by floats betwen 0 and 100.