如何避免CN1中的拖放痕迹

时间:2019-05-19 15:31:13

标签: codenameone

正如您在下面的动画中看到的那样,拖动会导致我不想要的痕迹。此外,拖动的分量垂直移动绘制。我想这与状态栏有关。但是我又如何避免这种情况呢?

enter image description here

这是我的代码:

class LockScreen: GenLockScreen() {

    var triggerOnUnlock: (() -> Unit)? = null

    override fun initComponent() {


        val draggable = StraightDraggableLabel(gui_Unlocker)
        replace(gui_Unlocker, draggable, null)

        gui_Unlocker = draggable
        gui_Unlocker.preferredSize = Dimension(gui_UnlockTarget.preferredW, gui_SlideArea.height)

        revalidate()

        // dragging

        draggable.apply {
            isVDragEnabled = false
            dragMinX = draggable.x
            dragMaxX = gui_SlideArea.x + gui_SlideArea.width
        }


        gui_UnlockTarget.isDropTarget = true
        gui_Unlocker.isDraggable = true
        gui_Unlocker.addDragOverListener {

            val overlap =  (gui_Unlocker.draggedx + gui_Unlocker.width) - gui_UnlockTarget.x
            val overlapRatio = overlap / gui_Unlocker.width.toDouble()

            if(overlapRatio >= 0.75) triggerOnUnlock?.invoke()
        }
    }
}


class StraightDraggableLabel(var isHDragEnabled: Boolean = true, var isVDragEnabled: Boolean = true): Label() {

    var dragMinX = Int.MIN_VALUE
    var dragMaxX = Int.MAX_VALUE
    var dragMinY = Int.MIN_VALUE
    var dragMaxY = Int.MAX_VALUE

    constructor(label: Label): this() {
        uiid = label.uiid
        text = label.text
        icon = label.icon
    }

    override fun getDragImage() = toImage()!!

    override fun drawDraggedImage(g: Graphics, img: Image, x: Int, y: Int) {
        //super.drawDraggedImage(g, img, x, y)
        val dX = if(isHDragEnabled) MathUtils.clamp(dragMinX, dragMaxX - img.width, x) else this.x
        val dY = if(isVDragEnabled) MathUtils.clamp(dragMinY, dragMaxY - img.height, y) else this.y

        g.drawImage(img, dX, dY)
    }
}

我省略了设计师特定的文件/类。

拖动的绿色组件的样式为css:

LockScreenUnlocker {
  background-color: #00a87f;
  border-radius: 2mm;
  text-align: center;
  color: white;
  font-size: large;
  padding: 0;
  margin: 0;
}

0 个答案:

没有答案