Skip to content

Font-based row height #5

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 2 commits into from
Jul 28, 2021

Conversation

lesamouraipourpre
Copy link
Contributor

@lesamouraipourpre lesamouraipourpre commented Jul 23, 2021

Add dynamic row heights based on font used. (Closes #3)
The row heights are almost certainly different to the previous version. This may affect some deployed code.

Deprecate title_length, ignore it for now. It is no longer needed with the update to Adafruit_CircuitPython_Display_Text removing max_glyphs.

Refactor the scaling so that the text_scale is not a multiple of the title_scale.

Correctly add multiple rows with the color-cycling effect. Previously all new rows had the same color.

Tested on Pynt with 7.0.0-alpha.5 and the following code, testing both fonts in different runs:

import microcontroller
import terminalio
from adafruit_bitmap_font import bitmap_font
from adafruit_simple_text_display import SimpleTextDisplay

FONT = bitmap_font.load_font("/fonts/LibreBodoniv2002-Bold-27.bdf")  # A big font
FONT = terminalio.FONT  # A small font
temperature_data = SimpleTextDisplay(
    title="Temperature Data!", title_scale=1, font=FONT, text_scale=2
)

temperature_data[14].text = "Row 14"
temperature_data[13].text = "Row 13"
temperature_data[12].text = "Row 12"
temperature_data[11].text = "Row 11"
temperature_data[10].text = "Row 10"
temperature_data[9].text = "Row 9"
temperature_data[8].text = "Row 8"
temperature_data[7].text = "Row 7"
temperature_data[6].text = "Row 6"
temperature_data[5].text = "Row 5"
temperature_data[4].text = "Row 4"
temperature_data[3].text = "Row 3"
temperature_data[2].text = "Row 2"
temperature_data[1].text = "Row 1"
temperature_data[0].text = "Row 0"

while True:
    temperature_data[0].text = "Temperature: {:.2f} degrees C".format(
        microcontroller.cpu.temperature
    )
    temperature_data[1].text = "Temperature: {:.2f} degrees F".format(
        (microcontroller.cpu.temperature * (9 / 5) + 32)
    )
    temperature_data.show()

Deprecate 'title_length', ignore it for now. It is no longer needed with the update to Adafruit_CircuitPython_Display_Text removing 'max_glyphs'.

Refactor the scaling so that the 'text_scale' is not a multiple of the 'title_scale'.

Correctly add multiple rows with the color-cycling effect. Previously all new rows had the same color.
@lesamouraipourpre
Copy link
Contributor Author

If anyone has any deployed code and can check this against it, especially MacroPad related, that would be great

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.

These changes look good to me.

I tested the example code that @lesamouraipourpre provided on a PyPortal with CircuitPython 7.0.0-alpha.4 and confirmed the issue noted with colors repeating.

I also tested the simpletest example from this repo as well as the example provided in the MacroPad library docs for the display_text() function from the MacroPad library. All of these appear to be working as intended to me.

I also tried using a few different custom fonts in the above examples and confirmed that this does fix the issue of text getting stacked on top of each other as shown in the picture from the issue linked at the top of this PR.

@lesamouraipourpre
Copy link
Contributor Author

As far as I can tell from grepping the Learn Guides repo, the only learn guide that uses the display_text() method of MacroPad is
https://learn.adafruit.com/adafruit-macropad-rp2040/macropad-midi

@FoamyGuy
Copy link
Contributor

I will try out the midi project tomorrow to ensure the UI still looks as expected with these changes.

@FoamyGuy
Copy link
Contributor

I tested the Midi project today on MacroPad with 7.0.0-alpha.5. When running the version from this PR it is nearly identical to running the currently released version of Simple_Text_Display.

The one tiny difference that I noticed is there appears to be a few pixels of space between the title text row and the first "normal" text row in the currently released version. Maybe 3-4px or so. If we want to get this back we could add a few pixels to _next_y when setting it after creating the title text. I'm not sure if that space was intentional originally or not we can check with Kattni during the week. I don't really have a preference on it though either way seems fine to me.

@lesamouraipourpre
Copy link
Contributor Author

I'm slightly paranoid because of the rumours on Discord of the contents of the new Adabox. I don't want this update to mess up any demo code that is planned.

@lesamouraipourpre
Copy link
Contributor Author

Code tested on a 240x135 screen with title_scale=1 and text_scale=1

Before PR
Title was given 18 pixels and text 13 pixels
IMG_20210727_075457__01
After PR Apologies for the poor focus
Title and text get 14 pixels as determined from font
IMG_20210727_082607__01

I'm happy for this to be merged. If it's felt that we need to add extra padding around the title that can be done in a follow-up PR.

@tannewt tannewt merged commit 4652367 into adafruit:main Jul 28, 2021
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Aug 4, 2021
Updating https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx to 2.5.0 from 2.4.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_MCP230xx#41 from Red-M/master
  > Moved default branch to main
  > Moved CI to Python 3.7

Updating https://github.com/adafruit/Adafruit_CircuitPython_SCD4X to 1.1.0 from 1.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_SCD4X#2 from lesamouraipourpre/constants
  > Merge pull request adafruit/Adafruit_CircuitPython_SCD4X#4 from lesamouraipourpre/docs

Updating https://github.com/adafruit/Adafruit_CircuitPython_SGP40 to 1.2.0 from 1.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_SGP40#6 from caternuson/iss5

Updating https://github.com/adafruit/Adafruit_CircuitPython_MacroPad to 1.3.0 from 1.2.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_MacroPad#15 from kattni/rotation
  > Merge pull request adafruit/Adafruit_CircuitPython_MacroPad#14 from kattni/display-image-fix

Updating https://github.com/adafruit/Adafruit_CircuitPython_Simple_Text_Display to 1.2.0 from 1.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Simple_Text_Display#6 from terop/fix_doc_typo
  > Merge pull request adafruit/Adafruit_CircuitPython_Simple_Text_Display#5 from lesamouraipourpre/adaptive-row-height

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_IS31FL3741
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.

The row height of the text is hard-coded
3 participants