From ef20e2c071cf0fdd4119a215faccf74fbabcfae4 Mon Sep 17 00:00:00 2001 From: tye-exe Date: Sun, 25 May 2025 09:43:35 +0100 Subject: [PATCH] Split "disabling" and "graying out". Split these two behaviours into different functions, as either behaviour is sometimes desirable. --- crates/egui/src/style.rs | 17 +++++++++++++---- crates/egui/src/ui.rs | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 21dfb85a6..43254d531 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -1019,7 +1019,7 @@ pub struct Visuals { /// How to display numeric color values. pub numeric_color_space: NumericColorSpace, - /// Opacity is multiplied by this amount when fading out widgets. + /// How much to modify the alpha of a disabled widget. pub disabled_alpha: f32, } @@ -1055,17 +1055,26 @@ impl Visuals { self.window_stroke } - /// When fading out things, we multiply the opacity by this. + /// Disabled widgets have their alpha modified by this. #[inline(always)] pub fn disabled_alpha(&self) -> f32 { self.disabled_alpha } - /// Returned a "grayed out" version of the given color. + /// Returns a "disabled" version of the given color. + /// + /// This function modifies the opcacity of the given color. + /// If this is undesirable use [`gray_out`](Self::gray_out). + #[inline(always)] + pub fn disable(&self, color: Color32) -> Color32 { + color.gamma_multiply(self.disabled_alpha()) + } + + /// Returns a "grayed out" version of the given color. #[doc(alias = "grey_out")] #[inline(always)] pub fn gray_out(&self, color: Color32) -> Color32 { - color.gamma_multiply(self.disabled_alpha()) + crate::ecolor::tint_color_towards(color, self.widgets.noninteractive.weak_bg_fill) } } diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index c088f8070..06e798975 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -2963,8 +2963,8 @@ impl Ui { if is_anything_being_dragged && !can_accept_what_is_being_dragged { // When dragging something else, show that it can't be dropped here: - fill = self.visuals().gray_out(fill); - stroke.color = self.visuals().gray_out(stroke.color); + fill = self.visuals().disable(fill); + stroke.color = self.visuals().disable(stroke.color); } frame.frame.fill = fill;