Skip to content

Directional label #135

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 10 commits into from
Mar 19, 2021
Merged

Directional label #135

merged 10 commits into from
Mar 19, 2021

Conversation

jposada202020
Copy link
Contributor

@jposada202020 jposada202020 commented Mar 10, 2021

Current proposal will modify the display_text label capabilities. This will introduces four new text directions:

  • Left-To-Right (LTR)
  • Top-To-Bottom (TTB)
  • Upwards (UPR)
  • Downwards (DWR)

By default label will be in LTR mode, so old code will function. Text direction will be set-up by label_direction parameter.
All the parameters works, this include:

  • Anchor Point
  • Base_alignment
  • Padding
  • Scale

Known Issues:

  • Text_background for TTB needs tweaking when setting up with base_alignment = True
  • Needs testing for Baseline.anchorpoint not tested
  • No logic was develop for new text. Features for features were not done.
    In order to test with other languages, please use the following font
    https://github.com/jposada202020/sandbox_display_text/blob/master/Helvetica-Bold-16.bdf
    . I have manually added the correct characters in BDF file in order to example to work in the display.
  • I had some problems during testing with the background, I have submit an issue.

Results

image

Test Code

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

import terminalio
import displayio
from os import uname
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")



bitmap = displayio.Bitmap(4, 320, 2)
palette = displayio.Palette(2)
palette[0] = 0x004400
palette[1] = 0x00FFFF
tile_grid = displayio.TileGrid(bitmap,
                               pixel_shader=palette,
                               x=155,
                               y=0)
splash.append(tile_grid)

bitmap = displayio.Bitmap(320, 4, 2)
tile_grid = displayio.TileGrid(bitmap,
                               pixel_shader=palette,
                               x=0,
                               y=110)
splash.append(tile_grid)


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

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


splash.append(text_area)

text = "V6.2.0"
text_area = label.Label(MEDIUM_FONT,
                        text=text,
                        label_direction="UPR",
                        padding_left=5,
                        padding_top=7,
                        padding_bottom=2,
                        background_color=0x990099,
                        padding_right=19)
text_area.x = 155
text_area.y = 90
splash.append(text_area)

text = "Blinka"
text_area = label.Label(MEDIUM_FONT,
                        text=text,
                        label_direction="DWR",
                        background_color=0x990099,
                        padding_left=10,
                        padding_top=10,
                        padding_bottom=10,
                        padding_right=10)
text_area.x = 155
text_area.y = 130
splash.append(text_area)

text = "我 是 高大壮"
text_area = label.Label(MEDIUM_FONT,
                        text=text,
                        label_direction="TTB",
                        padding_left=1,
                        padding_top=1,
                        padding_bottom=1,
                        padding_right=1,
                        background_color=0x990099,
                        anchor_point=(1.0, 0.0),
                        anchored_position=(display.width, 0),
                        base_alignment=False)

splash.append(text_area)

text = "מזל טוב"
text_area = label.Label(MEDIUM_FONT,
                        text=text,
                        
                        padding_left=1,
                        padding_top=1,
                        padding_bottom=1,
                        padding_right=1,
                        anchor_point=(1.0, 1.0),
                        background_color=0x990099,
                        label_direction="LTR",
                        anchored_position=(display.width, display.height),
                        )

splash.append(text_area)



display.show(splash)

@jposada202020
Copy link
Contributor Author

@FoamyGuy @kmatch98 could you kindly review.. and do some testing if possible. Thanks.

@hugodahl as discussed enclosed the new label for the Vertical progress bar. Thanks!

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.

This is looking pretty good @jposada202020. Thank you for all of your work on this!

I tested these changes using a modified simpletest script on

Adafruit CircuitPython 6.2.0-beta.3-182-g651f54b4c-dirty on 2021-03-14; Adafruit PyPortal with samd51j20

I tested all available directions and they were all working well for me.

I have a few suggestions if you think they would be good.

I'm also curious if you are willing to implement this functionality in the bitmap_label as well?

@jposada202020
Copy link
Contributor Author

This is looking pretty good @jposada202020. Thank you for all of your work on this!

I tested these changes using a modified simpletest script on

Adafruit CircuitPython 6.2.0-beta.3-182-g651f54b4c-dirty on 2021-03-14; Adafruit PyPortal with samd51j20

I tested all available directions and they were all working well for me.

I have a few suggestions if you think they would be good.

I'm also curious if you are willing to implement this functionality in the bitmap_label as well?

Yes, that is the idea, I like to do initial work on label and then extend to btmap_label once the feedback, revisions, request for changes and suggestions are in.

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 for this awesome new feature!

@FoamyGuy FoamyGuy merged commit a3112cd into adafruit:master Mar 19, 2021
@jposada202020
Copy link
Contributor Author

@FoamyGuy thanks for the review

@jposada202020 jposada202020 deleted the directional_label branch March 19, 2021 01:54
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 19, 2021
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.

2 participants