Font:getWrap can now accept a colored text table in the same format as what's accepted by love.graphics.print. Resolves issue #1108.

The returned table of strings still has no color information.
This commit is contained in:
Alex Szpakowski
2015-12-20 19:25:09 -05:00
parent efa08b1e44
commit 2ad1712eaf
3 changed files with 11 additions and 7 deletions
+6 -2
View File
@@ -21,6 +21,7 @@
// LOVE
#include "common/config.h"
#include "wrap_Font.h"
#include "wrap_Text.h"
// C++
#include <algorithm>
@@ -56,13 +57,16 @@ int w_Font_getWidth(lua_State *L)
int w_Font_getWrap(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
const char *str = luaL_checkstring(L, 2);
std::vector<Font::ColoredString> text;
luax_checkcoloredstring(L, 2, text);
float wrap = (float) luaL_checknumber(L, 3);
int max_width = 0;
std::vector<std::string> lines;
std::vector<int> widths;
luax_catchexcept(L, [&]() { t->getWrap(str, wrap, lines, &widths); });
luax_catchexcept(L, [&]() { t->getWrap(text, wrap, lines, &widths); });
for (int width : widths)
max_width = std::max(max_width, width);