From 37a3c9b59c8e3d73bc4a53afed58877eb5efc245 Mon Sep 17 00:00:00 2001 From: Matthew Dapena-Tretter Date: Thu, 23 Mar 2017 11:04:52 -0700 Subject: [PATCH] Measure toggle button size instead of hardcoding it --- src/dock.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/dock.js b/src/dock.js index 0908d8311..7ddc55883 100644 --- a/src/dock.js +++ b/src/dock.js @@ -290,16 +290,16 @@ module.exports = class Dock { // The area used when detecting "leave" events is actually larger than when detecting entrances. if (includeButtonWidth) { const hoverMargin = 20 - const toggleButtonSize = 50 / 2 // This needs to match the value in the CSS. + const {width, height} = this.toggleButton.getSize() switch (this.location) { case 'right': - bounds.left -= toggleButtonSize + hoverMargin + bounds.left -= width + hoverMargin break case 'bottom': - bounds.top -= toggleButtonSize + hoverMargin + bounds.top -= height + hoverMargin break case 'left': - bounds.right += toggleButtonSize + hoverMargin + bounds.right += width + hoverMargin break } } @@ -481,6 +481,13 @@ class DockToggleButton { return this.element } + getSize () { + if (this.size == null) { + this.size = this.element.getBoundingClientRect() + } + return this.size + } + destroy () { this.innerElement.removeEventListener('click', this.handleClick) this.innerElement.removeEventListener('dragenter', this.handleDragEnter)