Make unnecessary code fade configurable (#14442)

This PR allows configuring the intensity of code fade applied to unused
code (relates to #4785).

_Note: Right now I included it as a top level config which might be a
little out of place (but is easiest to instrument). Open for suggestions
on where else it would be better suited for._

_Note 2: I am unfamiliar with the codebase. Feel free to either close
this PR and re-implement in a better way or suggest high level changes
if I'm approaching anything wrong :)._

Release Notes:

- Added `unnecesary_code_fade` setting to control how strongly to fade
unused code.

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
Matthew D. Scholefield 2024-08-20 10:13:27 -07:00 committed by GitHub
parent ebcc2945c5
commit 5c0d800b21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 39 additions and 3 deletions

View file

@ -91,6 +91,7 @@ pub struct ThemeSettings {
pub active_theme: Arc<Theme>,
pub theme_overrides: Option<ThemeStyleContent>,
pub ui_density: UiDensity,
pub unnecessary_code_fade: f32,
}
impl ThemeSettings {
@ -283,6 +284,10 @@ pub struct ThemeSettingsContent {
#[serde(rename = "unstable.ui_density", default)]
pub ui_density: Option<UiDensity>,
/// How much to fade out unused code.
#[serde(default)]
pub unnecessary_code_fade: Option<f32>,
/// EXPERIMENTAL: Overrides for the current theme.
///
/// These values will override the ones on the current theme specified in `theme`.
@ -550,6 +555,7 @@ impl settings::Settings for ThemeSettings {
.unwrap(),
theme_overrides: None,
ui_density: defaults.ui_density.unwrap_or(UiDensity::Default),
unnecessary_code_fade: defaults.unnecessary_code_fade.unwrap_or(0.0),
};
for value in sources.user.into_iter().chain(sources.release_channel) {
@ -602,6 +608,10 @@ impl settings::Settings for ThemeSettings {
value.buffer_font_size.map(Into::into),
);
merge(&mut this.buffer_line_height, value.buffer_line_height);
// Clamp the `unnecessary_code_fade` to ensure text can't disappear entirely.
merge(&mut this.unnecessary_code_fade, value.unnecessary_code_fade);
this.unnecessary_code_fade = this.unnecessary_code_fade.clamp(0.0, 0.9);
}
Ok(this)