From d0cf57bd9801da7a38499f51d1a73a223a43e6cc Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 4 Dec 2024 15:15:02 +0100 Subject: [PATCH 1/2] Add Button::image_tint_follows_text_color --- crates/egui/src/widgets/button.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index 28a578ee694..bd3ad3d86dc 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -37,6 +37,7 @@ pub struct Button<'a> { min_size: Vec2, rounding: Option, selected: bool, + image_tint_follows_text_color: bool, } impl<'a> Button<'a> { @@ -70,6 +71,7 @@ impl<'a> Button<'a> { min_size: Vec2::ZERO, rounding: None, selected: false, + image_tint_follows_text_color: false, } } @@ -156,6 +158,15 @@ impl<'a> Button<'a> { self } + /// If true, the tint of the image is the same as the text color. + /// + /// This makes sense for images that are white, that should have the same color as the text color. + #[inline] + pub fn image_tint_follows_text_color(mut self, image_tint_follows_text_color: bool) -> Self { + self.image_tint_follows_text_color = image_tint_follows_text_color; + self + } + /// Show some text on the right side of the button, in weak color. /// /// Designed for menu buttons, for setting a keyboard shortcut text (e.g. `Ctrl+S`). @@ -190,6 +201,7 @@ impl Widget for Button<'_> { min_size, rounding, selected, + image_tint_follows_text_color, } = self; let frame = frame.unwrap_or_else(|| ui.visuals().button_frame); @@ -319,12 +331,16 @@ impl Widget for Button<'_> { let image_rect = Rect::from_min_size(image_pos, image_size); cursor_x += image_size.x; 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(); + } widgets::image::paint_texture_load_result( ui, &tlr, image_rect, image.show_loading_spinner, - image.image_options(), + &image_options, ); response = widgets::image::texture_load_result_response( &image.source(ui.ctx()), From 844432743bc1f757de2ceddcebd84b189b964116 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 4 Dec 2024 15:16:38 +0100 Subject: [PATCH 2/2] update docstring --- crates/egui/src/widgets/button.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/egui/src/widgets/button.rs b/crates/egui/src/widgets/button.rs index bd3ad3d86dc..bfcd656723c 100644 --- a/crates/egui/src/widgets/button.rs +++ b/crates/egui/src/widgets/button.rs @@ -161,6 +161,9 @@ impl<'a> Button<'a> { /// If true, the tint of the image is the same as the 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. + /// + /// Default: `false`. #[inline] pub fn image_tint_follows_text_color(mut self, image_tint_follows_text_color: bool) -> Self { self.image_tint_follows_text_color = image_tint_follows_text_color;