Skip to content

Commit

Permalink
Add Color32::mul (#5437)
Browse files Browse the repository at this point in the history
Multiply two `Color32` together quickly, in gamma-space
  • Loading branch information
emilk authored Dec 5, 2024
1 parent 291b83b commit 046034f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions crates/ecolor/src/color32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
])
}
}
4 changes: 2 additions & 2 deletions crates/egui/src/widgets/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 046034f

Please sign in to comment.