Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpui: Add text alignment #24090

Merged
merged 2 commits into from
Feb 2, 2025
Merged

Conversation

someone13574
Copy link
Contributor

@someone13574 someone13574 commented Feb 2, 2025

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

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 2, 2025
@mikayla-maki
Copy link
Contributor

Thank you!

@mikayla-maki mikayla-maki merged commit aa42e20 into zed-industries:main Feb 2, 2025
14 checks passed
@someone13574 someone13574 deleted the text-center branch February 2, 2025 17:15
@huacnlee
Copy link
Contributor

huacnlee commented Feb 3, 2025

I have do a quick try it. But it is looks like not works. 🤔

Before After
image image

@huacnlee
Copy link
Contributor

huacnlee commented Feb 3, 2025

This is cause by whitespace_nowrap

let mut glyph_origin = point(
aligned_origin_x(
origin,
align_width.unwrap_or(layout.width),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here layout.width is the actually text width, not the line width.

So if the text is "hello", the layout.width be the width of the "hello".

window: &mut Window,
cx: &mut App,
) -> Result<()> {
paint_line(
origin,
&self.layout.unwrapped_layout,
line_height,
align,
self.layout.wrap_width,
Copy link
Contributor

@huacnlee huacnlee Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whitespace_normal can works, because of the wrap_width have value.

This is by TextLayout to measured known_dimensions:

let wrap_width = if text_style.white_space == WhiteSpace::Normal {

But if nowrap mode, the wrap_width is none.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants