gpui: Fix line_through, underline position when used text center or right (#24721)

Release Notes:

- N/A

---

| Before | After |
| --- | --- |
| <img width="912" alt="image"
src="https://github.com/user-attachments/assets/0640ac85-ee5d-4707-b866-997e36608c18"
/> | <img width="912" alt="image"
src="https://github.com/user-attachments/assets/caf84477-a7bc-4c22-a9e6-f44c3b6f86ef"
/> |
 
And fix the `line_through` doc link.
This commit is contained in:
Jason Lee 2025-03-15 17:44:51 +08:00 committed by GitHub
parent b61171f152
commit 4b153e7f7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 4 deletions

View file

@ -11,12 +11,38 @@ impl Render for HelloWorld {
.bg(gpui::white()) .bg(gpui::white())
.flex() .flex()
.flex_col() .flex_col()
.gap_3() .gap_2()
.p_4() .p_4()
.size_full() .size_full()
.child(div().child("Text left")) .child(div().child("Text left"))
.child(div().text_center().child("Text center")) .child(div().text_center().child("Text center"))
.child(div().text_right().child("Text right")) .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( .child(
div() div()
.flex() .flex()

View file

@ -478,7 +478,7 @@ pub trait Styled: Sized {
} }
/// Sets the font style of the element to normal (not italic). /// 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 { fn not_italic(mut self) -> Self {
self.text_style() self.text_style()
.get_or_insert_with(Default::default) .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. /// 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 { fn line_through(mut self) -> Self {
let style = self.text_style().get_or_insert_with(Default::default); let style = self.text_style().get_or_insert_with(Default::default);
style.strikethrough = Some(StrikethroughStyle { style.strikethrough = Some(StrikethroughStyle {

View file

@ -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() { if let Some(boundary) = wrap_boundaries.last() {
let run = &layout.runs[boundary.run_ix]; let run = &layout.runs[boundary.run_ix];
let glyph = &run.glyphs[boundary.glyph_ix]; let glyph = &run.glyphs[boundary.glyph_ix];