fix for anchored_position to work correctly with scaled label #57
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This attempts to solve #55
It turned out there were a few issues with the existing handling of anchored position leading to it not working correctly with scale.
As noted on a comment in anchor_point and anchored_position do not work well with scale #55 the scale parameter in
__init__()
was actually belonging to the super class Group which does allow it to visually scale the text properly. But Label itself was not remembering or doing anything with the scale.The math in the
anchored_position
setter was taking into account the current (x, y) position of the label when determining the new one. But I don't think this is needed, the only things needed to determine the new position should be: the new desired coordinates, the anchor_point, and the width and height.These changes resolve those issues by keeping the scale in
self._scale
and accounting for it when setting theanchored_position
. As well as removing the unneeded referencing of the previous x,y position during calculations.Changes were tested with this code:
After these changes the label in this script is now positioned properly in the top left corner of the screen.
I also tested with the display_text_anchored_position.py example and it seems to still be working properly after these changes.