-
Notifications
You must be signed in to change notification settings - Fork 54
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
Color alpha support #19
Comments
No, at the moment alpha values are going to get chopped off the end of a hex string. It would be nice if the GUI "ignored" the last two characters and passed them along like you describe, I'll consider adding that. Adding a separate alpha slider for an Object or Array based color is pretty straightforward, but it's admittedly annoying for an let color;
const obj = { rgb: '#aabbcc', alpha: 1 };
gui.addColor( obj, 'rgb' ).onChange( update );
gui.add( obj, 'alpha', 0, 1 ).onChange( update );
update();
function update() {
color = obj.rgb + Math.round( obj.alpha * 0xff ).toString( 16 ).padStart( 2, 0 );
}; Hope that gets you by for now. I'd be curious to hear more about your use case too. |
Here's a snippet to preserve const params = { color: '#ff0000aa' }; // object you ultimately want to play with
const obj = { color: params.color.slice( 0, -2 ) }; // intermediate object
gui.addColor( obj, 'color' )
.onChange( value => {
params.color = value + params.color.slice( -2 );
} ); Note: A downside here is that the controller is attached to |
I'd be excited to see rgba() or #rrggbbaa support in this project. I'm using lil-gui to provide demos of a web component that I'm building. The component uses a gradient to render loading indicators, and the default config I have for the gradient has semi-transparent colors written as I can get away with just using the same colors without the alpha channel, but if I wanted to, for example, put one semi-transparent element over another for added visual effect, I wouldn't be able to do it comfortably with lil-gui. I would still be able to control opacity through additional controllers, but that's a lot more code than I'd like to write for a demo. The demo is here: https://amatyulkov.github.io/legendary-skeleton/examples/01-basic.html. |
hey @amatyulkov thanks for chiming in (and for using an existing issue 😉) So the main reason we don't have alpha support is because color controllers use the native I'd be curious to see a pass at an "advanced" color controller (written from scratch in lil-gui's visual style) that does everything the native color picker does + alpha. It would probably make the library a fair deal bigger, so maybe that could live as some kind of an "extension". Gonna make this the general color alpha thread for anyone else who has this same request, or thoughts on how to implement. |
I've done some more lurking. Dat.gui's color controller is 300 LOC without the alpha support. I think 300 LOC would make lil-gui not-so-lil, and ColorWithAlpha is better as a controller extension. What's your take on this? |
Agreed—longer reply in #12. And keep in mind that 300 lines doesn't include any of the color math or CSS 😉 |
+1 on adding Alpha support |
Hello, I recently replaced dat.gui by lil-gui in my projects and hadn't noticed there is currently no alpha support. This is my extension, adding an alpha range slider after the color input if desired: Here's a demo: Maybe it's helpful. |
Hello I made a version using jscolor library (the lib is not ESM and adds itself to the global context, but it the only one with a working UI I found) https://gist.github.com/mistic100/2ccdc808962d67adc8d81a15323e817c addColorPicker(gui, obj, 'color'); |
Is this somehow supported?
If not: how about just adding it by just using a rgb colorpocker, and entering the 'AA' value manually in the textbox (thats how dat.gui solved it).
The text was updated successfully, but these errors were encountered: