Kuix的焦点跳转有点奇怪,按左右键移动到屏幕最右边的控件后,会自动跳到下一个容器里面的控件,而且不是第一个控件,是离当前控件距离最近的控件。如果我们要下移到第一个控件,上移到最后一个控件,代码修改如下
private boolean isNearest(Widget originWidget, Widget nearestWidget, Alignment direction) {
if (originWidget != null && direction != null) {
int origX = originWidget.getDisplayX() + originWidget.visualCenterX;
int origY = originWidget.getDisplayY() + originWidget.visualCenterY;
int dx = getDisplayX() + visualCenterX - origX;
int dy = getDisplayY() + visualCenterY - origY;
if (nearestWidget != null) {
int nearestDx = nearestWidget.getDisplayX() + nearestWidget.visualCenterX - origX;
int nearestDy = nearestWidget.getDisplayY() + nearestWidget.visualCenterY - origY;
if (direction.isTop() || direction.isBottom()) {
if (Math.abs(dy) <= Math.abs(nearestDy) && dy != 0 && (direction.isBottom() && dy > 0 || direction.isTop() && dy < 0)) {
if (Math.abs(dx) <= Math.abs(nearestDx)) {
//修改这行就行了
//return Math.abs(dx) + Math.abs(dy) < Math.abs(nearestDx) + Math.abs(nearestDy);
return Math.abs(dx) + Math.abs(dy) > Math.abs(nearestDx) + Math.abs(nearestDy);
}
}
} else {
if (Math.abs(dx) <= Math.abs(nearestDx) && dx != 0 && (direction.isRight() && dx > 0 || direction.isLeft() && dx < 0)) {
if (Math.abs(dy) <= Math.abs(nearestDy)) {
return Math.abs(dx) + Math.abs(dy) < Math.abs(nearestDx) + Math.abs(nearestDy);
}
}
}
} else {
if (direction.isTop() || direction.isBottom()) {
return dy != 0 && (direction.isBottom() && dy > 0 || direction.isTop() && dy < 0);
} else {
return dx != 0 && (direction.isRight() && dx > 0 || direction.isLeft() && dx < 0);
}
}
}
return false;
}