-
Notifications
You must be signed in to change notification settings - Fork 80
fix(color-picker): alpha-channel slider scope updates to reflect current opacity #8700
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
Changes from 2 commits
92749d6
c98fbfe
d76bf68
afb7c34
fb37c29
2a5b1b8
a3f23a5
a7245a0
4d9f710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,16 @@ import { | |
} from "@stencil/core"; | ||
|
||
import Color from "color"; | ||
import { Channels, ColorMode, ColorValue, HSLA, HSVA, InternalColor, RGBA } from "./interfaces"; | ||
import { | ||
Channels, | ||
ColorMode, | ||
ColorValue, | ||
HSLA, | ||
HSVA, | ||
InternalColor, | ||
RGBA, | ||
SliderType, | ||
} from "./interfaces"; | ||
import { throttle } from "lodash-es"; | ||
import { Direction, getElementDir, isPrimaryPointerButton } from "../../utils/dom"; | ||
import { Scale } from "../interfaces"; | ||
|
@@ -1376,13 +1385,14 @@ export class ColorPicker | |
|
||
const x = hsvColor.saturationv() / (HSV_LIMITS.s / width); | ||
const y = height - hsvColor.value() / (HSV_LIMITS.v / height); | ||
const sliderType = "colorField"; | ||
|
||
requestAnimationFrame(() => { | ||
this.colorFieldScopeLeft = x; | ||
this.colorFieldScopeTop = y; | ||
}); | ||
|
||
this.drawThumb(this.colorFieldRenderingContext, radius, x, y, hsvColor); | ||
this.drawThumb(this.colorFieldRenderingContext, radius, x, y, hsvColor, sliderType); | ||
} | ||
|
||
private drawThumb( | ||
|
@@ -1391,6 +1401,7 @@ export class ColorPicker | |
x: number, | ||
y: number, | ||
color: Color, | ||
sliderType: SliderType, | ||
): void { | ||
const startAngle = 0; | ||
const endAngle = 2 * Math.PI; | ||
|
@@ -1400,14 +1411,28 @@ export class ColorPicker | |
context.arc(x, y, radius, startAngle, endAngle); | ||
context.fillStyle = "#fff"; | ||
context.fill(); | ||
|
||
context.strokeStyle = "rgba(0,0,0,0.3)"; | ||
context.lineWidth = outlineWidth; | ||
context.stroke(); | ||
|
||
const pattern = context.createPattern(this.getCheckeredBackgroundPattern(), "repeat"); | ||
Elijbet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
context.beginPath(); | ||
context.arc(x, y, radius - 3, startAngle, endAngle); | ||
context.fillStyle = pattern; | ||
Elijbet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
context.fill(); | ||
|
||
context.globalCompositeOperation = "source-atop"; | ||
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. Noice! I was not aware of this prop. Will need to add it to the toolbox. ✨🧰✨ 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. Yeah, it's layering operations, photoshop style. Here is a playground: https://www.w3schools.com/jsref/playcanvas.php?filename=playcanvas_globalcompop&preval=source-atop |
||
|
||
context.beginPath(); | ||
context.arc(x, y, radius - 3, startAngle, endAngle); | ||
context.fillStyle = color.rgb().alpha(1).string(); | ||
sliderType === "opacity" | ||
Elijbet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
? (context.fillStyle = color.rgb().alpha(color.alpha()).string()) | ||
: (context.fillStyle = color.rgb().alpha(1).string()); | ||
context.fill(); | ||
|
||
context.globalCompositeOperation = "source-over"; | ||
} | ||
|
||
private drawActiveHueSliderColor(): void { | ||
|
@@ -1429,12 +1454,13 @@ export class ColorPicker | |
const x = hsvColor.hue() / (HUE_LIMIT_CONSTRAINED / width); | ||
const y = radius; | ||
const sliderBoundX = this.getSliderBoundX(x, width, radius); | ||
const sliderType = "hue"; | ||
|
||
requestAnimationFrame(() => { | ||
this.hueScopeLeft = sliderBoundX; | ||
}); | ||
|
||
this.drawThumb(this.hueSliderRenderingContext, radius, sliderBoundX, y, hsvColor); | ||
this.drawThumb(this.hueSliderRenderingContext, radius, sliderBoundX, y, hsvColor, sliderType); | ||
} | ||
|
||
private drawHueSlider(): void { | ||
|
@@ -1584,12 +1610,20 @@ export class ColorPicker | |
const x = alphaToOpacity(hsvColor.alpha()) / (OPACITY_LIMITS.max / width); | ||
const y = radius; | ||
const sliderBoundX = this.getSliderBoundX(x, width, radius); | ||
const sliderType = "opacity"; | ||
|
||
requestAnimationFrame(() => { | ||
this.opacityScopeLeft = sliderBoundX; | ||
}); | ||
|
||
this.drawThumb(this.opacitySliderRenderingContext, radius, sliderBoundX, y, hsvColor); | ||
this.drawThumb( | ||
this.opacitySliderRenderingContext, | ||
radius, | ||
sliderBoundX, | ||
y, | ||
hsvColor, | ||
sliderType, | ||
); | ||
} | ||
|
||
private getSliderBoundX(x: number, width: number, radius: number): number { | ||
|
Uh oh!
There was an error while loading. Please reload this page.