lhadj / glcd-arduino

Automatically exported from code.google.com/p/glcd-arduino
0 stars 0 forks source link

Ability to do text justification (center, left, right) #39

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
There have been some requests to add the ability to justify text on the display.
This is actually quite a useful capability.

While it would be possible to do this on the fly on a row as the text comes in,
that method would require buffering all the text on the display and
continually having to re-draw the row of text as it is coming.
When doing the on-the-fly justification, users will also probably expect
word breaks across line wrapping to work, which adds in another layer
of complexity.t  It also gets very messy with variable width fonts.

A simpler/easier solution that provides enough functionality that would
probably satisfy most needs, would be to expand the DrawString() API call.
This would allow the user to specify justification parameters rather than
the absolute x,y location and then let the library calculate the x,y location
based on the desired justification.

Since DrawString operates on text areas, this allows the justification to be 
based
on the text area used to make the DrawString() call.

The API could allow horizontal justification of left, right, and center.
For vertical the possibilities are: 
current row/Y, this exact row, vcenter text area, top text area, bottom text 
area.

The horizontal justification could use a single parameter enum
The vertical could as well when not using exact row by using
"very large"/"out of bounds" row value for the enums.
That way the user can use a row
value or these defines/enums to indicate the preference.

One thing to be cautious of is  that if this is added by overloading the 
existing DrawSting() that function already takes three parameters, and while 
they currently are *ptr, uint8_t x, uint8_t y in the future the x & y values 
may need to be bumped to larger than 8 bits.
So this new function either needs to use signed ints for overloading or use a 
different named function to prevent future function collisions.

Original issue reported on code.google.com by bperry...@gmail.com on 11 Sep 2011 at 5:55

GoogleCodeExporter commented 8 years ago
Another thing to consider is whether this API call should also have an option 
for the ability to clear or not clear the entire row as the string is printed.

Original comment by bperry...@gmail.com on 11 Sep 2011 at 6:00

GoogleCodeExporter commented 8 years ago
This will be implemented as an extension to DrawString().
The current working experimental implementation uses this prototype:
void DrawString(char *str, int x, int y, eraseLine_t erase);

This allows x and y to be overloaded with either an x/y coordinate
or a formating token. 
The x token can determine left/center/right/current location
The y token can determine top/center/bottom/current location
The erase parameter is optional and will be eraseNONE by default.

This allows a single function to add new functionality and maintain full 
backward
compatibility.

Original comment by bperry...@gmail.com on 27 Sep 2011 at 6:21

GoogleCodeExporter commented 8 years ago
Drawstring() will also support text row/column.
The prototype is now:
void DrawString(char *str, int hpos, int vpos, eraseLine_t erase);

and hpos/vpos are now
- formatting token
- x/y value (if positive value)
- column/row (if negative value)

Original comment by bperry...@gmail.com on 25 Dec 2011 at 7:59