-
Notifications
You must be signed in to change notification settings - Fork 38
Updated background color handling for label #49
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirmed this issue and tested the fix successfully on a PyPortal with this slightly modified background color example:
"""
This examples shows the use color and background_color.
Modified to use BDF font.
"""
import time
import board
import terminalio
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
text = " Color Background Hello world"
font = bitmap_font.load_font("/Helvetica-Bold-16.bdf")
text_area = label.Label(
font, text=text, color=0x0000FF, background_color=0xFFAA00
)
text_area.x = 10
text_area.y = 50
print("background color is {:06x}".format(text_area.background_color))
board.DISPLAY.show(text_area)
time.sleep(2)
text_area.background_color = 0xFF0000
print("background color is {:06x}".format(text_area.background_color))
while True:
pass
I would love to eventually see options for adding padding, especially top and bottom. I think this can come in a future PR though. I am happy to have this fix in now to add immediate utility to BDF font based labels.
Thank you @kmatch98
…ed options for padding, including *background_tight* Boolean and padding_top/bottom/left/right optional parameters
Thanks for the feedback. I eliminated the chance for possible multiple Per @FoamyGuy request I added options for padding:
Limitations: For multiline text strings the background box will be the width of the widest line. Examples:
|
…dding_*) since there is are getter/setter and update functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there are no getter/setter functions, I hid these variables inside the class definition:
background_tight
padding_top
padding_bottom
padding_left
padding_right
@FoamyGuy the new example added uses a separately-connected display. If you have a chance, please verify it with your simpler code for starting the display for devices with built-in. (Currently my daughter is using our pyPortal full-time for her studies, so I can't really verify.) Feel free to change the example to the simpler version, since that will be easier for users to understand. |
Thanks! This looks good at a human level but note that pylint has something to tell you. Find where "Build CI / test" is failing, and look at the Details. let us know if you get stuck, the formatting checks can be very ... specific. |
If there are any pylint diagnostics that are too onerous to deal with, they can be ignored. Let me know if you need a pointer to docs on how to do this. |
I resolved all the error messages. Let me know if you see any other changes required. |
I successfully tested the new library and example code (slightly modified) on PyPortal. The functionality looks good to me. That comment on line 322 looks to be present still. If it's unneeded we can remove it. I'm not sure I understand fully what it does right now thought. I can tinker with it a bit in the morning perhaps. |
I don't see what you mean about line 322. I pushed a few commits just now. @jepler also said he's seeing a bunch of comments still in the file. I checked but I don't see anything in the latest revision. Let me know if I'm missing something.
|
In the font setter. This line:
|
Squashed it. Dunno how I overlooked it. Thanks for the find. I just committed the update and it passed the checks. Thanks for all of your help and patience! Hope this will be of help to someone out there. After a couple of days of this I'm ready to move on to something else... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, somehow I got led astray about the latest content of the PR. Sorry about that.
@kmatch98 Thank you for sticking through all the changes. It's really nice to have the background color working correctly with BDF fonts. And I really like the new padding functionality! |
Thanks guys for helping me through this and suggesting all the improvements. Thank y’all. Maybe we’ll see more text based projects on the show n tell! |
Updating https://github.com/adafruit/Adafruit_CircuitPython_AHTx0 to 1.0.1 from 1.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_AHTx0#1 from kattni/example-i2c-update Updating https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI to 3.4.1 from 3.4.0: > Merge pull request adafruit/Adafruit_CircuitPython_ESP32SPI#99 from Flameeyes/master Updating https://github.com/adafruit/Adafruit_CircuitPython_ILI9341 to 1.2.1 from 1.2.0: > Merge pull request adafruit/Adafruit_CircuitPython_ILI9341#22 from makermelissa/master > Merge pull request adafruit/Adafruit_CircuitPython_ILI9341#21 from adafruit/setup-py-disabled > build.yml: add black formatting check Updating https://github.com/adafruit/Adafruit_CircuitPython_LPS2X to 2.0.0 from 1.1.1: > Merge pull request adafruit/Adafruit_CircuitPython_LPS2X#4 from adafruit/lps22 > build.yml: add black formatting check Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.4.0 from 1.3.2: > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#20 from xorbit/master > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#14 from adafruit/pylint-update Updating https://github.com/adafruit/Adafruit_CircuitPython_AzureIoT to 2.2.1 from 2.2.0: > Merge pull request adafruit/Adafruit_CircuitPython_AzureIoT#16 from jimbobbennett/master Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.7.0 from 2.6.1: > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#49 from kmatch98/background > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#48 from FoamyGuy/better_group_full_error Updating https://github.com/adafruit/Adafruit_CircuitPython_LED_Animation to 2.3.0 from 2.2.0: > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#39 from rhooper/bugfixes > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#38 from rhooper/sequence-one-shot > Merge pull request adafruit/Adafruit_CircuitPython_LED_Animation#40 from rhooper/pixelgrid Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 3.1.0 from 3.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#38 from brentru/on-message-enhancements Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Added the following libraries: Adafruit_CircuitPython_ILI9341
When using imported BDF font files with proportional typefaces, the current version of label with applied background color only covers the glyphs but not the whitespace. Also, spaces provide some errant dots. See image:

This PR creates an additional colored bitmap tileGrid as the bottom layer below the text that is the size of the bounding box around the glyph text. The following three images show examples of the proposed PR with differing text.
Note: The bounding box is a simple minimum bounding box to fit the whole set of glyphs. This means that text with no ascenders and descenders (see second image below
mere a or o
) will have a smaller bounding box than other lines with taller letters.Possible enhancements: