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
+4 -4
View File
@@ -901,13 +901,13 @@ void Font::getWrap(const ColoredCodepoints &codepoints, float wraplimit, std::ve
}
}
void Font::getWrap(const std::string &text, float wraplimit, std::vector<std::string> &lines, std::vector<int> *linewidths)
void Font::getWrap(const std::vector<ColoredString> &text, float wraplimit, std::vector<std::string> &lines, std::vector<int> *linewidths)
{
ColoredCodepoints codepoints;
getCodepointsFromString(text, codepoints.cps);
ColoredCodepoints cps;
getCodepointsFromString(text, cps);
std::vector<ColoredCodepoints> codepointlines;
getWrap(codepoints, wraplimit, codepointlines, linewidths);
getWrap(cps, wraplimit, codepointlines, linewidths);
std::string line;
+1 -1
View File
@@ -160,7 +160,7 @@ public:
* @param max_width Optional output of the maximum width
* Returns a vector with the lines.
**/
void getWrap(const std::string &text, float wraplimit, std::vector<std::string> &lines, std::vector<int> *line_widths = nullptr);
void getWrap(const std::vector<ColoredString> &text, float wraplimit, std::vector<std::string> &lines, std::vector<int> *line_widths = nullptr);
void getWrap(const ColoredCodepoints &codepoints, float wraplimit, std::vector<ColoredCodepoints> &lines, std::vector<int> *line_widths = nullptr);
/**
+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);