|
| 1 | +# SPDX-FileCopyrightText: 2021 Tim C, written for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | +""" |
| 5 | +Test the wrap_text_to_pixels function. Try changing WRAP_WIDTH or text |
| 6 | +and observe the results. The red bar represents the full size of |
| 7 | +WRAP_WIDTH. |
| 8 | +""" |
| 9 | + |
| 10 | +import board |
| 11 | +import displayio |
| 12 | +import terminalio |
| 13 | +from adafruit_display_text import label, wrap_text_to_pixels |
| 14 | + |
| 15 | +WRAP_WIDTH = 140 |
| 16 | +text = ( |
| 17 | + "CircuitPython is a programming language designed to simplify experimenting " |
| 18 | + "and learning to code on low-cost microcontroller boards. " |
| 19 | +) |
| 20 | + |
| 21 | +# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.) |
| 22 | +# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.) |
| 23 | +# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus |
| 24 | +display = board.DISPLAY |
| 25 | + |
| 26 | +# Make the display context |
| 27 | +main_group = displayio.Group(max_size=10) |
| 28 | +display.show(main_group) |
| 29 | + |
| 30 | +font = terminalio.FONT |
| 31 | + |
| 32 | +print(text) |
| 33 | +print(display.width) |
| 34 | + |
| 35 | +text_area = label.Label( |
| 36 | + font, text=wrap_text_to_pixels(text, WRAP_WIDTH, font), background_color=0x0000DD |
| 37 | +) |
| 38 | + |
| 39 | +text_area.anchor_point = (0, 0) |
| 40 | +text_area.anchored_position = (0, 0) |
| 41 | + |
| 42 | +main_group.append(text_area) |
| 43 | + |
| 44 | +# Create a bitmap with two colors |
| 45 | +size_checker = displayio.Bitmap(WRAP_WIDTH, 10, 2) |
| 46 | +# Create a two color palette |
| 47 | +palette = displayio.Palette(2) |
| 48 | +palette[0] = 0x0000DD |
| 49 | +palette[1] = 0xDD0000 |
| 50 | + |
| 51 | +# Create a TileGrid using the Bitmap and Palette |
| 52 | +tile_grid = displayio.TileGrid(size_checker, pixel_shader=palette) |
| 53 | + |
| 54 | +tile_grid.y = text_area.bounding_box[1] + text_area.bounding_box[3] + 10 |
| 55 | + |
| 56 | +size_checker.fill(1) |
| 57 | + |
| 58 | +main_group.append(tile_grid) |
| 59 | + |
| 60 | +while True: |
| 61 | + pass |
0 commit comments