Skip to content

Add TextRect component to easily add backgrounds to Text components #479

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

Open
techniq opened this issue Apr 30, 2025 · 1 comment
Open

Comments

@techniq
Copy link
Owner

techniq commented Apr 30, 2025

Would be very helpful when using Svg and Canvas layers to easily add a Rect as a background behind a Text. Getting the dimensions (and support a padding attribute) will take some thought.

This could also be directly integrated into Text as:

<Text background="...">, <Text bg="...">, etc

@techniq techniq changed the title Add TextRect component to easily add backgrounds to Text components Add TextRect component to easily add backgrounds to Text components Apr 30, 2025
@techniq techniq changed the title Add TextRect component to easily add backgrounds to Text components Add TextRect component to easily add backgrounds to Text components Apr 30, 2025
@techniq
Copy link
Owner Author

techniq commented May 20, 2025

Since we already get word/line width in Text we should able able to leverage this to create the width of the bounding box.

Currently getStringWidth() uses getComputedTextLength() but might be better to get the bounding box with one of the aforementioned.

See also this canvas StackOverflow answer and SVG example

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

No branches or pull requests

1 participant