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.
Unified · Split
| @@ -1701,9 +1701,7 @@ impl EditorElement { · 1700 unmodified lines | ||
| 1701 | 1701 | len, |
| 1702 | 1702 | font, |
| 1703 | 1703 | color, |
| 1704 | − background_color: None, | |
| 1705 | − strikethrough: None, | |
| 1706 | − underline: None, | |
| 1704 | + ..Default::default() | |
| 1707 | 1705 | }], |
| 1708 | 1706 | None, |
| 1709 | 1707 | ) |
| @@ -3583,9 +3581,7 @@ impl EditorElement { · 1873 unmodified lines | ||
| 3583 | 3581 | len: line.len(), |
| 3584 | 3582 | font: style.text.font(), |
| 3585 | 3583 | color: placeholder_color, |
| 3586 | − background_color: None, | |
| 3587 | − underline: None, | |
| 3588 | − strikethrough: None, | |
| 3584 | + ..Default::default() | |
| 3589 | 3585 | }; |
| 3590 | 3586 | let line = window.text_system().shape_line( |
| 3591 | 3587 | line.to_string().into(), |
| @@ -7440,9 +7436,7 @@ impl EditorElement { · 3848 unmodified lines | ||
| 7440 | 7436 | len: column, |
| 7441 | 7437 | font: style.text.font(), |
| 7442 | 7438 | color: Hsla::default(), |
| 7443 | − background_color: None, | |
| 7444 | − underline: None, | |
| 7445 | − strikethrough: None, | |
| 7439 | + ..Default::default() | |
| 7446 | 7440 | }], |
| 7447 | 7441 | None, |
| 7448 | 7442 | ); |
| @@ -7465,9 +7459,7 @@ impl EditorElement { · 16 unmodified lines | ||
| 7465 | 7459 | len: text.len(), |
| 7466 | 7460 | font: self.style.text.font(), |
| 7467 | 7461 | color, |
| 7468 | − background_color: None, | |
| 7469 | − underline: None, | |
| 7470 | − strikethrough: None, | |
| 7462 | + ..Default::default() | |
| 7471 | 7463 | }; |
| 7472 | 7464 | window.text_system().shape_line( |
| 7473 | 7465 | text, |
| @@ -9568,9 +9560,7 @@ impl Element for EditorElement { · 2094 unmodified lines | ||
| 9568 | 9560 | len: tab_len, |
| 9569 | 9561 | font: self.style.text.font(), |
| 9570 | 9562 | color: cx.theme().colors().editor_invisible, |
| 9571 | − background_color: None, | |
| 9572 | − underline: None, | |
| 9573 | − strikethrough: None, | |
| 9563 | + ..Default::default() | |
| 9574 | 9564 | }], |
| 9575 | 9565 | None, |
| 9576 | 9566 | ); |
| @@ -9584,9 +9574,7 @@ impl Element for EditorElement { · 7 unmodified lines | ||
| 9584 | 9574 | len: space_len, |
| 9585 | 9575 | font: self.style.text.font(), |
| 9586 | 9576 | color: cx.theme().colors().editor_invisible, |
| 9587 | − background_color: None, | |
| 9588 | − underline: None, | |
| 9589 | − strikethrough: None, | |
| 9577 | + ..Default::default() | |
| 9590 | 9578 | }], |
| 9591 | 9579 | None, |
| 9592 | 9580 | ); |
| @@ -11573,11 +11561,8 @@ mod tests { · 1980 unmodified lines | ||
| 11573 | 11561 | fn generate_test_run(len: usize, color: Hsla) -> TextRun { |
| 11574 | 11562 | TextRun { |
| 11575 | 11563 | len, |
| 11576 | − font: gpui::font(".SystemUIFont"), | |
| 11577 | 11564 | color, |
| 11578 | − background_color: None, | |
| 11579 | − underline: None, | |
| 11580 | − strikethrough: None, | |
| 11565 | + ..Default::default() | |
| 11581 | 11566 | } |
| 11582 | 11567 | } |
| 11583 | 11568 | |
| @@ -739,7 +739,7 @@ impl Display for FontStyle { · 738 unmodified lines | ||
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | /// A styled run of text, for use in [`crate::TextLayout`]. |
| 742 | −#[derive(Clone, Debug, PartialEq, Eq)] | |
| 742 | +#[derive(Clone, Debug, PartialEq, Eq, Default)] | |
| 743 | 743 | pub struct TextRun { |
| 744 | 744 | /// A number of utf8 bytes |
| 745 | 745 | pub len: usize, |
| @@ -813,6 +813,12 @@ pub struct Font { · 67 unmodified lines | ||
| 813 | 813 | pub style: FontStyle, |
| 814 | 814 | } |
| 815 | 815 | |
| 816 | +impl Default for Font { | |
| 817 | + fn default() -> Self { | |
| 818 | + font(".SystemUIFont") | |
| 819 | + } | |
| 820 | +} | |
| 821 | + | |
| 816 | 822 | /// Get a [`Font`] for a given name. |
| 817 | 823 | pub fn font(family: impl Into<SharedString>) -> Font { |
| 818 | 824 | Font { |
| @@ -315,9 +315,7 @@ impl Boundary { · 314 unmodified lines | ||
| 315 | 315 | #[cfg(test)] |
| 316 | 316 | mod tests { |
| 317 | 317 | use super::*; |
| 318 | − use crate::{ | |
| 319 | − Font, FontFeatures, FontStyle, FontWeight, Hsla, TestAppContext, TestDispatcher, font, | |
| 320 | − }; | |
| 318 | + use crate::{Font, FontFeatures, FontStyle, FontWeight, TestAppContext, TestDispatcher, font}; | |
| 321 | 319 | #[cfg(target_os = "macos")] |
| 322 | 320 | use crate::{TextRun, WindowTextSystem, WrapBoundary}; |
| 323 | 321 | use rand::prelude::*; |
| @@ -341,10 +339,7 @@ mod tests { · 17 unmodified lines | ||
| 341 | 339 | weight: FontWeight::default(), |
| 342 | 340 | style: FontStyle::Normal, |
| 343 | 341 | }, |
| 344 | − color: Hsla::default(), | |
| 345 | − background_color: None, | |
| 346 | − underline: None, | |
| 347 | − strikethrough: None, | |
| 342 | + ..Default::default() | |
| 348 | 343 | }) |
| 349 | 344 | .collect() |
| 350 | 345 | } |
| @@ -691,16 +686,12 @@ mod tests { · 340 unmodified lines | ||
| 691 | 686 | font: font("Helvetica"), |
| 692 | 687 | color: Default::default(), |
| 693 | 688 | underline: Default::default(), |
| 694 | − strikethrough: None, | |
| 695 | − background_color: None, | |
| 689 | + ..Default::default() | |
| 696 | 690 | }; |
| 697 | 691 | let bold = TextRun { |
| 698 | 692 | len: 0, |
| 699 | 693 | font: font("Helvetica").bold(), |
| 700 | − color: Default::default(), | |
| 701 | − underline: Default::default(), | |
| 702 | − strikethrough: None, | |
| 703 | − background_color: None, | |
| 694 | + ..Default::default() | |
| 704 | 695 | }; |
| 705 | 696 | |
| 706 | 697 | let text = "aa bbb cccc ddddd eeee".into(); |
| @@ -101,9 +101,7 @@ impl TableView { · 100 unmodified lines | ||
| 101 | 101 | len: 0, |
| 102 | 102 | font: text_font, |
| 103 | 103 | color: text_style.color, |
| 104 | − background_color: None, | |
| 105 | − underline: None, | |
| 106 | − strikethrough: None, | |
| 104 | + ..Default::default() | |
| 107 | 105 | }]; |
| 108 | 106 | |
| 109 | 107 | for field in table.schema.fields.iter() { |
| @@ -1112,9 +1112,7 @@ impl Element for TerminalElement { · 1111 unmodified lines | ||
| 1112 | 1112 | len, |
| 1113 | 1113 | font: text_style.font(), |
| 1114 | 1114 | color: theme.colors().terminal_ansi_background, |
| 1115 | − background_color: None, | |
| 1116 | − underline: Default::default(), | |
| 1117 | − strikethrough: None, | |
| 1115 | + ..Default::default() | |
| 1118 | 1116 | }], |
| 1119 | 1117 | None, |
| 1120 | 1118 | ) |
| @@ -1322,9 +1320,8 @@ impl Element for TerminalElement { · 201 unmodified lines | ||
| 1322 | 1320 | len: text_to_mark.len(), |
| 1323 | 1321 | font: ime_style.font(), |
| 1324 | 1322 | color: ime_style.color, |
| 1325 | − background_color: None, | |
| 1326 | 1323 | underline: ime_style.underline, |
| 1327 | − strikethrough: None, | |
| 1324 | + ..Default::default() | |
| 1328 | 1325 | }], |
| 1329 | 1326 | None |
| 1330 | 1327 | ); |
| @@ -1842,27 +1839,21 @@ mod tests { · 511 unmodified lines | ||
| 1842 | 1839 | len: 1, |
| 1843 | 1840 | font: font("Helvetica"), |
| 1844 | 1841 | color: Hsla::red(), |
| 1845 | − background_color: None, | |
| 1846 | − underline: None, | |
| 1847 | − strikethrough: None, | |
| 1842 | + ..Default::default() | |
| 1848 | 1843 | }; |
| 1849 | 1844 | |
| 1850 | 1845 | let style2 = TextRun { |
| 1851 | 1846 | len: 1, |
| 1852 | 1847 | font: font("Helvetica"), |
| 1853 | 1848 | color: Hsla::red(), |
| 1854 | − background_color: None, | |
| 1855 | − underline: None, | |
| 1856 | − strikethrough: None, | |
| 1849 | + ..Default::default() | |
| 1857 | 1850 | }; |
| 1858 | 1851 | |
| 1859 | 1852 | let style3 = TextRun { |
| 1860 | 1853 | len: 1, |
| 1861 | 1854 | font: font("Helvetica"), |
| 1862 | 1855 | color: Hsla::blue(), // Different color |
| 1863 | − background_color: None, | |
| 1864 | − underline: None, | |
| 1865 | − strikethrough: None, | |
| 1856 | + ..Default::default() | |
| 1866 | 1857 | }; |
| 1867 | 1858 | |
| 1868 | 1859 | let font_size = AbsoluteLength::Pixels(px(12.0)); |
| @@ -1881,9 +1872,7 @@ mod tests { · 12 unmodified lines | ||
| 1881 | 1872 | len: 1, |
| 1882 | 1873 | font: font("Helvetica"), |
| 1883 | 1874 | color: Hsla::red(), |
| 1884 | − background_color: None, | |
| 1885 | − underline: None, | |
| 1886 | − strikethrough: None, | |
| 1875 | + ..Default::default() | |
| 1887 | 1876 | }; |
| 1888 | 1877 | |
| 1889 | 1878 | let font_size = AbsoluteLength::Pixels(px(12.0)); |
| @@ -1912,9 +1901,7 @@ mod tests { · 22 unmodified lines | ||
| 1912 | 1901 | len: 1, |
| 1913 | 1902 | font: font("Helvetica"), |
| 1914 | 1903 | color: Hsla::red(), |
| 1915 | − background_color: None, | |
| 1916 | − underline: None, | |
| 1917 | − strikethrough: None, | |
| 1904 | + ..Default::default() | |
| 1918 | 1905 | }; |
| 1919 | 1906 | |
| 1920 | 1907 | let font_size = AbsoluteLength::Pixels(px(12.0)); |
| @@ -1944,9 +1931,7 @@ mod tests { · 23 unmodified lines | ||
| 1944 | 1931 | len: 1, |
| 1945 | 1932 | font: font("Helvetica"), |
| 1946 | 1933 | color: Hsla::red(), |
| 1947 | − background_color: None, | |
| 1948 | − underline: None, | |
| 1949 | − strikethrough: None, | |
| 1934 | + ..Default::default() | |
| 1950 | 1935 | }; |
| 1951 | 1936 | |
| 1952 | 1937 | let font_size = AbsoluteLength::Pixels(px(12.0)); |