gpui: Add text alignment (#24090)

Adds a text property for controlling left, center, or right text
alignment.

#8792 should stay open since this doesn't add support for `justify`
(which would require a much bigger change since this can just alter the
origin of each line, but justify requires changing spacing, whereas
justify requires changes to each platform's shaping code).

Release Notes:

- N/A
This commit is contained in:
someone13574
2025-02-02 09:15:12 -08:00
committed by GitHub
parent 4a65315f3b
commit aa42e206b3
5 changed files with 112 additions and 6 deletions
+19
View File
@@ -293,6 +293,20 @@ pub enum TextOverflow {
Ellipsis(&'static str),
}
/// How to align text within the element
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum TextAlign {
/// Align the text to the left of the element
#[default]
Left,
/// Center the text within the element
Center,
/// Align the text to the right of the element
Right,
}
/// The properties that can be used to style text in GPUI
#[derive(Refineable, Clone, Debug, PartialEq)]
#[refineable(Debug)]
@@ -335,6 +349,10 @@ pub struct TextStyle {
/// The text should be truncated if it overflows the width of the element
pub text_overflow: Option<TextOverflow>,
/// How the text should be aligned within the element
pub text_align: TextAlign,
/// The number of lines to display before truncating the text
pub line_clamp: Option<usize>,
}
@@ -362,6 +380,7 @@ impl Default for TextStyle {
strikethrough: None,
white_space: WhiteSpace::Normal,
text_overflow: None,
text_align: TextAlign::default(),
line_clamp: None,
}
}