Skip to content
Closed
1 change: 1 addition & 0 deletions crates/egui/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl Painter {
}

/// If set, colors will be modified to look like this
#[deprecated = "Use `multiply_opacity` instead"]
pub fn set_fade_to_color(&mut self, fade_to_color: Option<Color32>) {
self.fade_to_color = fade_to_color;
}
Expand Down
16 changes: 11 additions & 5 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,9 @@ pub struct Visuals {

/// How to display numeric color values.
pub numeric_color_space: NumericColorSpace,

/// Opacity is multiplied by this amount when fading out widgets.
pub disabled_alpha: f32,
}

impl Visuals {
Expand Down Expand Up @@ -1052,18 +1055,17 @@ impl Visuals {
self.window_stroke
}

/// When fading out things, we fade the colors towards this.
// TODO(emilk): replace with an alpha
/// When fading out things, we multiply the opacity by this.
#[inline(always)]
pub fn fade_out_to_color(&self) -> Color32 {
self.widgets.noninteractive.weak_bg_fill
pub fn fade_out_opacity(&self) -> f32 {
Comment thread
emilk marked this conversation as resolved.
Outdated
self.disabled_alpha
}

/// Returned a "grayed out" version of the given color.
#[doc(alias = "grey_out")]
#[inline(always)]
pub fn gray_out(&self, color: Color32) -> Color32 {
crate::ecolor::tint_color_towards(color, self.fade_out_to_color())
color.gamma_multiply(self.fade_out_opacity())
}
}

Expand Down Expand Up @@ -1383,6 +1385,7 @@ impl Visuals {
image_loading_spinners: true,

numeric_color_space: NumericColorSpace::GammaByte,
disabled_alpha: 0.5,
}
}

Expand Down Expand Up @@ -2062,6 +2065,7 @@ impl Visuals {
image_loading_spinners,

numeric_color_space,
disabled_alpha: fade_out_by,
Comment thread
emilk marked this conversation as resolved.
Outdated
} = self;

ui.collapsing("Background Colors", |ui| {
Expand Down Expand Up @@ -2190,6 +2194,8 @@ impl Visuals {
ui.label("Color picker type");
numeric_color_space.toggle_button_ui(ui);
});

ui.add(Slider::new(fade_out_by, 0.0..=1.0).text("Disabled element alpha"));
});

ui.vertical_centered(|ui| reset_button(ui, self, "Reset visuals"));
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl Ui {
self.enabled = false;
if self.is_visible() {
self.painter
.set_fade_to_color(Some(self.visuals().fade_out_to_color()));
Comment thread
emilk marked this conversation as resolved.
.multiply_opacity(self.visuals().fade_out_opacity());
}
}

Expand Down