1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Customise fade amount

The fade amount for UI elements can be customised.
This commit is contained in:
tye-exe
2025-04-30 17:49:44 +01:00
parent 450956f546
commit 83a5c0f2b2

View File

@@ -1018,6 +1018,9 @@ pub struct Visuals {
/// How to display numeric color values. /// How to display numeric color values.
pub numeric_color_space: NumericColorSpace, pub numeric_color_space: NumericColorSpace,
/// Opacity is multiplied by this amount when fading out widgets.
pub fade_out_by: f32,
} }
impl Visuals { impl Visuals {
@@ -1055,7 +1058,7 @@ impl Visuals {
/// When fading out things, we multiply the opacity by this. /// When fading out things, we multiply the opacity by this.
#[inline(always)] #[inline(always)]
pub fn fade_out_opacity(&self) -> f32 { pub fn fade_out_opacity(&self) -> f32 {
0.5 self.fade_out_by
} }
/// Returned a "grayed out" version of the given color. /// Returned a "grayed out" version of the given color.
@@ -1382,6 +1385,7 @@ impl Visuals {
image_loading_spinners: true, image_loading_spinners: true,
numeric_color_space: NumericColorSpace::GammaByte, numeric_color_space: NumericColorSpace::GammaByte,
fade_out_by: 0.5,
} }
} }
@@ -2061,6 +2065,7 @@ impl Visuals {
image_loading_spinners, image_loading_spinners,
numeric_color_space, numeric_color_space,
fade_out_by,
} = self; } = self;
ui.collapsing("Background Colors", |ui| { ui.collapsing("Background Colors", |ui| {
@@ -2189,6 +2194,8 @@ impl Visuals {
ui.label("Color picker type"); ui.label("Color picker type");
numeric_color_space.toggle_button_ui(ui); numeric_color_space.toggle_button_ui(ui);
}); });
ui.add(Slider::new(fade_out_by, 0.0..=1.0).text("Fades out widgets by"));
}); });
ui.vertical_centered(|ui| reset_button(ui, self, "Reset visuals")); ui.vertical_centered(|ui| reset_button(ui, self, "Reset visuals"));