peterhinch / micropython-micro-gui

A lightweight MicroPython GUI library for display drivers based on framebuf, allows input via pushbuttons. See also micropython-touch.
MIT License
247 stars 37 forks source link

Feature: text align #11

Closed petrkr closed 2 years ago

petrkr commented 2 years ago

I think calculate some text align will not be easy part.

I have some labels as "status" messages, and those will be handy to have in center, but problem is status messages have different length, so fixed position is not good.

peterhinch commented 2 years ago

The Label widget supports only left alignment. However you can display text using the Writer or CWriter object - the stringlen method returns the length of the string in pixels. You can therefore determine the start location for centre alignment. One approach might be to subclass Label although I haven't considered this in detail.

peterhinch commented 2 years ago

I have pushed an update: the Label widget now supports a justify constructor arg allowing left, centre and right justification. Thank you for the suggestion: it proved easy to implement and is a worthwhile enhancement.

petrkr commented 2 years ago

Pretty cool https://youtu.be/mnMPRWHL11k