Add `Color32::mul` (#5437)

Multiply two `Color32` together quickly, in gamma-space
This commit is contained in:
Emil Ernerfeldt 2024-12-05 13:53:20 +01:00 committed by GitHub
parent 291b83b7be
commit 046034f902
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -269,3 +269,18 @@ impl Color32 {
)
}
}
impl std::ops::Mul for Color32 {
type Output = Self;
/// Fast gamma-space multiplication.
#[inline]
fn mul(self, other: Self) -> Self {
Self([
fast_round(self[0] as f32 * other[0] as f32 / 255.0),
fast_round(self[1] as f32 * other[1] as f32 / 255.0),
fast_round(self[2] as f32 * other[2] as f32 / 255.0),
fast_round(self[3] as f32 * other[3] as f32 / 255.0),
])
}
}

View File

@ -158,7 +158,7 @@ impl<'a> Button<'a> {
self
}
/// If true, the tint of the image is the same as the text color.
/// If true, the tint of the image is multiplied by the widget text color.
///
/// This makes sense for images that are white, that should have the same color as the text color.
/// This will also make the icon color depend on hover state.
@ -336,7 +336,7 @@ impl Widget for Button<'_> {
let tlr = image.load_for_size(ui.ctx(), image_size);
let mut image_options = image.image_options().clone();
if image_tint_follows_text_color {
image_options.tint = visuals.text_color();
image_options.tint = image_options.tint * visuals.text_color();
}
widgets::image::paint_texture_load_result(
ui,