@Override public void setPosition (float x, float y) { Root root = root(); if (root != null) { Scale scale = root.iface.plat.graphics().scale(); if (hrange.active()) x = scale.roundToNearestPixel(x); if (vrange.active()) y = scale.roundToNearestPixel(y); } Scroller.this.content.layer.setTranslation(x, y); } };
/** * Does whatever this element needs to validate itself. This may involve recomputing * visualizations, or laying out children, or anything else. */ protected void validate () { if (!isSet(Flag.VALID)) { // prior to laying ourselves out, ensure that our visual boundaries fall on physical // pixels; this avoids rendering artifacts on devices where the scale factor between // virtual and physical pixels is non-integral Root root = root(); if (root != null) { Scale scale = root.iface.plat.graphics().scale(); float x = layer.tx(), y = layer.ty(); float rx = scale.roundToNearestPixel(x), ry = scale.roundToNearestPixel(y); float rr = scale.roundToNearestPixel(x + _size.width); float rb = scale.roundToNearestPixel(y + _size.height); layer.setTranslation(rx, ry); _size.setSize(rr-rx, rb-ry); } // now that our boundaries are adjusted, we can layout our children (if any) layout(); set(Flag.VALID, true); wasValidated(); } }