adding example scripts for display_text learn guide

This commit is contained in:
foamyguy 2021-03-08 11:37:49 -06:00
parent 7e45a4c514
commit f4ba83f195
16 changed files with 32184 additions and 0 deletions

View file

@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
"""
Illustrates the background_color parameter of display_text label and bitmap_label
"""
import board
import displayio
import terminalio
from adafruit_display_text import label
# Make the display context. Change size if you want
display = board.DISPLAY
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
reg_label = label.Label(
font=terminalio.FONT,
text="CircuitPython",
scale=3,
background_color=0xDD00DD,
)
reg_label.anchor_point = (0, 0)
reg_label.anchored_position = (20, 20)
main_group.append(reg_label)
while True:
pass

View file

@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Illustrates the background_tight parameter of display_text label and bitmap_label
"""
import board
import displayio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label
# Built-in display
display = board.DISPLAY
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
font = bitmap_font.load_font("fonts/Fayette-HandwrittenScript-48.bdf")
reg_label = label.Label(
font=font, text="False", scale=2, background_color=0xDD00DD, background_tight=False
)
reg_label.anchor_point = (0, 0)
reg_label.anchored_position = (20, 20)
j_label = label.Label(
font=font, text="joy", scale=2, background_color=0xDD00DD, background_tight=False
)
j_label.anchor_point = (0, 0)
j_label.anchored_position = (150, 36)
main_group.append(j_label)
main_group.append(reg_label)
tight_label = label.Label(
font=font, text="True", scale=2, background_color=0xDD00DD, background_tight=True
)
tight_label.anchor_point = (0, 0)
tight_label.anchored_position = (20, 120)
main_group.append(tight_label)
while True:
pass

View file

@ -0,0 +1,76 @@
# SPDX-FileCopyrightText: 2021 Jose David Montoya for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
This example shows the use of base_alignment parameter.
"""
import board
import displayio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import bitmap_label as label
# Built-in display
display = board.DISPLAY
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
# Font definition. You can choose any two fonts available in your system
MEDIUM_FONT = bitmap_font.load_font("fonts/LeagueSpartan-Bold-16.bdf")
BIG_FONT = bitmap_font.load_font("fonts/LeagueGothic-Regular-36.bdf")
TEXT_RIGHT = "MG"
TEXT_LEFT = "32.47"
main_group = displayio.Group()
# Create labels
# Base Alignment parameter False
left_text = label.Label(
BIG_FONT,
text=TEXT_LEFT,
color=0xDD00DD,
x=10,
y=50,
base_alignment=False,
)
main_group.append(left_text)
right_text = label.Label(
MEDIUM_FONT,
text=TEXT_RIGHT,
color=0xDD00DD,
x=90,
y=50,
base_alignment=False,
)
main_group.append(right_text)
# Base Alignment parameter True
left_text_aligned = label.Label(
BIG_FONT,
text=TEXT_LEFT,
color=0xDD00DD,
x=10,
y=160,
base_alignment=True,
)
main_group.append(left_text_aligned)
right_text_aligned = label.Label(
MEDIUM_FONT,
text=TEXT_RIGHT,
color=0xDD00DD,
x=90,
y=160,
base_alignment=True,
)
main_group.append(right_text_aligned)
display.show(main_group)
while True:
pass

View file

@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
"""
Illustrates the color parameter of display_text label and bitmap_label
"""
import board
import displayio
import terminalio
from adafruit_display_text import label
# Make the display context. Change size if you want
display = board.DISPLAY
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
reg_label = label.Label(
font=terminalio.FONT,
text="CircuitPython",
scale=3,
color=0xDD00DD,
)
reg_label.anchor_point = (0, 0)
reg_label.anchored_position = (20, 20)
main_group.append(reg_label)
while True:
pass

View file

