[demo] Mouse demo: Fix issues with box rendering

pull/1/head
cpsdqs 7 years ago
parent d987f504a2
commit 336849a9bb
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 5
      js/term/demo.js

@ -813,7 +813,7 @@ let demoshIndex = {
} }
} }
getBoxAt (x, y) { getBoxAt (x, y) {
let boxes = this.boxes.reverse() // top to bottom, like drawing order let boxes = this.boxes.slice().reverse() // top to bottom, like drawing order
for (let box of boxes) { for (let box of boxes) {
if (box.x <= x && box.x + box.width > x && box.y <= y && box.y + box.height > y) { if (box.x <= x && box.x + box.width > x && box.y <= y && box.y + box.height > y) {
return box return box
@ -836,7 +836,8 @@ let demoshIndex = {
if (box) { if (box) {
this.grabbedBox = box this.grabbedBox = box
this.grabOffset = [box.x - x, box.y - y] this.grabOffset = [box.x - x, box.y - y]
this.render() // move grabbed box to top of stack
this.boxes.push(...this.boxes.splice(this.boxes.indexOf(box), 1))
} }
} }
this.render() this.render()

Loading…
Cancel
Save