-
Notifications
You must be signed in to change notification settings - Fork 38
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
Added "cx" and "cy" property to the label to change center of Label #22
Conversation
I like how you are using the Group's x and y to handle this! I'd rather not add separate cx and cy properties though. Instead, I'd like to see one or two properties that set the anchor position. Right how it's fixed as Center Left but you'd like Center Center. With the anchor property, changes to the bounding box, x, or y (overridden) would trigger changing the Group's x and y. Thanks! |
@neoxharsh Thank you for the contribution! There are a number of linting errors that need addressing, as well as a change request in the comment above. If you're still interested in seeing this included in this library, please make the necessary changes. If you need assistance with any of it, please let us know. Thanks! |
moving to anchor point instead of cx and cy
fix for missing _anchor_point in init
adafruit_display_text/label.py
Outdated
_anchored_position = ( | ||
self.x-self._boundingbox[2]*self._anchor_point[0], | ||
self.y-self._boundingbox[3]*self._anchor_point[1]) | ||
return _anchored_position |
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.
You can avoid creating _anchored_position
and shorten this up to something like:
return self.x-self._boundingbox[2]*self._anchor_point[0],
self.y-self._boundingbox[3]*self._anchor_point[1]
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, I see. Thank you, this way it won't need to create the variable at all.
Here is an example script that shows usage and testing of the anchor point functionality. |
removing unneeded _anchored_position variable.
adding _anchor_point into init
@caternuson I am trying to work through the pylint issues. It looks like it's mad that I've used |
Hmmm...I think that has to do with the linter not knowing the actual class layout for things from the CP firmware. @tannewt What say you? |
Perhaps the linter would be happy if you set the x and y to some default value inside of the |
tested with simpletest and the anchor point test linked above.
@tannewt @kattni @makermelissa @FoamyGuy @caternuson, thanks for all your support. I am on vacation, staying away from tech for a while. 😇 |
@makermelissa @caternuson @FoamyGuy Did one of you test this iteration? If so, we can merge it. If not, can one of you please test it? Thanks! |
@neoxharsh No worries! Thank you for the original contribution! Have a wonderful vacation! |
@kattni, I did not test. I was merely interpreting the Pylint error. |
@FoamyGuy Please create a new PR for the example. @caternuson Thank you for testing! I'll get this merged. |
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.
That'll work. For future ref - you don't even need the parans to return a tuple. Can just do like:
return x, y, z
@FoamyGuy At your convenience, please create a new PR with the example you linked. Please ping me for assistance with naming the example file if it is unclear what it should be named. Thanks! |
@kattni I did test last night with both the simpletest, and the example linked above. @caternuson I had tried it without the parans first actually. If I understood correct I was getting an Indention error due to that return statement being split across two lines. Explicitly adding the parans seemed to fix the issue for me. I will make a PR to add the example code today, it'll probably take me a bit to get to, but I'll definitely get it done at some point. |
@FoamyGuy Ah, for multiple lines without parans, may have needed a return x, \
y No biggie. Mainly just wanted to point out the syntax is possible. |
Ah, I see. Thank you. I appreciate it, I've come a long way with Python, but I'm still not very familiar with some of it's features. |
@caternuson @FoamyGuy I prefer using parens to allow line wraps. I think it's easier to see than the trailing \ |
^^ yep. i'd agree. for simple, shorter, one liners, can use other syntax |
Updating https://github.com/adafruit/Adafruit_CircuitPython_PyPortal to 3.1.9 from 3.1.8: > Merge pull request adafruit/Adafruit_CircuitPython_PyPortal#64 from cogliano/master Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.2.0 from 2.1.6: > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#30 from FoamyGuy/master > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#22 from neoxharsh/master
I have added "cx" and "cy" property to the label, such that setting those will move the center of the text rather than the top left corner of the text. My apologies if it is already available.
Eg. for PyPortal