From 4b153e7f7fc60825eca50f4defc29924f8d91966 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Sat, 15 Mar 2025 17:44:51 +0800 Subject: [PATCH] gpui: Fix `line_through`, `underline` position when used text center or right (#24721) Release Notes: - N/A --- | Before | After | | --- | --- | | image | image | And fix the `line_through` doc link. --- crates/gpui/examples/text_layout.rs | 28 +++++++++++++++++++++++++++- crates/gpui/src/styled.rs | 4 ++-- crates/gpui/src/text_system/line.rs | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/crates/gpui/examples/text_layout.rs b/crates/gpui/examples/text_layout.rs index d855b6434857754a366cb39e6c81a92d4e76d0a4..993a718528712bd058d1f4731152bc33db041e26 100644 --- a/crates/gpui/examples/text_layout.rs +++ b/crates/gpui/examples/text_layout.rs @@ -11,12 +11,38 @@ impl Render for HelloWorld { .bg(gpui::white()) .flex() .flex_col() - .gap_3() + .gap_2() .p_4() .size_full() .child(div().child("Text left")) .child(div().text_center().child("Text center")) .child(div().text_right().child("Text right")) + .child(div().text_decoration_1().child("Text left (underline)")) + .child( + div() + .text_center() + .text_decoration_1() + .child("Text center (underline)"), + ) + .child( + div() + .text_right() + .text_decoration_1() + .child("Text right (underline)"), + ) + .child(div().line_through().child("Text left (line_through)")) + .child( + div() + .text_center() + .line_through() + .child("Text center (line_through)"), + ) + .child( + div() + .text_right() + .line_through() + .child("Text right (line_through)"), + ) .child( div() .flex() diff --git a/crates/gpui/src/styled.rs b/crates/gpui/src/styled.rs index 57951650c331fa21f858021905ae6d444532dd20..3fe344fd8ac7c6370c90977ae5d8750ed3b53e4e 100644 --- a/crates/gpui/src/styled.rs +++ b/crates/gpui/src/styled.rs @@ -478,7 +478,7 @@ pub trait Styled: Sized { } /// Sets the font style of the element to normal (not italic). - /// [Docs](https://tailwindcss.com/docs/font-style#italicizing-text) + /// [Docs](https://tailwindcss.com/docs/font-style#displaying-text-normally) fn not_italic(mut self) -> Self { self.text_style() .get_or_insert_with(Default::default) @@ -498,7 +498,7 @@ pub trait Styled: Sized { } /// Sets the decoration of the text to have a line through it. - /// [Docs](https://tailwindcss.com/docs/text-decoration#setting-the-text-decoration) + /// [Docs](https://tailwindcss.com/docs/text-decoration-line#adding-a-line-through-text) fn line_through(mut self) -> Self { let style = self.text_style().get_or_insert_with(Default::default); style.strikethrough = Some(StrikethroughStyle { diff --git a/crates/gpui/src/text_system/line.rs b/crates/gpui/src/text_system/line.rs index af6c0b7354f8fa6015715308ca3ab0acacf2ea48..d638465ce7294bb31486e7f738e02b5a4244aaf4 100644 --- a/crates/gpui/src/text_system/line.rs +++ b/crates/gpui/src/text_system/line.rs @@ -355,7 +355,7 @@ fn paint_line( } } - let mut last_line_end_x = origin.x + layout.width; + let mut last_line_end_x = glyph_origin.x; if let Some(boundary) = wrap_boundaries.last() { let run = &layout.runs[boundary.run_ix]; let glyph = &run.glyphs[boundary.glyph_ix];