-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Use supported_color_modes to determine what UI elements to show
#8961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
230e312
Use `supported_color_modes` to determine what to UI to show
bramkragten 2f12ffc
Rename
bramkragten eeeef78
Color modes can also be dimmed
bramkragten f5cddd4
Update light.ts
bramkragten 0619290
lint
bramkragten e9d8396
Use the new modes and service calls
bramkragten 3e77b3e
lint
bramkragten 2c0b7ce
Fix rgb adjustment
bramkragten aeddd11
Update more-info-light.ts
bramkragten 3168d9b
Fixes
bramkragten ca9a997
Update more-info-light.ts
bramkragten 80d84df
Update more-info-light.ts
bramkragten 5ed64b4
Use rgb instead of hs to display colors
bramkragten 980b1ea
Remove log
bramkragten c2af97b
Update more-info-light.ts
bramkragten 2ef0be6
Review comments
bramkragten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { html } from "@polymer/polymer/lib/utils/html-tag"; | |
| /* eslint-plugin-disable lit */ | ||
| import { PolymerElement } from "@polymer/polymer/polymer-element"; | ||
| import { EventsMixin } from "../mixins/events-mixin"; | ||
|
|
||
| import { rgb2hs } from "../common/color/convert-color"; | ||
| /** | ||
| * Color-picker custom element | ||
| * | ||
|
|
@@ -114,6 +114,12 @@ class HaColorPicker extends EventsMixin(PolymerElement) { | |
| observer: "applyHsColor", | ||
| }, | ||
|
|
||
| // use these properties to update the state via attributes | ||
| desiredRgbColor: { | ||
| type: Object, | ||
| observer: "applyRgbColor", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. observer 😱 |
||
| }, | ||
|
|
||
| // width, height and radius apply to the coordinates of | ||
| // of the canvas. | ||
| // border width are relative to these numbers | ||
|
|
@@ -177,8 +183,11 @@ class HaColorPicker extends EventsMixin(PolymerElement) { | |
| this.drawMarker(); | ||
|
|
||
| if (this.desiredHsColor) { | ||
| this.setMarkerOnColor(this.desiredHsColor); | ||
| this.applyColorToCanvas(this.desiredHsColor); | ||
| this.applyHsColor(this.desiredHsColor); | ||
| } | ||
|
|
||
| if (this.desiredRgbColor) { | ||
| this.applyRgbColor(this.desiredRgbColor); | ||
| } | ||
|
|
||
| this.interactionLayer.addEventListener("mousedown", (ev) => | ||
|
|
@@ -282,12 +291,13 @@ class HaColorPicker extends EventsMixin(PolymerElement) { | |
| processUserSelect(ev) { | ||
| const canvasXY = this.convertToCanvasCoordinates(ev.clientX, ev.clientY); | ||
| const hs = this.getColor(canvasXY.x, canvasXY.y); | ||
| this.onColorSelect(hs); | ||
| const rgb = this.getRgbColor(canvasXY.x, canvasXY.y); | ||
| this.onColorSelect(hs, rgb); | ||
| } | ||
|
|
||
| // apply color to marker position and canvas | ||
| onColorSelect(hs) { | ||
| this.setMarkerOnColor(hs); // marker always follows mounse 'raw' hs value (= mouse position) | ||
| onColorSelect(hs, rgb) { | ||
| this.setMarkerOnColor(hs); // marker always follows mouse 'raw' hs value (= mouse position) | ||
| if (!this.ignoreSegments) { | ||
| // apply segments if needed | ||
| hs = this.applySegmentFilter(hs); | ||
|
|
@@ -301,21 +311,21 @@ class HaColorPicker extends EventsMixin(PolymerElement) { | |
| // eventually after throttle limit has passed | ||
| clearTimeout(this.ensureFinalSelect); | ||
| this.ensureFinalSelect = setTimeout(() => { | ||
| this.fireColorSelected(hs); // do it for the final time | ||
| this.fireColorSelected(hs, rgb); // do it for the final time | ||
| }, this.throttle); | ||
| return; | ||
| } | ||
| this.fireColorSelected(hs); // do it | ||
| this.fireColorSelected(hs, rgb); // do it | ||
| this.colorSelectIsThrottled = true; | ||
| setTimeout(() => { | ||
| this.colorSelectIsThrottled = false; | ||
| }, this.throttle); | ||
| } | ||
|
|
||
| // set color values and fire colorselected event | ||
| fireColorSelected(hs) { | ||
| fireColorSelected(hs, rgb) { | ||
| this.hsColor = hs; | ||
| this.fire("colorselected", { hs: { h: hs.h, s: hs.s } }); | ||
| this.fire("colorselected", { hs, rgb }); | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -363,6 +373,11 @@ class HaColorPicker extends EventsMixin(PolymerElement) { | |
| this.applyColorToCanvas(hs); | ||
| } | ||
|
|
||
| applyRgbColor(rgb) { | ||
| const [h, s] = rgb2hs(rgb); | ||
| this.applyHsColor({ h, s }); | ||
| } | ||
|
|
||
| /* | ||
| * input processing helpers | ||
| */ | ||
|
|
@@ -395,6 +410,15 @@ class HaColorPicker extends EventsMixin(PolymerElement) { | |
| return { h: hue, s: sat }; | ||
| } | ||
|
|
||
| getRgbColor(x, y) { | ||
| // get current pixel | ||
| const imageData = this.backgroundLayer | ||
| .getContext("2d") | ||
| .getImageData(x + 250, y + 250, 1, 1); | ||
| const pixel = imageData.data; | ||
| return { r: pixel[0], g: pixel[1], b: pixel[2] }; | ||
| } | ||
|
|
||
| applySegmentFilter(hs) { | ||
| // apply hue segment steps | ||
| if (this.hueSegments) { | ||
|
|
@@ -468,7 +492,7 @@ class HaColorPicker extends EventsMixin(PolymerElement) { | |
| .getPropertyValue("--wheel-bordercolor") | ||
| .trim(); | ||
| const wheelShadow = wheelStyle.getPropertyValue("--wheel-shadow").trim(); | ||
| // extract shadow properties from CCS variable | ||
| // extract shadow properties from CSS variable | ||
| // the shadow should be defined as: "10px 5px 5px 0px COLOR" | ||
| if (wheelShadow !== "none") { | ||
| const values = wheelShadow.split("px "); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.