Skip to content

Conversation

@xStrom
Copy link
Member

@xStrom xStrom commented May 26, 2025

The two builders (ranged/tree) use different sources of truth to achieve a default style. This is already a bad idea, as evidenced by them having a different default line height until very recently. It gets even worse, because the ranged builder uses ResolvedStyle::default() which means it has a dummy font and doesn't respect scale.

This PR makes both builders use a single source of truth - a TextStyle which then gets resolved.

This means that we can confidently change our default style in only one place - the TextStyle::default method. Those default values then also get properly resolved according to available fonts, scale, etc.

Note that I didn't change the public API on purpose. I do think that being able to immediately provide a custom root style to the ranged builder, like it is possible with the tree builder, is probably worth doing. However, I want to do any potential public API changes as a focused follow-up PR.

The PlainEditor::ime_cursor_area method needed a slight modification as well. It was depending on ResolvedStyle::default() for a font size based calculation. That did not respect scale, so I fixed it by just keeping track of the font size that was provided to the PlainEditor constructor.

I replaced the custom ResolvedStyle::default() implementation with a simple derive. The only remaining non-derivable part was setting the font size to 16. Given that it doesn't respect scale, that custom implementation just provides a false sense of utility. A zero font size is perfectly fine for a state clearing default, which is how we're still using it.

I also added a test to ensure that the default styles remain in sync between the different builders.

@xStrom xStrom force-pushed the builders-default branch from d0515ec to 5d86781 Compare June 1, 2025 12:28
@xStrom xStrom marked this pull request as ready for review June 1, 2025 12:33
Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

Approving if and only if we still get rendering if you don't explicitly set a font size. Having a silent non-rendering due to the default font size being 0 would be an extremely poor UX (I could also forsee it leading to other fun bugs, such as with the overlapping line heights, although maybe we already addressed that).

@xStrom xStrom force-pushed the builders-default branch from 8672c2c to 192629d Compare July 7, 2025 08:51
@xStrom
Copy link
Member Author

xStrom commented Jul 7, 2025

There is no API surface that actually uses the 0 font size. It's only being used internally for clearing memory. 👍

@xStrom xStrom added this pull request to the merge queue Jul 7, 2025
Merged via the queue into linebender:main with commit b0d2b3b Jul 7, 2025
24 checks passed
@xStrom xStrom deleted the builders-default branch July 7, 2025 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants