code.py
1 # SPDX-FileCopyrightText: 2021 Jose David Montoya for Adafruit Industries 2 # SPDX-License-Identifier: MIT 3 4 """ 5 This example shows the use of base_alignment parameter. 6 """ 7 8 import board 9 import displayio 10 from adafruit_bitmap_font import bitmap_font 11 from adafruit_display_text import bitmap_label as label 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 20 21 # Font definition. You can choose any two fonts available in your system 22 MEDIUM_FONT = bitmap_font.load_font("fonts/LeagueSpartan-Bold-16.bdf") 23 BIG_FONT = bitmap_font.load_font("fonts/LeagueGothic-Regular-36.bdf") 24 25 TEXT_RIGHT = "MG" 26 TEXT_LEFT = "32.47" 27 28 main_group = displayio.Group() 29 30 # Create labels 31 # Base Alignment parameter False 32 left_text = label.Label( 33 BIG_FONT, 34 text=TEXT_LEFT, 35 color=0xDD00DD, 36 x=10, 37 y=50, 38 base_alignment=False, 39 ) 40 main_group.append(left_text) 41 42 right_text = label.Label( 43 MEDIUM_FONT, 44 text=TEXT_RIGHT, 45 color=0xDD00DD, 46 x=90, 47 y=50, 48 base_alignment=False, 49 ) 50 main_group.append(right_text) 51 52 # Base Alignment parameter True 53 left_text_aligned = label.Label( 54 BIG_FONT, 55 text=TEXT_LEFT, 56 color=0xDD00DD, 57 x=10, 58 y=160, 59 base_alignment=True, 60 ) 61 main_group.append(left_text_aligned) 62 63 right_text_aligned = label.Label( 64 MEDIUM_FONT, 65 text=TEXT_RIGHT, 66 color=0xDD00DD, 67 x=90, 68 y=160, 69 base_alignment=True, 70 ) 71 72 main_group.append(right_text_aligned) 73 display.show(main_group) 74 75 while True: 76 pass