code.py
 1  # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2  # SPDX-License-Identifier: MIT
 3  
 4  """
 5  This examples shows the use of anchor_point and anchored_position.
 6  """
 7  import board
 8  import terminalio
 9  import displayio
10  from adafruit_display_text import label
11  
12  
13  # Built-in display
14  display = board.DISPLAY
15  
16  # Make the display context
17  main_group = displayio.Group()
18  display.show(main_group)
19  DISPLAY_WIDTH = 320
20  DISPLAY_HEIGHT = 240
21  TEXT = "Hello"
22  
23  text_area_top_left = label.Label(terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2)
24  text_area_top_left.anchor_point = (0.0, 0.0)
25  text_area_top_left.anchored_position = (8, 8)
26  
27  text_area_top_middle = label.Label(terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2)
28  text_area_top_middle.anchor_point = (0.5, 0.0)
29  text_area_top_middle.anchored_position = (DISPLAY_WIDTH / 2, 8)
30  
31  text_area_top_right = label.Label(terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2)
32  text_area_top_right.anchor_point = (1.0, 0.0)
33  text_area_top_right.anchored_position = (DISPLAY_WIDTH - 8, 8)
34  
35  text_area_middle_left = label.Label(terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2)
36  text_area_middle_left.anchor_point = (0.0, 0.5)
37  text_area_middle_left.anchored_position = (8, DISPLAY_HEIGHT / 2)
38  
39  text_area_middle_middle = label.Label(
40      terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2
41  )
42  text_area_middle_middle.anchor_point = (0.5, 0.5)
43  text_area_middle_middle.anchored_position = (DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2)
44  
45  text_area_middle_right = label.Label(
46      terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2
47  )
48  text_area_middle_right.anchor_point = (1.0, 0.5)
49  text_area_middle_right.anchored_position = (DISPLAY_WIDTH - 8, DISPLAY_HEIGHT / 2)
50  
51  text_area_bottom_left = label.Label(terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2)
52  text_area_bottom_left.anchor_point = (0.0, 1.0)
53  text_area_bottom_left.anchored_position = (8, DISPLAY_HEIGHT - 8)
54  
55  text_area_bottom_middle = label.Label(
56      terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2
57  )
58  text_area_bottom_middle.anchor_point = (0.5, 1.0)
59  text_area_bottom_middle.anchored_position = (DISPLAY_WIDTH / 2, DISPLAY_HEIGHT - 8)
60  
61  text_area_bottom_right = label.Label(
62      terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2
63  )
64  text_area_bottom_right.anchor_point = (1.0, 1.0)
65  text_area_bottom_right.anchored_position = (DISPLAY_WIDTH - 8, DISPLAY_HEIGHT - 8)
66  
67  text_group = displayio.Group()
68  text_group.append(text_area_top_middle)
69  text_group.append(text_area_top_left)
70  text_group.append(text_area_top_right)
71  text_group.append(text_area_middle_middle)
72  text_group.append(text_area_middle_left)
73  text_group.append(text_area_middle_right)
74  text_group.append(text_area_bottom_middle)
75  text_group.append(text_area_bottom_left)
76  text_group.append(text_area_bottom_right)
77  
78  display.show(text_group)
79  
80  while True:
81      pass