text rendering: support strikethroughs (#7363)

<img width="1269" alt="image"
src="https://github.com/zed-industries/zed/assets/18583882/d4c93033-b2ac-4ae0-8e12-457f256ee869">

Release Notes:

- Added support for styling text with strikethrough.

Related: 
- https://github.com/zed-industries/zed/issues/5364
- https://github.com/zed-industries/zed/pull/7345
This commit is contained in:
Kieran Gill 2024-02-07 09:51:27 -05:00 committed by GitHub
parent 55129d4d6c
commit ad3940c66f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 145 additions and 4 deletions

View file

@ -10,7 +10,7 @@ pub use line_wrapper::*;
use crate::{
px, Bounds, DevicePixels, EntityId, Hsla, Pixels, PlatformTextSystem, Point, Result,
SharedString, Size, UnderlineStyle,
SharedString, Size, StrikethroughStyle, UnderlineStyle,
};
use anyhow::anyhow;
use collections::{BTreeSet, FxHashMap, FxHashSet};
@ -317,6 +317,7 @@ impl WindowTextSystem {
if let Some(last_run) = decoration_runs.last_mut() {
if last_run.color == run.color
&& last_run.underline == run.underline
&& last_run.strikethrough == run.strikethrough
&& last_run.background_color == run.background_color
{
last_run.len += run.len as u32;
@ -328,6 +329,7 @@ impl WindowTextSystem {
color: run.color,
background_color: run.background_color,
underline: run.underline,
strikethrough: run.strikethrough,
});
}
@ -382,6 +384,7 @@ impl WindowTextSystem {
if decoration_runs.last().map_or(false, |last_run| {
last_run.color == run.color
&& last_run.underline == run.underline
&& last_run.strikethrough == run.strikethrough
&& last_run.background_color == run.background_color
}) {
decoration_runs.last_mut().unwrap().len += run_len_within_line as u32;
@ -391,6 +394,7 @@ impl WindowTextSystem {
color: run.color,
background_color: run.background_color,
underline: run.underline,
strikethrough: run.strikethrough,
});
}
@ -406,6 +410,7 @@ impl WindowTextSystem {
let layout = self
.line_layout_cache
.layout_wrapped_line(&line_text, font_size, &font_runs, wrap_width);
lines.push(WrappedLine {
layout,
decoration_runs,
@ -599,6 +604,8 @@ pub struct TextRun {
pub background_color: Option<Hsla>,
/// The underline style (if any)
pub underline: Option<UnderlineStyle>,
/// The strikethrough style (if any)
pub strikethrough: Option<StrikethroughStyle>,
}
/// An identifier for a specific glyph, as returned by [`TextSystem::layout_line`].