mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +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:
@@ -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;
|
ColoredCodepoints cps;
|
||||||
getCodepointsFromString(text, codepoints.cps);
|
getCodepointsFromString(text, cps);
|
||||||
|
|
||||||
std::vector<ColoredCodepoints> codepointlines;
|
std::vector<ColoredCodepoints> codepointlines;
|
||||||
getWrap(codepoints, wraplimit, codepointlines, linewidths);
|
getWrap(cps, wraplimit, codepointlines, linewidths);
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ public:
|
|||||||
* @param max_width Optional output of the maximum width
|
* @param max_width Optional output of the maximum width
|
||||||
* Returns a vector with the lines.
|
* 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);
|
void getWrap(const ColoredCodepoints &codepoints, float wraplimit, std::vector<ColoredCodepoints> &lines, std::vector<int> *line_widths = nullptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
// LOVE
|
// LOVE
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
#include "wrap_Font.h"
|
#include "wrap_Font.h"
|
||||||
|
#include "wrap_Text.h"
|
||||||
|
|
||||||
// C++
|
// C++
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -56,13 +57,16 @@ int w_Font_getWidth(lua_State *L)
|
|||||||
int w_Font_getWrap(lua_State *L)
|
int w_Font_getWrap(lua_State *L)
|
||||||
{
|
{
|
||||||
Font *t = luax_checkfont(L, 1);
|
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);
|
float wrap = (float) luaL_checknumber(L, 3);
|
||||||
int max_width = 0;
|
int max_width = 0;
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
std::vector<int> widths;
|
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)
|
for (int width : widths)
|
||||||
max_width = std::max(max_width, width);
|
max_width = std::max(max_width, width);
|
||||||
|
|||||||
Reference in New Issue
Block a user