Skip to content

Bitmap label base alignment #120

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 12 commits into from
Feb 20, 2021
Merged

Bitmap label base alignment #120

merged 12 commits into from
Feb 20, 2021

Conversation

jposada202020
Copy link
Contributor

There present PR is to include new parameter base_alignment to the bitmap_label. This parameter will allow to align to different bitmap_label along the baseline. This is similar to the work done on the label library.
Including in this text the code used to test. Also included a Picture of the results.
As you can see in the picture, including this parameter will allow the user to align both the Label and the bitmap_label at the same time. If a sample code is needed let me know. I consider that the example for the base_label parameter in label is enough.
@kmatch98 if you can take a look at this, I am guessing that you are the writer of this library. So any input would be appreciated.
And sorry again for the fonts :)
Test code @FoamyGuy I know my test are complicated ;)

import time
from blinka_displayio_pygamedisplay import PyGameDisplay
import displayio
from adafruit_bitmap_font import bitmap_font
import terminalio
from adafruit_display_text import bitmap_label
from adafruit_display_text import label

display = PyGameDisplay(width=320, height=240)


# Test parameters
TEXT_BACKGROUND_COLOR = [0xe0433, 0x990099, 0xd6d714, 0xd73014, 0x1415d7, 0x71646f]
TEXT_COLOR = 0x00FF00
FONT_TESTS = [bitmap_font.load_font("IBMPlexMono-Medium-24_jep.bdf"),
              bitmap_font.load_font("LeagueSpartan-Bold-16.bdf"),
              bitmap_font.load_font("Fayette-HandwrittenScript-24.bdf"),
              terminalio.FONT]
TEXT_X_PLACES = [10, 80, 120, 190, 230]
main_group = displayio.Group(max_size=9)
text = ["34.47", "MG"]
text_area_left = bitmap_label.Label(FONT_TESTS[3],
                                    text=text[0],
                                    background_color=TEXT_BACKGROUND_COLOR[1],
                                    x=TEXT_X_PLACES[0], y=100)
text_area_right = bitmap_label.Label(FONT_TESTS[1], text=text[1],
                                     background_color=TEXT_BACKGROUND_COLOR[3], x=TEXT_X_PLACES[1], y=100)

text_area_left_aligned = bitmap_label.Label(FONT_TESTS[0],
                                            text=text[0],
                                            background_color=TEXT_BACKGROUND_COLOR[1],
                                            x=TEXT_X_PLACES[0],
                                            y=150,
                                            background_tight=False,
                                            padding_top=15,
                                            padding_left=4,
                                            base_alignment=True)
text_area_right_aligned = bitmap_label.Label(FONT_TESTS[1],
                                             text=text[1],
                                             background_color=TEXT_BACKGROUND_COLOR[3],
                                             x=TEXT_X_PLACES[1],
                                             y=150,
                                             background_tight=False,
                                             padding_bottom=5,
                                             padding_right=8,
                                             base_alignment=True)

text_area_left_aligned_true = bitmap_label.Label(FONT_TESTS[0],
                                                text=text[0],
                                                background_color=TEXT_BACKGROUND_COLOR[1],
                                                x=TEXT_X_PLACES[2],
                                                y=150,
                                                background_tight=True,
                                                base_alignment=True)
text_area_right_aligned_true = bitmap_label.Label(FONT_TESTS[1],
                                                 text=text[1],
                                                 background_color=TEXT_BACKGROUND_COLOR[3],
                                                 x=TEXT_X_PLACES[3],
                                                 y=150,
                                                 background_tight=True,
                                                 base_alignment=True)

right_text_aligned = label.Label(
    FONT_TESTS[1],
    text=text[1],
    color=0x000000,
    background_color=0x999999,
    x=TEXT_X_PLACES[4],
    y=150,
    base_alignment=True
)


main_group.append(text_area_right)
main_group.append(text_area_left)
main_group.append(text_area_right_aligned)
main_group.append(text_area_left_aligned)
main_group.append(text_area_right_aligned_true)
main_group.append(text_area_left_aligned_true)
main_group.append(right_text_aligned)

bitmap = displayio.Bitmap(280, 5, 2)
palette = displayio.Palette(2)
palette[0] = 0x004400
palette[1] = 0x00FFFF
tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette, x=10, y=100)
main_group.append(tile_grid)


bitmap = displayio.Bitmap(300, 5, 2)
tile_grid2 = displayio.TileGrid(bitmap, pixel_shader=palette, x=10, y=150)
main_group.append(tile_grid2)

display.show(main_group)

while True:
    pass

image

@kmatch98
Copy link
Contributor

Wow this looks really great and thanks fro getting this done so promptly! I’m actually right in the middle of something that needs this exact function so I’m eager to try it out.

I had some unexpected guests arrive today (housing some friends that los power) so it may take me a day or two to put this through its paces. So my apologies if it takes some time for me to try it out and get you any constructive feedback.

1 similar comment
@kmatch98
Copy link
Contributor

Wow this looks really great and thanks fro getting this done so promptly! I’m actually right in the middle of something that needs this exact function so I’m eager to try it out.

I had some unexpected guests arrive today (housing some friends that los power) so it may take me a day or two to put this through its paces. So my apologies if it takes some time for me to try it out and get you any constructive feedback.

@kmatch98
Copy link
Contributor

@jposada202020 This looks great to me. And thanks for the detailed review of typos in the comments.

I tried the example and then some other code I'm working on and the base_alignment option works great to me. Also, the Fayette typeface is a good trial, and it worked as it should. The background_tight feature worked properly, too.

I recommend that we change base_alignment=True to the default case. I think it will be easier to understand for any new designs, yet folks using previous versions can always fall back to the older version. If we change the default behavior, an additional comment in the documentation strings may help head off some questions.

This looks good to me. Thanks for the making these changes, this is a helpful addition to both these libraries.

@jposada202020
Copy link
Contributor Author

@kmatch98 Thanks for the quick answer, revision and effort put into this.

For the default to be True, I have not issue with that. It would change from revision to version to let people know that the behavior will change as the label/bitmap_label will not longer center around the midpoint, this will imply also changing the Learning Guides. Both, I am ok with both, redoing the PR to do that change in both libraries it would not represent a lot of work.

@kmatch98
Copy link
Contributor

@FoamyGuy and @jepler any feedback on changing the default for baseline alignment?

@FoamyGuy
Copy link
Contributor

I think I lean toward defaulting it to False so that the positioning behavior stays the same as it is today by default.

I do think new way is nicer, so I can see the appeal of defaulting to that. But it would cause any existing code to start placing things differently so folks would have to go back and either add the parameter and set it False or potentially adjust the position to account for the difference.

I'm open to input from others as well though, I do admit I tend to go toward not changing defaults more often than not. Sometimes I overestimate how much trouble the change will actually cause in the end.

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.

I tested this successfully on Adafruit CircuitPython 6.2.0-beta.2 on 2021-02-11; Adafruit PyPortal with samd51j20

Looks good to me. Thank you @jposada202020!

@FoamyGuy FoamyGuy merged commit 89562e3 into adafruit:master Feb 20, 2021
@jposada202020
Copy link
Contributor Author

@FoamyGuy @kmatch98 Thank you for the support and reviews and comments :)

adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Feb 20, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_datetime to 1.1.0 from 1.0.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_datetime#2 from makermelissa/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 2.14.0 from 2.12.4:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#120 from jposada202020/bitmap_label_base_alignment
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#115 from jposada202020/base_alignement_proposal
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.

3 participants