Skip to content

fixing label padding #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2023
Merged

fixing label padding #187

merged 1 commit into from
Mar 13, 2023

Conversation

jposada202020
Copy link
Contributor

closes #185

Test code almost the same as previous PR by Neradoc

# setup the display (this was tested on a CPB with TFT gizmo)
# display = ...

from adafruit_display_text import label, bitmap_ll
import time
import displayio
import terminalio
import vectorio
import board


display = board.DISPLAY
# Make the display context
splash = displayio.Group(x=1, y=1, scale=3)
display.show(splash)
display.auto_refresh = False

color_palette = displayio.Palette(3)
color_palette[0] = 0x008000  # Bright Green
color_palette[1] = 0x808080 # 0xAA0088
color_palette[2] = 0x000022

lines = displayio.Group()
for num in range(21):
    y = 10 * num
    if num % 5 == 0:
        COLOR = 0
    else:
        COLOR = 1
    lines.append(vectorio.Rectangle(pixel_shader=color_palette,
        width=display.width, height=1, x=0, y=y, color_index=COLOR,
    ))
    lines.append(vectorio.Rectangle(pixel_shader=color_palette,
        width=1, height=display.height, x=y, y=0, color_index=COLOR,
    ))

text_group = displayio.Group(scale=1, x=0, y=0)

def add_text(border=0, x=0, y=0, anchor=(0,0), scale=1, direction="LTR", text=None, color=None, touse=None
        ):
    position = (x, y)
    if isinstance(border, int):
        border = (border, border, border, border)
    if touse == "label":
        text_area1 = label.Label(
            terminalio.FONT, text=text, color=0xFFFFFF,
            anchor_point=anchor,
            anchored_position=position,
            padding_top = border[0],
            padding_bottom = border[1],
            padding_left = border[2],
            padding_right = border[3],
            background_color = color,
            scale = scale,
            label_direction=direction,
        )
        text_group.append(text_area1)

    if touse == "bmlabel":
        text_area2 = bitmap_ll.Label(
            terminalio.FONT, text=text, color=0x000000,
            anchor_point=anchor,
            anchored_position=position,
            padding_top = border[0],
            padding_bottom = border[1],
            padding_left = border[2],
            padding_right = border[3],
            background_color=0xFFFFFF,
            scale=scale,
            label_direction=direction,
        )
        text_group.append(text_area2)




direction = "DWR"
add_text(border=(5, 0, 0, 0), x=5, y=5, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(5, 0, 0, 0), x=5, y=10, direction=direction, text="J", touse="bmlabel")
add_text(border=(0, 5, 0, 0), x=5, y=17, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 5, 0, 0), x=5, y=22, direction=direction, text="J", touse="bmlabel")
add_text(border=(0, 0, 5, 0), x=5, y=35, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 0, 5, 0), x=15, y=35, direction=direction, text="J", touse="bmlabel")
add_text(border=(0, 0, 0, 5), x=5, y=45, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 0, 0, 5), x=15, y=45, direction=direction, text="J", touse="bmlabel")
#
direction = "UPR"
add_text(border=(5, 0, 0, 0), x=30, y=5, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(5, 0, 0, 0), x=30, y=10, direction=direction, text="J", touse="bmlabel")
add_text(border=(0, 5, 0, 0), x=30, y=17, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 5, 0, 0), x=30, y=22, direction=direction, text="J", touse="bmlabel")
add_text(border=(0, 0, 5, 0), x=30, y=35, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 0, 5, 0), x=40, y=35, direction=direction, text="J", touse="bmlabel")
add_text(border=(0, 0, 0, 5), x=30, y=55, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 0, 0, 5), x=40, y=55, direction=direction, text="J", touse="bmlabel")


direction = "TTB"
add_text(border=(5, 0, 0, 0), x=65, y=15, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 5, 0, 0), x=65, y=35, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 0, 5, 0), x=65, y=55, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 0, 0, 5), x=65, y=75, direction=direction, text="J", color=0x440044, touse="label")


direction = "LTR"
add_text(border=(5, 0, 0, 0), x=90, y=5, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(5, 0, 0, 0), x=95, y=5, direction=direction, text="J", touse="bmlabel")
add_text(border=(0, 5, 0, 0), x=90, y=20, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 5, 0, 0), x=95, y=20, direction=direction, text="J", touse="bmlabel")
add_text(border=(0, 0, 5, 0), x=90, y=38, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 0, 5, 0), x=90, y=51, direction=direction, text="J", touse="bmlabel")
add_text(border=(0, 0, 0, 5), x=90, y=65, direction=direction, text="J", color=0x440044, touse="label")
add_text(border=(0, 0, 0, 5), x=90, y=78, direction=direction, text="J", touse="bmlabel")

splash.append(text_group)
splash.append(lines)
display.refresh()

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you @jposada202020!

I tested the changes successfully on a PyPortal Titano 8.0.3 with a slightly modified version of the example code posted here.

@FoamyGuy FoamyGuy merged commit 81998a6 into adafruit:main Mar 13, 2023
@jposada202020 jposada202020 deleted the fixing_label_padding branch March 13, 2023 23:13
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 14, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.28.0 from 2.26.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#188 from FoamyGuy/scrolling_label_text_prop
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#187 from jposada202020/fixing_label_padding

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

label.Label padding is wrong when using DWR or UPR
2 participants