-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Color swatch widget. #20237
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
base: main
Are you sure you want to change the base?
Color swatch widget. #20237
Conversation
return vec4<f32>(bg, alpha); | ||
} | ||
|
||
// From: https://github.com/bevyengine/bevy/pull/8973 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no cleaner way to reuse this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's two problems with that:
- Sharing shader code is hard
- It's not exactly the same code, I had to tweak some of the constants to avoid a tiny AA halo problem.
@alice-i-cecile The way I have implemented this may not be the best way, but it's the only way that works currently. ColorSwatch is a more complex widget than it might appear to be. It doesn't just display a color: it also updates the color displayed in response to user actions (such as dragging an RGB slider). This means that it needs to have a way to easily and dynamically modify what color is being displayed. In a reactive framework this would be trivial: the swatch would simply take a Color-valued signal as input. However, we don't have that, so we have to look for another way. Now, you might think, "Oh, just modify the This means that in order to update the displayed color, you need to modify the This also assumes that the compositing operation between a child entity and it's parent is correct: recall that shaders deal in linear colors, so the alpha blend factor used will be a linear alpha. Fortunately, when we pass a A different approach would be to use a single entity, with a custom shader that does both the alpha pattern and the constant color, and do the mixing ourselves. This is in fact how I did it in bevy_thorium, and in some ways it is simpler. The problem is that changing the color requires updating a shader uniform, and there's no general mechanism in Bevy for updating shader uniforms in response to changes to a Another strategy is to use |
|
||
/// Observer to fill in the material handle (since we don't have access to the materials asset | ||
/// in the template) | ||
fn on_add_color_swatch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to nitpick at all, but when I read the name of the function and then the list of parameters, I expected something like "On<Add, ColorSwatch>" because that's literally what the function is named. Instead it's AlphaPattern.
Maybe AlphaPattern should be renamed? Or this function? (Yes, I saw line 44 and the mut q_swatch, which again doesn't query a ColorSwatch, but a MaterialNode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting that. Cut & paste error from an earlier refactor.
@@ -39,7 +39,7 @@ pub(crate) struct AlphaPattern; | |||
|
|||
/// Observer to fill in the material handle (since we don't have access to the materials asset | |||
/// in the template) | |||
fn on_add_color_swatch( | |||
fn on_add_alpha_pattern( | |||
ev: On<Add, AlphaPattern>, | |||
mut q_swatch: Query<&mut MaterialNode<AlphaPatternMaterial>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@viridia sorry, not to be annoying, but is this intended? Or should it be just q
or q_material
or something?
I am sorry, I am a non-native speaker, it just stands out. I may shut up at any point if you tell me to.
Super grateful for all your work related to UI... it's the sore spot in bevy and you do amazing stuff!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh...!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW it's possible that much of this can go away when we migrate this widget to BSN, since we have access to the asset server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine considering the limitations of the UI material API.
A simple color swatch with an alpha pattern; this has been split out from the other color widgets.
The main reason for wanting this in is to set up the infrastructure for custom shaders in feathers.
Part of #16900
Note this is pre-BSN, and will need to be revised when merging with the BSN stuff. I deliberately left some stuff out to make merging easier.