@ -0,0 +1,77 @@
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Illustrates the advanced usage of bitmap_label with transparency to
create a color mask cutout
"""
import board
import displayio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import bitmap_label as label
def wheel(pos):
# input a value 0 to 255 to get a color value
# the colors are a transition r-g-b-back to r.
if pos < 1 or pos > 255:
return (0, 0, 0)
if pos < 85:
return (255 - pos * 3, pos * 3, 0)
if pos < 170:
pos -= 85
return (0, 255 - pos * 3, pos * 3)
pos -= 170
return (pos * 3, 0, 255 - pos * 3)
# Make the display context. Change size if you want
display = board.DISPLAY
background = displayio.Bitmap(320, 240, 1)
bg_palette = displayio.Palette(1)
bg_palette[0] = 0xDDDD00
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
font = bitmap_font.load_font("fonts/LeagueSpartan-Bold-16.bdf")
reg_label = label.Label(
font=font,
text="CIRCUIT PYTHON",
padding_bottom=20,
color=None,
scale=1,
background_color=0x000000,
)
reg_label.anchor_point = (0.5, 0.5)
reg_label.anchored_position = (display.width // 2, display.height // 2)
rainbow_bitmap = displayio.Bitmap(
reg_label.bounding_box[2] * reg_label.scale,
reg_label.bounding_box[3] * reg_label.scale,
255,
)
rainbow_palette = displayio.Palette(255)
for i in range(0, 255):
rainbow_palette[i] = int("".join("%02x" % i for i in wheel(i)), 16)
for y in range(rainbow_bitmap.height):
for x in range(rainbow_bitmap.width):
rainbow_bitmap[x, y] = max(1, (x + 1) % 255)
bg_tilegrid = displayio.TileGrid(rainbow_bitmap, pixel_shader=rainbow_palette)
print(reg_label.bounding_box[0])
bg_tilegrid.x = reg_label.x + 1
bg_tilegrid.y = reg_label.y - 8
main_group.append(bg_tilegrid)
main_group.append(reg_label)
while True:
pass

View file

@ -0,0 +1,81 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
This examples shows the use of anchor_point and anchored_position.
"""
import board
import terminalio
import displayio
from adafruit_display_text import label
# Built-in display
display = board.DISPLAY
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
DISPLAY_WIDTH = 320
DISPLAY_HEIGHT = 240
TEXT = "Hello"
text_area_top_left = label.Label(terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2)
text_area_top_left.anchor_point = (0.0, 0.0)
text_area_top_left.anchored_position = (8, 8)
text_area_top_middle = label.Label(terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2)
text_area_top_middle.anchor_point = (0.5, 0.0)
text_area_top_middle.anchored_position = (DISPLAY_WIDTH / 2, 8)
text_area_top_right = label.Label(terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2)
text_area_top_right.anchor_point = (1.0, 0.0)
text_area_top_right.anchored_position = (DISPLAY_WIDTH - 8, 8)
text_area_middle_left = label.Label(terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2)
text_area_middle_left.anchor_point = (0.0, 0.5)
text_area_middle_left.anchored_position = (8, DISPLAY_HEIGHT / 2)
text_area_middle_middle = label.Label(
terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2
)
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, color=0xDD00DD, scale=2
)
text_area_middle_right.anchor_point = (1.0, 0.5)
text_area_middle_right.anchored_position = (DISPLAY_WIDTH - 8, DISPLAY_HEIGHT / 2)
text_area_bottom_left = label.Label(terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2)
text_area_bottom_left.anchor_point = (0.0, 1.0)
text_area_bottom_left.anchored_position = (8, DISPLAY_HEIGHT - 8)
text_area_bottom_middle = label.Label(
terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2
)
text_area_bottom_middle.anchor_point = (0.5, 1.0)
text_area_bottom_middle.anchored_position = (DISPLAY_WIDTH / 2, DISPLAY_HEIGHT - 8)
text_area_bottom_right = label.Label(
terminalio.FONT, text=TEXT, color=0xDD00DD, scale=2
)
text_area_bottom_right.anchor_point = (1.0, 1.0)
text_area_bottom_right.anchored_position = (DISPLAY_WIDTH - 8, DISPLAY_HEIGHT - 8)
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)
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)
display.show(text_group)
while True:
pass

View file

