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
+4 -1
View File
@@ -1661,6 +1661,8 @@ impl Interactivity {
window: &mut Window,
cx: &mut App,
) {
use crate::TextAlign;
if global_id.is_some()
&& (style.debug || style.debug_below || cx.has_global::<crate::DebugBelow>())
&& hitbox.is_hovered(window)
@@ -1682,7 +1684,8 @@ impl Interactivity {
.ok()
.and_then(|mut text| text.pop())
{
text.paint(hitbox.origin, FONT_SIZE, window, cx).ok();
text.paint(hitbox.origin, FONT_SIZE, TextAlign::Left, window, cx)
.ok();
let text_bounds = crate::Bounds {
origin: hitbox.origin,
+3 -1
View File
@@ -390,8 +390,10 @@ impl TextLayout {
let line_height = element_state.line_height;
let mut line_origin = bounds.origin;
let text_style = window.text_style();
for line in &element_state.lines {
line.paint(line_origin, line_height, window, cx).log_err();
line.paint(line_origin, line_height, text_style.text_align, window, cx)
.log_err();
line_origin.y += line.size(line_height).height;
}
}