Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Anchoring was not working properly for multiline text because of the way text.Orig and text.bounds are aligned. Orig is at the bottom of the first line, and bounds are extended downward after each
\n
character. For a single line of text, Orig is effectively at bounds.Min, so anchoring relative to bounds works as expected. However after one or more line breaks there is a growing offset between Orig and bounds.Min and the anchor vec from bounds is no longer correctly aligned.In order to preserve the previous behavior of text, in which characters are drawn starting at the origin and expanding right and down, the anchor offset is disabled by default until
AlignedTo(...)
is called. Otherwise now that anchoring is correctly computed text would shift up after each newline since the default anchor value is TopRight (a.k.apixel.Anchor{0, 0}
).Broken anchoring
Here the anchor is set to pixel.Center, but instead of being centered on Orig, it is anchored to un-untransformed bounds.Min, so the entire text moves down after every line break. Additionally, there is no convenient way to get the true bounds or Dot of the text in anchor-space, since anchoring is applied at draw time.
Here there are a number of
\n
and\t
characters entered first before entering text. Because bounds did not account for them, the anchoring is not aligned to Orig.Fixed anchoring
After offsetting the anchor vec by the height minus the first line, anchoring works as expected. I have also added
AnchoredBounds()
andAnchoredDot()
convenience functions to easily retrieve their positions in anchor-space.Centered on Orig
Compute bounds/anchoring corrrectly for control characters
\n
and\t
Previously bounds were not expanded for line break and tab characters, which could throw off the anchoring.
Anchored to the top right corner (or pixel.BottomLeft for... reasons?)
Compute bounds for space characters when font atlas returns empty rect
Some text fonts return empty bounds for the space character, meaning text that starts with space would not start it's bounds until after the first non-space rune. Again, throwing off the anchoring from what would be expected.
Anchored to bottom left corner (pixel.TopRight)
Unanchored text