Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
allow various alignment corners & centers #4
adafruit gfx does baseline https://github.com/adafruit/Adafruit-GFX-Library/blob/master/Adafruit_GFX.cpp#L1033
Thinking more about this I don't think we want baseline because it handles multiline text poorly. The examples above don't handle multiline layout themselves but TextArea does.
Before we add anchor options, I think defaulting to vertical center of the left edge of the text would provide the best default behavior for both single and multiline text.
Since the overall bounding box is much larger than most glyphs, I think we should use the capital M's measurements to determine line size. Therefore, the vertical center would be
We cannot base the origin on the actual glyphs because that risks different alignment across aligned TextAreas.
Does that make sense?
Later we can add top left and bottom left anchors based on the M too. We'll also want to expose a bounding box or vertical padding so the user can account for ascenders and descenders.
I also think we should remove
Coming back to this because we had someone in the discord run into a case where the
I also find the behavior of the
As a suggestion, I'd propose we go to the same behavior as PICO8, Cairo, and other common font renders: the
So, something like:
from adafruit_display_text import TextArea font = .. text = TextArea(font, "Hallo Ásta\nGóðan daginn", color=0xFFCC00) # The extents of the text can be used directly to align the text, # in this example, it centers the text on the display. text.x = display.width / 2 - text.width / 2 text.y = display.height / 2 - text.height / 2 # Or helper methods can be used text.center(display.width / 2, display.height /2) text.center_horizontal(display.width / 2) text.center_vertical(display.height / 2) text.left_align(x=20) text.right_align(x=160) text.top_align(y=20) text.bottom_align(y=120)
We did the vertical y alignment to have the best result when rendering text in a button. Having it be the top left requires adjustment depending on the number of lines of text where vertical centering looks somewhat better.
I'd love to see other options available though.