Simple test

Ensure your device works with this simple test.

examples/styles_simpletest.py
import board
import terminalio
from adafruit_display_text import label
from styles import apply_style
from styles.styles import DarkBlue

text = "Hello world"
text_area = label.Label(terminalio.FONT, text=text)
text_area.x = 10
text_area.y = 10
apply_style(text_area, DarkBlue)
board.DISPLAY.show(text_area)
while True:
    pass

Advanced test

Shows different graphical elements changing styles on the fly.

examples/styles_advanced_example.py
import time
import board
import displayio
from adafruit_display_text import label
from adafruit_display_text.scrolling_label import ScrollingLabel
from adafruit_progressbar.horizontalprogressbar import (
    HorizontalProgressBar,
    HorizontalFillDirection,
)
from adafruit_bitmap_font import bitmap_font
from adafruit_button import Button
from styles import apply_style
from styles.styles import (
    DarkBlue,
    BlueMono,
    GreenMono,
    BrownBlue,
    BrightColors,
)


display = board.DISPLAY

# Creating a Label
font = bitmap_font.load_font("../fonts/Helvetica-Bold-16.bdf")
text_area = label.Label(font, text="Hello world", x=30, y=30)
main_group = displayio.Group()
main_group.append(text_area)

# Creating a Progress Bar
progress_bar = HorizontalProgressBar(
    (display.width // 2 - display.width // 2, display.height // 3),
    (display.width - 40, 30),
    direction=HorizontalFillDirection.LEFT_TO_RIGHT,
)
progress_bar.value = 50
main_group.append(progress_bar)

# Creating a Button
button = Button(
    x=display.width // 2,
    y=display.height // 2,
    width=100,
    height=50,
    style=Button.ROUNDRECT,
    fill_color=0x00FFFF,
    outline_color=0xFF00FF,
    label="Hello world",
    label_font=font,
    label_color=0x000000,
)
main_group.append(button)

# Creating a Scrolling Label
my_scrolling_label = ScrollingLabel(
    font,
    text="Hello world CircuitPython scrolling label",
    max_characters=20,
    animate_time=0.3,
    x=30,
    y=200,
)
main_group.append(my_scrolling_label)
# Preparing the Colors to display
colors_change = [DarkBlue, BlueMono, GreenMono, BrownBlue, BrightColors]
display.show(main_group)
counter = 0

while True:
    if counter == len(colors_change):
        counter = 0
    apply_style(text_area, colors_change[counter])
    apply_style(progress_bar, colors_change[counter])
    apply_style(button, colors_change[counter])
    apply_style(my_scrolling_label, colors_change[counter])
    current_time_counter = time.time()
    while True:
        my_scrolling_label.update()
        if time.time() - current_time_counter > 4:
            break
    display.refresh()
    time.sleep(4)
    counter = counter + 1

List Select Example

An example using the community library ListSelect

examples/styles_list_select_example.py
import time
import displayio
import board
from displayio_listselect import ListSelect
from styles import apply_style
from styles.styles import Topanga

# Make the display context. Change size if you want
display = board.DISPLAY

# Make the display context
main_group = displayio.Group()
display.show(main_group)

items = ["First", "Second", "Third", "Fourth"]

list_select = ListSelect(scale=2, items=items)

# Applying some style to the list
apply_style(list_select, Topanga)

main_group.append(list_select)

list_select.anchor_point = (0.5, 0.5)
list_select.anchored_position = (display.width // 2, display.height // 2)

for i in range(3):
    list_select.move_selection_down()
    time.sleep(1)

for i in range(3):
    list_select.move_selection_up()
    time.sleep(1)

list_select.selected_index = 3
while True:
    pass