|
| 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 | + |
| 12 | +text_group = displayio.Group(max_size=9) |
| 13 | +text = "Hello" |
| 14 | +text_area_top_left = label.Label(terminalio.FONT, text=text) |
| 15 | +text_area_top_left.anchor_point = (0.0, 0.0) |
| 16 | +text_area_top_left.anchored_position = (10, 10) |
| 17 | + |
| 18 | +text_area_top_middle = label.Label(terminalio.FONT, text=text) |
| 19 | +text_area_top_middle.anchor_point = (0.5, 0.0) |
| 20 | +text_area_top_middle.anchored_position = (DISPLAY_WIDTH/2, 10) |
| 21 | + |
| 22 | +text_area_top_right = label.Label(terminalio.FONT, text=text) |
| 23 | +text_area_top_right.anchor_point = (1.0, 0.0) |
| 24 | +text_area_top_right.anchored_position = (DISPLAY_WIDTH-10, 10) |
| 25 | + |
| 26 | +text_area_middle_left = label.Label(terminalio.FONT, text=text) |
| 27 | +text_area_middle_left.anchor_point = (0.0, 0.5) |
| 28 | +text_area_middle_left.anchored_position = (10,DISPLAY_HEIGHT/2) |
| 29 | + |
| 30 | +text_area_middle_middle = label.Label(terminalio.FONT, text=text) |
| 31 | +text_area_middle_middle.anchor_point = (0.5, 0.5) |
| 32 | +text_area_middle_middle.anchored_position = (DISPLAY_WIDTH/2,DISPLAY_HEIGHT/2) |
| 33 | + |
| 34 | +text_area_middle_right = label.Label(terminalio.FONT, text=text) |
| 35 | +text_area_middle_right.anchor_point = (1.0, 0.5) |
| 36 | +text_area_middle_right.anchored_position = (DISPLAY_WIDTH-10, DISPLAY_HEIGHT/2) |
| 37 | + |
| 38 | + |
| 39 | +text_area_bottom_left = label.Label(terminalio.FONT, text=text) |
| 40 | +text_area_bottom_left.anchor_point = (0.0, 1.0) |
| 41 | +text_area_bottom_left.anchored_position = (10, DISPLAY_HEIGHT) |
| 42 | + |
| 43 | +text_area_bottom_middle = label.Label(terminalio.FONT, text=text) |
| 44 | +text_area_bottom_middle.anchor_point = (0.5, 1.0) |
| 45 | +text_area_bottom_middle.anchored_position = (DISPLAY_WIDTH/2, DISPLAY_HEIGHT) |
| 46 | + |
| 47 | +text_area_bottom_right = label.Label(terminalio.FONT, text=text) |
| 48 | +text_area_bottom_right.anchor_point = (1.0, 1.0) |
| 49 | +text_area_bottom_right.anchored_position = (DISPLAY_WIDTH-10, DISPLAY_HEIGHT) |
| 50 | + |
| 51 | +text_group.append(text_area_top_middle) |
| 52 | +text_group.append(text_area_top_left) |
| 53 | +text_group.append(text_area_top_right) |
| 54 | +text_group.append(text_area_middle_middle) |
| 55 | +text_group.append(text_area_middle_left) |
| 56 | +text_group.append(text_area_middle_right) |
| 57 | +text_group.append(text_area_bottom_middle) |
| 58 | +text_group.append(text_area_bottom_left) |
| 59 | +text_group.append(text_area_bottom_right) |
| 60 | + |
| 61 | +print(text_area_top_right.anchored_position) |
| 62 | +print(text_area_top_right.anchor_point) |
| 63 | + |
| 64 | +board.DISPLAY.show(text_group) |
| 65 | + |
| 66 | +while True: |
| 67 | + pass |
0 commit comments