Skip to content

New parameter and example creation for testing and future reference #115

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
Feb 19, 2021
Merged

New parameter and example creation for testing and future reference #115

merged 10 commits into from
Feb 19, 2021

Conversation

jposada202020
Copy link
Contributor

With this change, we are adding a new parameter called base_alignment in the label library. Also we are including some tests to compare old behavior vs New behavior. This will address issues #103 and #100.
For back-compatibility parameter is set to False by default, that way old code created will still function with the new version

@jposada202020
Copy link
Contributor Author

@FoamyGuy

  from adafruit_display_text import label
  import displayio
  from blinka_displayio_pygamedisplay import PyGameDisplay
  from adafruit_bitmap_font import bitmap_font
  import terminalio
  import time
  import random
  
  display = PyGameDisplay(width=320, height=240)
  
  # Create the text label
  main_group = displayio.Group(max_size=18)
  
  # Test parameters
  TEXT_BACKGROUND_COLOR = [0xe0433, 0x990099, 0xd6d714, 0xd73014, 0x1415d7, 0x71646f]
  FONT_TESTS = [bitmap_font.load_font("Fayette-HandwrittenScript-24.bdf"),
                bitmap_font.load_font("LeagueSpartan-Bold-16.bdf"),
                terminalio.FONT]
  TEXT_COLOR = 0x00FF00
  X_COL_POS = [10, 110]  # X position of the Label boxes
  TEST_TEXT = ["aApPqQ.", 'ñúÇèüß']  # Iteration text for testing
  LOCALISATION_Y = [40, 80]  # Y coordinate of the text labels
  NUMBER_TEXT_LABELS = len(LOCALISATION_Y) * len(X_COL_POS)  # Calculation for Display.Group function
  TIME_BETWEEN_TEXTS = 3  # Seconds
  TEST_PADDING_VALUES = [-3, 0, 15]
  TEST_CHOICES = [True, False]
  BASE_ALIGNMENT_OPTIONS = [False, True]
  
  
  for behaviour in BASE_ALIGNMENT_OPTIONS:
      for padding in TEST_PADDING_VALUES:
          for text_test in TEST_TEXT:
              main_group = displayio.Group(max_size=NUMBER_TEXT_LABELS + 1)
              for position in LOCALISATION_Y:
                  text = label.Label(
                      font=FONT_TESTS[0],
                      text=text_test,
                      color=TEXT_COLOR,
                      background_tight=random.choice(TEST_CHOICES),
                      background_color=TEXT_BACKGROUND_COLOR[0],
                      x=X_COL_POS[0],
                      y=position,
                      base_alignment=behaviour,
                  )
                  main_group.append(text)
                  text = label.Label(
                      font=FONT_TESTS[1],
                      text=text_test,
                      color=TEXT_COLOR,
                      background_tight=False,
                      background_color=TEXT_BACKGROUND_COLOR[1],
                      x=X_COL_POS[1],
                      y=position,
                      base_alignment=behaviour,
                  )
                  main_group.append(text)
                  display.show(main_group)
                  display.refresh()
              time.sleep(TIME_BETWEEN_TEXTS)

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.

Thanks @jposada202020. I'm not sure what I saw last time but it does seem all good now with the Fayette font.

I think is pretty close to ready. It seems that when I merged the scale PRs it caused merge conflicts here. I think it can be resolved if you merge master into this branch. Let me know if you'd like help though, I'm happy to help out.

I'd like to get a simplified example if we can as well.

After those things I think this is probably good to go! Thanks again for working on this!

@jposada202020
Copy link
Contributor Author

@FoamyGuy Thanks for the revision, thanks for all the suggestions, For the code, you are right, I was just trying to find where the problem was :) ...I think I will use original code by @endico in issue #103 for the example. And also make the changes as suggested. Thanks for the review. And for your time 👍🏼

@jposada202020
Copy link
Contributor Author

...I forgot "it caused merge conflicts here. I think it can be resolved if you merge master into this branch. Let me know if you'd like help though, I'm happy to help out." Yes, I will need help with that. I will ping you when other changes are ready

@kmatch98
Copy link
Contributor

I ran the example code with a few different font files and it works great!

The Large font that's in the example wasn't in the repository fonts folder. Maybe add another large version of the LeagueSpartan to include in the repo to highlight this new feature?

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.

Thanks for working on this! I see the conflicts are handled now.

@jposada202020
Copy link
Contributor Author

@FoamyGuy I changed the example to include both 4 labels in the screen at all times, Thanks for the comments reviews, and help with this PR.

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 these changes successfully on PyPortal and MagTag. Changes look good to me. Thanks for working on this @jposada202020!

Here is how the new example looks on a MagTag:
image

I changed the big font to one I had available and adjusted the positions slightly to fit the magtag screen better.

@jposada202020
Copy link
Contributor Author

@FoamyGuy Team Work!!!! Thanks! You save us some time for the documentation :). Thank you

@kmatch98
Copy link
Contributor

@jposada202020 this is really helpful. Thanks for adding. Do you plan to do the same for the bitmap_label version?

@jposada202020
Copy link
Contributor Author

@kmatch98

Yes no problem. I will like to take a look at bitmap_label at the same time to do the Documentation (Including/Excluding features compared with Label) if that is ok?. So give me until the weekend :)

@FoamyGuy FoamyGuy merged commit 895c06d into adafruit:master Feb 19, 2021
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