Skip to content

adding anchored position example #30

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
merged 2 commits into from
Jan 29, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions examples/display_text_anchored_position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
This examples shows the use of anchor_point and anchored_position.
"""
import board
import terminalio
from adafruit_display_text import label
import displayio

DISPLAY_WIDTH = 320
DISPLAY_HEIGHT = 240

text_group = displayio.Group(max_size=9)
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be better moved to just before your first text_group.append line below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like it, better to keep the text_group setup together than have it split by all of the lines setting up labels. I will make this change along with the others in the next commit

text = "Hello"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is like a const, so maybe change it to TEXT and move it up by the DISPLAY_ defs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, agreed. Will do.

text_area_top_left = label.Label(terminalio.FONT, text=text)
text_area_top_left.anchor_point = (0.0, 0.0)
text_area_top_left.anchored_position = (10, 10)

text_area_top_middle = label.Label(terminalio.FONT, text=text)
text_area_top_middle.anchor_point = (0.5, 0.0)
text_area_top_middle.anchored_position = (DISPLAY_WIDTH/2, 10)

text_area_top_right = label.Label(terminalio.FONT, text=text)
text_area_top_right.anchor_point = (1.0, 0.0)
text_area_top_right.anchored_position = (DISPLAY_WIDTH-10, 10)

text_area_middle_left = label.Label(terminalio.FONT, text=text)
text_area_middle_left.anchor_point = (0.0, 0.5)
text_area_middle_left.anchored_position = (10,DISPLAY_HEIGHT/2)

text_area_middle_middle = label.Label(terminalio.FONT, text=text)
text_area_middle_middle.anchor_point = (0.5, 0.5)
text_area_middle_middle.anchored_position = (DISPLAY_WIDTH/2,DISPLAY_HEIGHT/2)

text_area_middle_right = label.Label(terminalio.FONT, text=text)
text_area_middle_right.anchor_point = (1.0, 0.5)
text_area_middle_right.anchored_position = (DISPLAY_WIDTH-10, DISPLAY_HEIGHT/2)


Copy link
Contributor

Choose a reason for hiding this comment

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

extra line

text_area_bottom_left = label.Label(terminalio.FONT, text=text)
text_area_bottom_left.anchor_point = (0.0, 1.0)
text_area_bottom_left.anchored_position = (10, DISPLAY_HEIGHT)

text_area_bottom_middle = label.Label(terminalio.FONT, text=text)
text_area_bottom_middle.anchor_point = (0.5, 1.0)
text_area_bottom_middle.anchored_position = (DISPLAY_WIDTH/2, DISPLAY_HEIGHT)

text_area_bottom_right = label.Label(terminalio.FONT, text=text)
text_area_bottom_right.anchor_point = (1.0, 1.0)
text_area_bottom_right.anchored_position = (DISPLAY_WIDTH-10, DISPLAY_HEIGHT)

text_group.append(text_area_top_middle)
text_group.append(text_area_top_left)
text_group.append(text_area_top_right)
text_group.append(text_area_middle_middle)
text_group.append(text_area_middle_left)
text_group.append(text_area_middle_right)
text_group.append(text_area_bottom_middle)
text_group.append(text_area_bottom_left)
text_group.append(text_area_bottom_right)

print(text_area_top_right.anchored_position)
print(text_area_top_right.anchor_point)
Copy link
Contributor

Choose a reason for hiding this comment

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

still need these prints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say the prints are not really essential, I mainly put them to test and ensure the getters were working as expected. I can remove them.


board.DISPLAY.show(text_group)

while True:
pass