-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Support separate background and foreground color on UI text #5935
Comments
I don't know the implementation details, but I feel this should be added to |
Can you please describe precisely what a "text background color" is here?
You can achieve 3. by wrapping the text into a parent I think the request is about 2., in which case this is related to another issue about the fact we discard the position of the glyphs relative to the baseline in the text pipeline and instead always position text based on the bounding box of the glyphs, which is wrong. |
Yeah, don't really know enough about this to know exactly how this should be done, but from your description I think that 2. is what users really want. |
Item 2. is when you highlight a text by selecting it. The selection needs to be of constant height whatever the text so the height is based on the font metrics, not the actual text content (glyphs used). "ace" and "pub" would have the same background rectangle height despite the "p" and "b". Most likely this is what we want to implement with this issue indeed. Item 3. is when you place a single-word text inside a rect as e.g. a button and you want it aligned in some particular way, possibly with borders and padding, and you want visually the same spacing around all sides, so depends on the text content(*). (*) Actually typography purists would probably argue that even for a button you want to align from the baseline and font metrics so it's a bad example. But it's good enough to understand I think. 😊 |
After reading alexheretic/glyph-brush#153, it looks like we're stuck with only the glyph bounds with their section and index. When drawing backgrounds, we need to:
|
If you try to implement text highlighting (option 2.) with this, you will end up with line backgrounds of varying heights and that will look ugly. |
It may be useful to store information about each line with |
Actually the ascent and descent are per font and not per glyph so I'm not sure what you were talking about referencing the glyph bounds (which have no typographic meaning). Maybe we're talking about the same thing? |
Ascent and descent are font properties unrelated to what glyphs are used in the line. There's no need to store nor calculate anything because if I remember correctly we cannot use multiple fonts nor font sizes per section. |
# Objective `TextBundle` should have a `BackgroundColor` component. Apart from adding emphasis etc to text, adding a background color to text nodes can be extremely useful for understanding how Bevy aligns, sizes and positions text, and identifying and debugging problems. It's easy for users to insert the `BackgroundColor` component themselves but not immediately obvious or discoverable that it's possible. A `BackgroundColor` component allows us to add a `with_background_color` helper function to `TextBundle`. related issue: #5935 ## Solution Add a `BackgroundColor` component to `TextBundle`. --- ## Changelog * Added a `BackgroundColor` component to `TextBundle`. * Added a helper method `with_background_color` to `TextBundle`. ## Migration Guide `TextBundle` now has a `BackgroundColor` component. Use `TextBundle`'s `background_color` field or the `with_background_color` method to set a background color for text when spawning a text node, in place of manual insertion of a `BackgroundColor` component.
Is this completed by #7596 ? |
What problem does this solve or what need does it fill?
We would like to be able to support things like text-highlighting, text-selection and generally improve what we can do with text in our UI. These require that we can color foreground and background of the text independently.
At the moment we have support for foreground color of text in the text sections, but we have no background color support.
What solution would you like?
Not completely sure which approach is correct. Either add a
background-color
field toTextBundle
or add background color to theTextSection
.We probably need the latter if we want to want to support highlighting of arbitrary sections of text, but this is going to be very interesting how it would work with things like "user marks arbitrary text that gets highlighted". Maybe these need to be multiple but separated features?
What alternative(s) have you considered?
TextBundle / TextSection
.The text was updated successfully, but these errors were encountered: