Add Lua function lcd.drawTextLines(...) drawing text across multiple lines inside bounding box

This commit is contained in:
jfrickmann
2021-09-02 14:33:14 -04:00
parent 88b8ac86fb
commit b100d9a164
3 changed files with 40 additions and 4 deletions
+36
View File
@@ -289,6 +289,41 @@ static int luaLcdSizeText(lua_State *L)
return 2;
}
/*luadoc
@function lcd.drawTextLines(x, y, w, h, text [, flags])
Draw text inside rectangle (x,y,w,h) with line breaks
@param x,y (positive numbers) starting coordinate
@param w,h (positive numbers) width and height of bounding rectangle
@param text (string) text to display
@param flags (optional) please see [Lcd functions overview](../lcd-functions-less-than-greater-than-luadoc-begin-lcd/lcd_functions-overview.html) for drawing flags and colors, and [Appendix](../../part_vii_-_appendix/fonts.md) for available characters in each font set. INVERS and BLINK are not implemented.
@status current Introduced in 2.5.0
*/
static int luaLcdDrawTextLines(lua_State *L)
{
if (!luaLcdAllowed || !luaLcdBuffer)
return 0;
int x = luaL_checkinteger(L, 1);
int y = luaL_checkinteger(L, 2);
int w = luaL_checkinteger(L, 3);
int h = luaL_checkinteger(L, 4);
const char * s = luaL_checkstring(L, 5);
LcdFlags flags = luaL_optunsigned(L, 6, 0);
// apply text offsets, needed to align 2.4.x to 2.3.x font baselines
x += getTextHorizontalOffset(flags);
y += getTextVerticalOffset(flags);
drawTextLines(luaLcdBuffer, x, y, w, h, s, flags);
return 0;
}
/*luadoc
@function lcd.drawTimer(x, y, value [, flags [, inversColor]])
@@ -1159,6 +1194,7 @@ const luaL_Reg lcdLib[] = {
{ "drawRectangle", luaLcdDrawRectangle },
{ "drawFilledRectangle", luaLcdDrawFilledRectangle },
{ "drawText", luaLcdDrawText },
{ "drawTextLines", luaLcdDrawTextLines },
{ "sizeText", luaLcdSizeText },
{ "drawTimer", luaLcdDrawTimer },
{ "drawNumber", luaLcdDrawNumber },