LuaBox
Loading...
Searching...
No Matches
DisplayTextSize.h
Go to the documentation of this file.
1#pragma once
2
3#include "lua_include.h"
4#include "global.h"
5
23
24int DisplayTextSize(lua_State* L_)
25{
26 int arg_count = lua_gettop(L_);
27
28 const char* t = luaL_checkstring(L_, 1);
29 int size = 1;
30
31 if (arg_count >= 2)
32 size = luaL_checkinteger(L_, 2);
33
34 int sx = tft.textWidth(t);
35
36 int lines = 1;
37 for (const char* p = t; *p; p++)
38 if (*p == '\n')
39 lines++;
40
41 int sy = lines * tft.fontHeight() * size;
42
43 lua_newtable(L_);
44 lua_pushinteger(L_, sx);
45 lua_setfield(L_, -2, "x");
46
47 lua_pushinteger(L_, sy);
48 lua_setfield(L_, -2, "y");
49
50 return 1;
51}
int DisplayTextSize(lua_State *L_)
Calculate the pixel width and height of a text string on the sprite buffer.
Definition DisplayTextSize.h:24