diff options
author | Josh Rahm <rahm@google.com> | 2021-09-15 00:12:07 -0600 |
---|---|---|
committer | Josh Rahm <rahm@google.com> | 2021-09-15 00:12:07 -0600 |
commit | d2b578e011d62311125033d895060986a96d3c88 (patch) | |
tree | 00df698df2700c2a752f37a23858d1ce2a8c0a88 /alacritty | |
parent | 990f3f81f064f572aa0e6a528cfb3eb5215b88a4 (diff) | |
download | r-alacritty-d2b578e011d62311125033d895060986a96d3c88.tar.gz r-alacritty-d2b578e011d62311125033d895060986a96d3c88.tar.bz2 r-alacritty-d2b578e011d62311125033d895060986a96d3c88.zip |
Added a rudimentary undercurl to Alacritty. Currently does not support setting the color. That is the next task
Diffstat (limited to 'alacritty')
-rw-r--r-- | alacritty/src/display/content.rs | 2 | ||||
-rw-r--r-- | alacritty/src/renderer/rects.rs | 98 |
2 files changed, 86 insertions, 14 deletions
diff --git a/alacritty/src/display/content.rs b/alacritty/src/display/content.rs index 2deb3d3e..09116508 100644 --- a/alacritty/src/display/content.rs +++ b/alacritty/src/display/content.rs @@ -271,7 +271,7 @@ impl RenderableCell { self.bg_alpha == 0. && self.character == ' ' && self.zerowidth.is_none() - && !self.flags.intersects(Flags::UNDERLINE | Flags::STRIKEOUT | Flags::DOUBLE_UNDERLINE) + && !self.flags.intersects(Flags::UNDERLINE | Flags::STRIKEOUT | Flags::DOUBLE_UNDERLINE | Flags::UNDERCURL) } /// Apply [`CellRgb`] colors to the cell's colors. diff --git a/alacritty/src/renderer/rects.rs b/alacritty/src/renderer/rects.rs index 77c22011..91a67c22 100644 --- a/alacritty/src/renderer/rects.rs +++ b/alacritty/src/renderer/rects.rs @@ -62,7 +62,7 @@ impl RenderLine { end: Point<usize>, color: Rgb, ) { - let (position, thickness) = match flag { + match flag { Flags::DOUBLE_UNDERLINE => { // Position underlines so each one has 50% of descent available. let top_pos = 0.25 * metrics.descent; @@ -78,22 +78,93 @@ impl RenderLine { color, )); - (bottom_pos, metrics.underline_thickness) + rects.push(Self::create_rect( + size, + metrics.descent, + start, + end, + bottom_pos, + metrics.underline_thickness, + color, + )); + }, + Flags::UNDERLINE => { + rects.push(Self::create_rect( + size, + metrics.descent, + start, + end, + metrics.underline_position, + metrics.underline_thickness, + color, + )); }, - Flags::UNDERLINE => (metrics.underline_position, metrics.underline_thickness), - Flags::STRIKEOUT => (metrics.strikeout_position, metrics.strikeout_thickness), + Flags::STRIKEOUT => { + rects.push(Self::create_rect( + size, + metrics.descent, + start, + end, + metrics.strikeout_position, + metrics.strikeout_thickness, + color, + )); + }, + Flags::UNDERCURL => { + Self::push_undercurl_rects( + rects, + size, + metrics.descent, + start, + end, + metrics.underline_position, + metrics.underline_thickness, + color) + } _ => unimplemented!("Invalid flag for cell line drawing specified"), }; + } - rects.push(Self::create_rect( - size, - metrics.descent, - start, - end, - position, - thickness, - color, - )); + fn push_undercurl_rects( + rects: &mut Vec<RenderRect>, + size: &SizeInfo, + descent: f32, + start: Point<usize>, + end: Point<usize>, + position: f32, + mut thickness: f32, + color: Rgb, + ) { + let start_x = start.column.0 as f32 * size.cell_width(); + let end_x = (end.column.0 + 1) as f32 * size.cell_width(); + + // Make sure lines are always visible. + thickness = thickness.max(1.); + + let line_bottom = (start.line as f32 + 1.) * size.cell_height(); + let baseline = line_bottom + descent; + + let mut y = (baseline - position - thickness / 2.).ceil(); + let max_y = line_bottom - thickness; + if y > max_y { + y = max_y; + } + + let mut x = start_x; + let mut idx = 0; + while x < end_x { + let rect = RenderRect::new( + x + size.padding_x(), + y + size.padding_y() + ((idx % 2) as f32) - 1., + 1., + thickness + 1., + color, + 1., + ); + rects.push(rect); + x += 1.; + idx += 1; + } } /// Create a line's rect at a position relative to the baseline. @@ -161,6 +232,7 @@ impl RenderLines { self.update_flag(cell, Flags::UNDERLINE); self.update_flag(cell, Flags::DOUBLE_UNDERLINE); self.update_flag(cell, Flags::STRIKEOUT); + self.update_flag(cell, Flags::UNDERCURL); } /// Update the lines for a specific flag. |