gpui: Impl Default for TextRun (#41084)

Release Notes:

- N/A

When I was implementing Input, I often used `TextRun`, but `background`,
`underline` and `strikethrough` were often not used.

So make change to simplify it.
This commit is contained in:
Jason Lee
2025-11-06 01:50:23 +00:00
committed by GitHub
parent 622d626a29
commit 64c8c19e1b
5 changed files with 27 additions and 62 deletions
+7 -1
View File
@@ -739,7 +739,7 @@ impl Display for FontStyle {
}
/// A styled run of text, for use in [`crate::TextLayout`].
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub struct TextRun {
/// A number of utf8 bytes
pub len: usize,
@@ -813,6 +813,12 @@ pub struct Font {
pub style: FontStyle,
}
impl Default for Font {
fn default() -> Self {
font(".SystemUIFont")
}
}
/// Get a [`Font`] for a given name.
pub fn font(family: impl Into<SharedString>) -> Font {
Font {
+4 -13
View File
@@ -315,9 +315,7 @@ impl Boundary {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
Font, FontFeatures, FontStyle, FontWeight, Hsla, TestAppContext, TestDispatcher, font,
};
use crate::{Font, FontFeatures, FontStyle, FontWeight, TestAppContext, TestDispatcher, font};
#[cfg(target_os = "macos")]
use crate::{TextRun, WindowTextSystem, WrapBoundary};
use rand::prelude::*;
@@ -341,10 +339,7 @@ mod tests {
weight: FontWeight::default(),
style: FontStyle::Normal,
},
color: Hsla::default(),
background_color: None,
underline: None,
strikethrough: None,
..Default::default()
})
.collect()
}
@@ -691,16 +686,12 @@ mod tests {
font: font("Helvetica"),
color: Default::default(),
underline: Default::default(),
strikethrough: None,
background_color: None,
..Default::default()
};
let bold = TextRun {
len: 0,
font: font("Helvetica").bold(),
color: Default::default(),
underline: Default::default(),
strikethrough: None,
background_color: None,
..Default::default()
};
let text = "aa bbb cccc ddddd eeee".into();