Skip to content

Commit

Permalink
Add underline scale factor config (#2116)
Browse files Browse the repository at this point in the history
* Make automatic underline scaling the default and change the existing configuration to be a scale factor as per user request

* remove trailing whitespace
  • Loading branch information
Kethku committed Nov 8, 2023
1 parent f45ec8e commit 4711f10
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
16 changes: 4 additions & 12 deletions src/renderer/grid_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,10 @@ impl GridRenderer {
let mut underline_paint = Paint::default();
underline_paint.set_anti_alias(false);
underline_paint.set_blend_mode(BlendMode::SrcOver);
let auto_scaling = SETTINGS
.get::<RendererSettings>()
.underline_automatic_scaling;
// Arbitrary value under which we simply round the line thickness to 1. Anything else
// results in ugly aliasing artifacts.
let stroke_width = if self.shaper.current_size() < 15. || !auto_scaling {
underline_paint.set_anti_alias(false);
1.0
} else {
underline_paint.set_anti_alias(true);
self.shaper.current_size() / 10.
};
let underline_stroke_scale = SETTINGS.get::<RendererSettings>().underline_stroke_scale;
// If the stroke width is less than one, clamp it to one otherwise we get nasty aliasing
// issues
let stroke_width = (self.shaper.current_size() * underline_stroke_scale / 10.).max(1.);

underline_paint
.set_color(style.special(&self.default_style.colors).to_color())
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct RendererSettings {
light_radius: f32,
debug_renderer: bool,
profiler: bool,
underline_automatic_scaling: bool,
underline_stroke_scale: f32,
}

impl Default for RendererSettings {
Expand All @@ -69,7 +69,7 @@ impl Default for RendererSettings {
light_radius: 5.,
debug_renderer: false,
profiler: false,
underline_automatic_scaling: false,
underline_stroke_scale: 1.,
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions website/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,23 +308,23 @@ mouse makes it visible again.
VimScript:

```vim
let g:neovide_underline_automatic_scaling = v:false
let g:neovide_underline_stroke_scale = 1.0
```

Lua:

```lua
vim.g.neovide_underline_automatic_scaling = false
vim.g.neovide_underline_stroke_scale = 1.0
```

**Available since 0.10.**
**Unrelease yet.**

Setting `g:neovide_underline_automatic_scaling` to a boolean value determines whether automatic
scaling of text underlines (including undercurl, underdash, etc.) is enabled. Noticeable for font
sizes above 15.
Setting `g:neovide_underline_stroke_scale` to a floating point will increase or decrease the stroke
width of the underlines (including undercurl, underdash, etc.). If the scaled stroke width is less
than 1, it is clamped to 1 to prevent strange aliasing.

**Note**: This is currently glitchy, and leads to some underlines being clipped by the line of text
below.
**Note**: This is currently glitchy if the scale is too large, and leads to some underlines being
clipped by the line of text below.

#### Theme

Expand Down

0 comments on commit 4711f10

Please sign in to comment.