mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user