Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

feature request: align text in matrixportal/pyportal
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

feature request: align text in matrixportal/pyportal

by grookill on Wed Mar 10, 2021 9:45 pm

Hmm. I've been struggling to properly align some dynamic text (time of day) on my MatrixPortal. Given a time of day, the string is going to be either 5 characters (like "11:22") or 4 characters (like "8:13"). I'd like the string to be centered on the matrix. It would be great if "add_text" had an "text_align" option, which would kind of replace the current "text_position" option. For example, I would love to do:

Code: Select all | TOGGLE FULL SIZE
matrixportal.add_text(
    text_font=terminalio.FONT,
    text_position=(CENTER, 25),
)


In this case, text_postion asks that the text be centered on the screen and the top of the text is at row 25. When "set_text" is called, the routine will then determine where to put the top left text pixel based upon how wide the text string is, probably something similar to ((matrixportal.width()//2) - (( (chars in message) * (character width) ) // 2) * text_scale). Doing this will allow the text string (in my case, the time) to always be centered on the matrix.

Admittedly this is tough to do, given the near infinite number of fonts available, but perhaps such a beast could be added for just the standard terminalio font?

grookill
 
Posts: 12
Joined: Sat Feb 02, 2019 4:25 am

Re: feature request: align text in matrixportal/pyportal

by mikeysklar on Fri Mar 12, 2021 2:13 pm

@grookill,

I was going to recommend that you open an issue with the Adafruit_CircuitPython_MatrixPortal github repo requesting this, but it kind of looks like CENTER is the default with scrolling text.

Code: Select all | TOGGLE FULL SIZE
        if scrolling:
            if text_position is None:
                # Center text if position not specified
                text_position = (self.display.width, self.display.height // 2 - 1)
            else:
                text_position = (self.display.width, text_position[1])



https://github.com/adafruit/Adafruit_Ci ... xportal.py

mikeysklar
 
Posts: 4154
Joined: Mon Aug 01, 2016 8:10 pm

Re: feature request: align text in matrixportal/pyportal

by grookill on Sat Mar 13, 2021 3:16 am

...kind of looks like CENTER is the default with scrolling text.


I may have glossed over that line half a dozen times because it deals with scrolling text. "Kind of" is the operative phrase here. The model I'm working with is a variable length string (time) that has a fixed height and a fixed center position. Looking at https://learn.adafruit.com/network-connected-metro-rgb-matrix-clock, there is code to center the time:

Code: Select all | TOGGLE FULL SIZE
    bbx, bby, bbwidth, bbh = clock_label.bounding_box
    # Center the label
    clock_label.x = round(display.width / 2 - bbwidth / 2)
    clock_label.y = display.height // 2


I'll think about this some more and maybe do some testing before I decide to open an issue on Github. I have this nagging feeling that adding something like a "CENTER" option to MatrixPortal's string library may be opening up a can of design worms that should be left closed.

In any case, it's simple enough to avoid using adafruit_matrixportal text system and use adafruit_display_text instead. It may mean more coding on my end though...

Thank you for your reply. I really should have seen that fragment in MatrixPortal...

grookill
 
Posts: 12
Joined: Sat Feb 02, 2019 4:25 am

Please be positive and constructive with your questions and comments.