Kuix 焦点跳转问题

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;
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值