-
Notifications
You must be signed in to change notification settings - Fork 39
Adding background_color #35
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
Hi, looks mostly good. However, if you don't set the background color so that it is transparent and read the property, it returns 0, which is the same value returned if it is black. Can we modify this so that if the color is transparent, it returns None? It doesn't appear circuitpython currently has a native way to check whether it is transparent, so we may need to store that as a flag on the label internally. |
adafruit_display_text/label.py
Outdated
@@ -57,7 +57,7 @@ class Label(displayio.Group): | |||
:param int color: Color of all text in RGB hex | |||
:param double line_spacing: Line spacing of text to display""" | |||
def __init__(self, font, *, x=0, y=0, text=None, max_glyphs=None, color=0xffffff, | |||
line_spacing=1.25, **kwargs): | |||
background_color=False, line_spacing=1.25, **kwargs): |
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.
Can you change the default to None
instead and then change your logic to match? You can check for None
easily:
if background_color:
# action if there is a color set
else:
# action if it's None
text_area = label.Label(terminalio.FONT, text=text, color=0x0000FF, background_color=0xFFAA00) | ||
text_area.x = 10 | ||
text_area.y = 10 | ||
board.DISPLAY.show(text_area) |
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.
Also add some lines that show:
- querying current background color
- changing back to no background color
adafruit_display_text/label.py
Outdated
@property | ||
def background_color(self): | ||
"""Color of the background as an RGB hex number.""" | ||
return self.palette[0] |
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.
It would be good if this would return None
when there is no background color set.
…arency and return None when background is transparent. add more functionality to example.
@makermelissa @caternuson I believe all of the mentioned changes have been made with the new commits. In making and testing the changes I also found and fixed a few issues with changing too and from transparent background colors. |
Thanks @FoamyGuy. One more small thing. Can we change it so
|
@makermelissa Got it done. Thank you. |
self.palette.make_transparent(0) | ||
else: | ||
self.transparent_background = False | ||
self.palette[0] = background_color |
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.
Sorry, I totally forgot about needing to accept 0
as a possible valid color. If that were done with above, then it would be treated as setting transparent. How about this?
if background_color is not None:
self.palette[0] = background_color
self.palette.make_opaque(0)
self.transparent_background = False
else:
self.palette.make_transparent(0)
self.transparent_background = True
Or could maybe do like you did in the setter?
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.
(but also with the leading underscore)
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.
Ah right, thank you. just pushed some commits to fix this in the constructor.
adafruit_display_text/label.py
Outdated
@@ -71,7 +71,14 @@ def __init__(self, font, *, x=0, y=0, text=None, max_glyphs=None, color=0xffffff | |||
self.y = y | |||
|
|||
self.palette = displayio.Palette(2) | |||
self.palette.make_transparent(0) | |||
if background_color or background_color == 0x000000: |
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.
This might be better expressed as: if background_color is not None:
adafruit_display_text/label.py
Outdated
|
||
@background_color.setter | ||
def background_color(self, new_color): | ||
if new_color or new_color == 0x000000: |
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.
same with this: if new_color is not None:
Thank you for making these changes. We want your code to be in its best possible form. |
@makermelissa there is a new commit now that changes both if statements to use the I really appreciate everyone taking the time to point out ways it can be improved. I cut my teeth as a solo programmer, and even now I work on a team of only 2-3 developers. So feedback on source code is something I haven't got much experience with before getting involved with Circuit Python. I appreciate the feedback because I can hopefully learn and improve from it. |
@FoamyGuy Thanks for making all the changes. @makermelissa At this point - looks OK to me. |
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.
Looks good to me too. Thanks @FoamyGuy!
Updating https://github.com/adafruit/Adafruit_CircuitPython_BusDevice to 4.2.1 from 4.2.0: > Merge pull request adafruit/Adafruit_CircuitPython_BusDevice#45 from dhalbert/fix-end-values Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.4.0 from 2.3.2: > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#35 from FoamyGuy/master Updating https://github.com/adafruit/Adafruit_CircuitPython_PyBadger to 1.1.1 from 1.1.0: > Merge pull request adafruit/Adafruit_CircuitPython_PyBadger#20 from nnja/fix_business_card_display
This change allows you to set background_color of the label in the constructor or with a property. Setting background_color to false, or excluding it entirely will result in same current behavior which is transparent background. This is referenced in issue #33.