From afeb2a2669b3ad6b735e5e1fbc4aaaaf12209931 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Tue, 28 Jan 2020 22:01:00 -0600 Subject: [PATCH 1/2] adding anchored position example --- examples/display_text_anchored_position.py | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 examples/display_text_anchored_position.py diff --git a/examples/display_text_anchored_position.py b/examples/display_text_anchored_position.py new file mode 100644 index 0000000..c637001 --- /dev/null +++ b/examples/display_text_anchored_position.py @@ -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) +text = "Hello" +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) + + +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) + +board.DISPLAY.show(text_group) + +while True: + pass From 8ca3c1a724f96de7c7673e823d84e38d48392601 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Wed, 29 Jan 2020 13:49:28 -0600 Subject: [PATCH 2/2] remove unneeded prints, make the 'text' variable more like a constant. moving text_group setup code all together. cleanup some whitespace. --- examples/display_text_anchored_position.py | 30 ++++++++++------------ 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/examples/display_text_anchored_position.py b/examples/display_text_anchored_position.py index c637001..963270e 100644 --- a/examples/display_text_anchored_position.py +++ b/examples/display_text_anchored_position.py @@ -8,46 +8,45 @@ DISPLAY_WIDTH = 320 DISPLAY_HEIGHT = 240 +TEXT = "Hello" -text_group = displayio.Group(max_size=9) -text = "Hello" -text_area_top_left = label.Label(terminalio.FONT, text=text) +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 = 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 = 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 = 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_left.anchored_position = (10, DISPLAY_HEIGHT/2) -text_area_middle_middle = label.Label(terminalio.FONT, text=text) +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_middle.anchored_position = (DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2) -text_area_middle_right = label.Label(terminalio.FONT, text=text) +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) - -text_area_bottom_left = label.Label(terminalio.FONT, text=text) +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 = 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 = 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 = displayio.Group(max_size=9) text_group.append(text_area_top_middle) text_group.append(text_area_top_left) text_group.append(text_area_top_right) @@ -58,9 +57,6 @@ 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) - board.DISPLAY.show(text_group) while True: