From 27046b00c6456313c23ba9ecedf9a513c98f0c4e Mon Sep 17 00:00:00 2001 From: NovapaX Date: Thu, 30 Nov 2017 20:20:16 +0100 Subject: [PATCH] Replacing the color picker with a Hue-Saturation color wheel. (#695) * first workable version of a colorwheel * don't stretch it too big smaller screens * better touch/drag behaviour + some properties centralized * changed coordinate system, dragable marker * little tweaks and cleanups * touch drag color tooltip * Segments, color via attribute, throttling, CSS-styling, small fixes * inmproved segment behaviour * styling with css vars/mixins * structuring, commenting and cleanup * properly prevent user select * don't import debounce * settled on some default color segmentation and wheel styling * getting rid of the hidden #wheel element just set css vars on the backgroundLayer and get those via getCumputedStyle * remove the #wheel css declaration too * width is just a stupid word that looks too much like with * move the color circle/tooltip a bit higher * quote all attributes --- src/components/ha-color-picker.html | 638 ++++++++++++++++++++++++---- src/more-infos/more-info-light.html | 48 ++- 2 files changed, 577 insertions(+), 109 deletions(-) diff --git a/src/components/ha-color-picker.html b/src/components/ha-color-picker.html index e9f5a748f7..a92262a5ba 100644 --- a/src/components/ha-color-picker.html +++ b/src/components/ha-color-picker.html @@ -5,148 +5,612 @@ diff --git a/src/more-infos/more-info-light.html b/src/more-infos/more-info-light.html index a5f7637e01..ec753f794d 100644 --- a/src/more-infos/more-info-light.html +++ b/src/more-infos/more-info-light.html @@ -31,10 +31,10 @@ ha-color-picker { display: block; - width: 250px; + width: 100%; max-height: 0px; - overflow: hidden; + overflow: visible; transition: max-height .2s ease-in; } @@ -46,7 +46,12 @@ } .has-rgb_color ha-color-picker { - max-height: 200px; + max-height: 500px; + --ha-color-picker-wheel-borderwidth: 5; + --ha-color-picker-wheel-bordercolor: white; + --ha-color-picker-wheel-shadow: none; + --ha-color-picker-marker-borderwidth: 2; + --ha-color-picker-marker-bordercolor: white; } paper-item { @@ -89,7 +94,13 @@ on-change='wvSliderChanged'> - + @@ -136,6 +147,10 @@ type: Number, value: 0, }, + + colorPickerColor: { + type: Object, + } }; } @@ -144,6 +159,7 @@ this.brightnessSliderValue = newVal.attributes.brightness; this.ctSliderValue = newVal.attributes.color_temp; this.wvSliderValue = newVal.attributes.white_value; + this.colorPickerColor = this.rgbArrToObj(newVal.attributes.rgb_color); if (newVal.attributes.effect_list) { this.effectIndex = newVal.attributes.effect_list.indexOf(newVal.attributes.effect); @@ -237,29 +253,17 @@ }); } + rgbArrToObj(rgbArr) { + return { r: rgbArr[0], g: rgbArr[1], b: rgbArr[2] }; + } + /** - * Called when a new color has been picked. We will not respond to every - * color pick event but have a pause between requests. + * Called when a new color has been picked. + * should be throttled with the 'throttle=' attribute of the color picker */ colorPicked(ev) { - if (this.skipColorPicked) { - this.colorChanged = true; - return; - } - this.color = ev.detail.rgb; - this.serviceChangeColor(this.hass, this.stateObj.entity_id, this.color); - - this.colorChanged = false; - this.skipColorPicked = true; - - this.colorDebounce = setTimeout(function () { - if (this.colorChanged) { - this.serviceChangeColor(this.hass, this.stateObj.entity_id, this.color); - } - this.skipColorPicked = false; - }.bind(this), 500); } }