@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
This examples shows the use custom fonts
"""
import board
import displayio
import terminalio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label
# built-in display
display = board.DISPLAY
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
font = bitmap_font.load_font("fonts/LeagueSpartan-Bold-16.bdf")
# font = terminalio.FONT
reg_label = label.Label(font=terminalio.FONT, text="Blinka_Displayio", scale=2)
reg_label.anchor_point = (0, 0)
reg_label.anchored_position = (20, 20)
custom_font_lbl = label.Label(font=font, text="League Spartan", scale=1)
custom_font_lbl.anchor_point = (0, 0)
custom_font_lbl.anchored_position = (20, 50)
main_group.append(reg_label)
main_group.append(custom_font_lbl)
while True:
pass

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,15 @@
Greetings!
Thanks for choosing to use Fayette. A few things to note:
1. This typeface includes an entire set of glyphs(!) a few of which are important to note. Because smart-quotes are not automatic, the specific right and left quotation marks are found in the glyphs. (Quotes will need some manual adjusting in the Adobe suite, but they are all there an available in the glyphs!) Also, two versions of the lowercase 'f' (one to be used at the beginning of the word, another in the middle) exist, along with two of the lowercase 'r' for the same reason. There are three glyphs of the letter 't' (one long, swooping t, a second 'l-like' t, for use in double-t situations, and a single, less-swooped t, when the large swoop may interfere with legibility of surrounding letters.)
2. Fayette is free to use for commercial and personal use.
3. Fayette tends to work best in the Adobe Creative Suite, but should work in Microsoft Word (though I make no guarantees!) depending on the version you have.
4. Have fun using this typeface! I hope you enjoy it.
xo
Mia Cinelli
2012 // 2019

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,111 @@
Copyright (c) 2020, Caleb Maclennan <caleb@alerque>
Copyright (c) 2010-2012, Micah Rich <micah@micahrich.com>,
with Reserved Font Name: "League Gothic".
Copyright (c) 2010, Caroline Hadilaksono <caroline@hadilaksono>
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
Version 1.1 - 26 February 2007
----
SIL Open Font License
=====================
Preamble
--------
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
Definitions
-----------
`"Font Software"` refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
`"Reserved Font Name"` refers to any names specified as such after the
copyright statement(s).
`"Original Version"` refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
`"Modified Version"` refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
`"Author"` refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
Permission & Conditions
-----------------------
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1. Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2. Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3. No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4. The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5. The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
Termination
-----------
This license becomes null and void if any of the above conditions are
not met.
Disclaimer
----------
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,109 @@
Copyright (c) 2016-2020, Tyler Finck <hi@tylerfinck.com>
Copyright (c) 2014, Micah Rich <micah@micahrich.com>,
with Reserved Font Name: "League Spartan".
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
Version 1.1 - 26 February 2007
----
SIL Open Font License
=====================
Preamble
--------
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
Definitions
-----------
`"Font Software"` refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
`"Reserved Font Name"` refers to any names specified as such after the
copyright statement(s).
`"Original Version"` refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
`"Modified Version"` refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
`"Author"` refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
Permission & Conditions
-----------------------
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1. Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2. Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3. No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4. The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5. The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
Termination
-----------
This license becomes null and void if any of the above conditions are
not met.
Disclaimer
----------
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

View file

@ -0,0 +1,40 @@
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Illustrates the line_spacing parameter of label and bitmap_label
"""
import board
import displayio
import terminalio
from adafruit_display_text import label
# Make the display context. Change size if you want
display = board.DISPLAY
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
# font = bitmap_font.load_font("Fayette-HandwrittenScript-48.bdf")
font = terminalio.FONT
reg_label = label.Label(
font=font, text="Line1\nLine2\nLine3\n1.25", scale=2, line_spacing=1.25
)
reg_label.anchor_point = (0, 0)
reg_label.anchored_position = (20, 20)
bottom_label = label.Label(
font=font, text="Line1\nLine2\nLine3\n2.0", scale=2, line_spacing=2.25
)
bottom_label.anchor_point = (0, 0)
bottom_label.anchored_position = (110, 20)
main_group.append(reg_label)
main_group.append(bottom_label)
while True:
pass

View file

@ -0,0 +1,70 @@
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Illustrate padding parameters of label and bitmap_label
"""
import board
import displayio
import terminalio
from adafruit_display_text import label
# Built-in display
display = board.DISPLAY
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
# font = bitmap_font.load_font("Fayette-HandwrittenScript-48.bdf")
font = terminalio.FONT
reg_label = label.Label(
font=font, text="top", scale=2, background_color=0xDD00DD, padding_top=6
)
reg_label.anchor_point = (0, 0)
reg_label.anchored_position = (20, 20)
bottom_label = label.Label(
font=font, text="bottom", scale=2, background_color=0xDD00DD, padding_bottom=6
)
bottom_label.anchor_point = (0, 0)
bottom_label.anchored_position = (80, 20)
left_label = label.Label(
font=font, text="left", scale=2, background_color=0xDD00DD, padding_left=6
)
left_label.anchor_point = (0, 0)
left_label.anchored_position = (20, 70)
right_label = label.Label(
font=font, text="right", scale=2, background_color=0xDD00DD, padding_right=6
)
right_label.anchor_point = (0, 0)
right_label.anchored_position = (80, 70)
all_label = label.Label(
font=font,
text="all",
scale=2,
background_color=0xDD00DD,
padding_right=6,
padding_top=6,
padding_bottom=6,
padding_left=6,
)
all_label.anchor_point = (0, 0)
all_label.anchored_position = (40, 140)
main_group.append(left_label)
main_group.append(right_label)
main_group.append(all_label)
main_group.append(reg_label)
main_group.append(bottom_label)
while True:
pass

View file

@ -0,0 +1,40 @@
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Illustrate how the scale parameter of displayio.Group can be used to
change the size of label and bitmap_label
"""
import board
import displayio
import terminalio
from adafruit_display_text import label
# Built-in display
display = board.DISPLAY
# Make the display context
main_group = displayio.Group(max_size=10)
display.show(main_group)
font = terminalio.FONT
reg_label = label.Label(font=font, text="scale=1", scale=1)
reg_label.anchor_point = (0, 0)
reg_label.anchored_position = (20, 20)
scale2_lbl = label.Label(font=font, text="scale=2", scale=2)
scale2_lbl.anchor_point = (0, 0)
scale2_lbl.anchored_position = (20, 40)
scale3_lbl = label.Label(font=font, text="scale=3", scale=3)
scale3_lbl.anchor_point = (0, 0)
scale3_lbl.anchored_position = (20, 70)
main_group.append(reg_label)
main_group.append(scale3_lbl)
main_group.append(scale2_lbl)
while True:
pass