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