adafruit / Adafruit_CircuitPython_Display_Text

Library to display text using displayio
MIT License
57 stars 38 forks source link

Style label #143

Closed jposada202020 closed 3 years ago

jposada202020 commented 3 years ago

HISTORY

After our CircuitPython meeting on 2021-03-15. It was decided to use the library colorsys as a helper to add style for different widgets. old PR #139 will be closed and changes will be followed in this. This new PR uses the new unpackaged library. For completion I added the same text as previous PR. I include also a new example of usage

Features

The change will add the feature to use label with styles. With this feature you could possible create the same style among differents widgets. The syles are taken from the PySimpleGui Project

Changes

There are changes in the following files:

Tests

Expected result of the example is: image

Others

See https://github.com/adafruit/Adafruit_CircuitPython_CPython/issues/13 for projects updates. Code example, style file and helper functions will be added there

TEST CODE

# SPDX-FileCopyrightText: 2021 Jose David Montoya
# SPDX-License-Identifier: MIT

import terminalio
import displayio
from os import uname
import time

if uname()[0] == 'samd51':
    import board
else:
    from blinka_displayio_pygamedisplay import PyGameDisplay
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font

if uname()[0] == 'samd51':
    display = board.DISPLAY
else:
    display = PyGameDisplay(width=320, height=240)
splash = displayio.Group(max_size=10)
MEDIUM_FONT = bitmap_font.load_font("fonts/Helvetica-Bold-16.bdf")

text = "CircuitPython"
text_area = label.Label(MEDIUM_FONT,
                        text=text,
                        label_direction="LTR",
                        background_tight=True,
                        x=155,
                        y=110,
                        padding_left=10,
                        padding_top=10,
                        padding_bottom=10,
                        padding_right=10,)

splash.append(text_area)
display.show(splash)
time.sleep(1)

text_area.label_direction = "UPR"
text_area.label_style = "DarkRed2"
display.show(splash)
time.sleep(1)
text_area.label_direction = "RTL"
text_area.label_style = "DarkGreen5"
display.show(splash)
time.sleep(1)
text_area.label_direction = "DWR"
text_area.label_style = "LightGreen8"
display.show(splash)
time.sleep(1)
text_area.label_direction = "TTB"
display.show(splash)
time.sleep(1)
text = "CircuitPython"

while True:
    pass
jposada202020 commented 3 years ago

Closing this in here, a new Library will be in place to deal with the styles, and we would not need to add the code in these libraries to use it. For reference on developing please follow this in here, however is not official by any means just yet. https://github.com/jposada202020/Adafruit_CircuitPython_Styles/issues/4