|
| 1 | +""" |
| 2 | +This examples shows the use of anchor_point and anchored_position. |
| 3 | +""" |
| 4 | +import board |
| 5 | +import terminalio |
| 6 | +from adafruit_display_text import label |
| 7 | +import displayio |
| 8 | + |
| 9 | +DISPLAY_WIDTH = 320 |
| 10 | +DISPLAY_HEIGHT = 240 |
| 11 | +TEXT = "Hello" |
| 12 | + |
| 13 | +text_area_top_left = label.Label(terminalio.FONT, text=TEXT) |
| 14 | +text_area_top_left.anchor_point = (0.0, 0.0) |
| 15 | +text_area_top_left.anchored_position = (10, 10) |
| 16 | + |
| 17 | +text_area_top_middle = label.Label(terminalio.FONT, text=TEXT) |
| 18 | +text_area_top_middle.anchor_point = (0.5, 0.0) |
| 19 | +text_area_top_middle.anchored_position = (DISPLAY_WIDTH/2, 10) |
| 20 | + |
| 21 | +text_area_top_right = label.Label(terminalio.FONT, text=TEXT) |
| 22 | +text_area_top_right.anchor_point = (1.0, 0.0) |
| 23 | +text_area_top_right.anchored_position = (DISPLAY_WIDTH-10, 10) |
| 24 | + |
| 25 | +text_area_middle_left = label.Label(terminalio.FONT, text=TEXT) |
| 26 | +text_area_middle_left.anchor_point = (0.0, 0.5) |
| 27 | +text_area_middle_left.anchored_position = (10, DISPLAY_HEIGHT/2) |
| 28 | + |
| 29 | +text_area_middle_middle = label.Label(terminalio.FONT, text=TEXT) |
| 30 | +text_area_middle_middle.anchor_point = (0.5, 0.5) |
| 31 | +text_area_middle_middle.anchored_position = (DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2) |
| 32 | + |
| 33 | +text_area_middle_right = label.Label(terminalio.FONT, text=TEXT) |
| 34 | +text_area_middle_right.anchor_point = (1.0, 0.5) |
| 35 | +text_area_middle_right.anchored_position = (DISPLAY_WIDTH-10, DISPLAY_HEIGHT/2) |
| 36 | + |
| 37 | +text_area_bottom_left = label.Label(terminalio.FONT, text=TEXT) |
| 38 | +text_area_bottom_left.anchor_point = (0.0, 1.0) |
| 39 | +text_area_bottom_left.anchored_position = (10, DISPLAY_HEIGHT) |
| 40 | + |
| 41 | +text_area_bottom_middle = label.Label(terminalio.FONT, text=TEXT) |
| 42 | +text_area_bottom_middle.anchor_point = (0.5, 1.0) |
| 43 | +text_area_bottom_middle.anchored_position = (DISPLAY_WIDTH/2, DISPLAY_HEIGHT) |
| 44 | + |
| 45 | +text_area_bottom_right = label.Label(terminalio.FONT, text=TEXT) |
| 46 | +text_area_bottom_right.anchor_point = (1.0, 1.0) |
| 47 | +text_area_bottom_right.anchored_position = (DISPLAY_WIDTH-10, DISPLAY_HEIGHT) |
| 48 | + |
| 49 | +text_group = displayio.Group(max_size=9) |
| 50 | +text_group.append(text_area_top_middle) |
| 51 | +text_group.append(text_area_top_left) |
| 52 | +text_group.append(text_area_top_right) |
| 53 | +text_group.append(text_area_middle_middle) |
| 54 | +text_group.append(text_area_middle_left) |
| 55 | +text_group.append(text_area_middle_right) |
| 56 | +text_group.append(text_area_bottom_middle) |
| 57 | +text_group.append(text_area_bottom_left) |
| 58 | +text_group.append(text_area_bottom_right) |
| 59 | + |
| 60 | +board.DISPLAY.show(text_group) |
| 61 | + |
| 62 | +while True: |
| 63 | + pass |
0 commit comments