Eliminate rounding errors

This commit is contained in:
Rossen Hristov
2016-03-21 13:05:17 +02:00
parent 220cc627d2
commit d80bc5fc81
4 changed files with 34 additions and 11 deletions

View File

@ -723,7 +723,7 @@ export var test_getLocationOnScreen_IsUndefinedWhenNotInTheVisualTree = function
TKUnit.assertNull(label.getLocationOnScreen());
}
var delta = 0.5;
var delta = 0.1;
export var test_getLocationRelativeToOtherView = function () {
var a1 = new absoluteLayoutModule.AbsoluteLayout();
a1.width = 200;

View File

@ -1149,18 +1149,9 @@ export class View extends ProxyObject implements definition.View {
}
public getLocationRelativeTo(otherView: definition.View): definition.Point {
var my = this.getLocationInWindow();
var other = otherView.getLocationInWindow();
if (!my || !other) {
return undefined;
}
return {
x: my.x - other.x,
y: my.y - other.y
}
}
public getActualSize(): definition.Size {
var currentBounds = this._getCurrentLayoutBounds();
if (!currentBounds) {

View File

@ -389,6 +389,23 @@ export class View extends viewCommon.View {
}
}
public getLocationRelativeTo(otherView: viewDefinition.View): viewDefinition.Point {
if (!this._nativeView || !this._nativeView.getWindowToken() ||
!otherView._nativeView || !otherView._nativeView.getWindowToken() ||
this._nativeView.getWindowToken() !== otherView._nativeView.getWindowToken()) {
return undefined;
}
var myArray = (<any>Array).create("int", 2);
this._nativeView.getLocationOnScreen(myArray);
var otherArray = (<any>Array).create("int", 2);
otherView._nativeView.getLocationOnScreen(otherArray);
return {
x: utils.layout.toDeviceIndependentPixels(myArray[0] - otherArray[0]),
y: utils.layout.toDeviceIndependentPixels(myArray[1] - otherArray[1]),
}
}
public static resolveSizeAndState(size: number, specSize: number, specMode: number, childMeasuredState: number): number {
var result = size;
switch (specMode) {

View File

@ -278,6 +278,21 @@ export class View extends viewCommon.View {
}
}
public getLocationRelativeTo(otherView: viewDefinition.View): viewDefinition.Point {
if (!this._nativeView || !this._nativeView.window ||
!otherView._nativeView || !otherView._nativeView.window ||
this._nativeView.window !== otherView._nativeView.window) {
return undefined;
}
var myPointInWindow = this._nativeView.convertPointToView(this._nativeView.bounds.origin, null);
var otherPointInWindow = otherView._nativeView.convertPointToView(otherView._nativeView.bounds.origin, null);
return {
x: utils.layout.toDeviceIndependentPixels(myPointInWindow.x - otherPointInWindow.x),
y: utils.layout.toDeviceIndependentPixels(myPointInWindow.y - otherPointInWindow.y),
}
}
private _onSizeChanged() {
this.style._sizeChanged();
}