Skip to content

fix for anchored_position to work correctly with scaled label #57

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

Merged

Conversation

FoamyGuy
Copy link
Contributor

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 the anchored_position. As well as removing the unneeded referencing of the previous x,y position during calculations.

Changes were tested with this code:

import terminalio, displayio, board
from adafruit_display_text import label
text_area = label.Label(
    terminalio.FONT,
    text="Scale!", scale=5, color=0xc0c0c0, 
    background_color=0x0000FF
)
text_area.anchor_point = (0,0)
board.DISPLAY.show(text_area)
text_area.anchored_position = (0,0)  ### expectation is text will be on screen at top left
while True:
    pass

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.

@FoamyGuy FoamyGuy requested a review from a team June 28, 2020 20:59
Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Blinka Displayio

@makermelissa makermelissa merged commit 225b0b1 into adafruit:master Jul 2, 2020
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 3, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_BH1750 to 1.0.1 from 1.0.0:
  > Update README.rst

Updating https://github.com/adafruit/Adafruit_CircuitPython_L3GD20 to 2.3.0 from 2.2.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_L3GD20#19 from dherrada/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.7.6 from 2.7.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#57 from FoamyGuy/fix_anchor_when_text_is_scaled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants