ReAdd text shorting
This commit is contained in:
@@ -103,6 +103,8 @@ class PD_LITHIUM_API Font {
|
|||||||
PD::Li::Texture::Ref tex);
|
PD::Li::Texture::Ref tex);
|
||||||
std::string pWrapText(const std::string& txt, float scale,
|
std::string pWrapText(const std::string& txt, float scale,
|
||||||
const PD::fvec2& max, PD::fvec2& dim);
|
const PD::fvec2& max, PD::fvec2& dim);
|
||||||
|
std::string pShortText(const std::string& txt, float scale,
|
||||||
|
const PD::fvec2& max, PD::fvec2& dim);
|
||||||
|
|
||||||
/** Data Section */
|
/** Data Section */
|
||||||
int PixelHeight;
|
int PixelHeight;
|
||||||
|
|||||||
@@ -272,10 +272,10 @@ PD_LITHIUM_API void Font::CmdTextEx(std::vector<Command::Ref> &cmds,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto &it : lines) {
|
for (auto &it : lines) {
|
||||||
/*if (flags & LITextFlags_Short) {
|
if (flags & LiTextFlags_Short) {
|
||||||
fvec2 tmp_dim;
|
fvec2 tmp_dim;
|
||||||
it = ShortText(it, box.x() - pos.x(), tmp_dim);
|
it = pShortText(it, scale, box - pos, tmp_dim);
|
||||||
}*/
|
}
|
||||||
auto wline = Strings::MakeWstring(it);
|
auto wline = Strings::MakeWstring(it);
|
||||||
auto cmd = Command::New();
|
auto cmd = Command::New();
|
||||||
auto Tex = GetCodepoint(wline[0]).Tex;
|
auto Tex = GetCodepoint(wline[0]).Tex;
|
||||||
@@ -344,5 +344,37 @@ PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PD_LITHIUM_API std::string Font::pShortText(const std::string &txt, float scale,
|
||||||
|
const PD::fvec2 &max,
|
||||||
|
PD::fvec2 &dim) {
|
||||||
|
auto test = GetTextBounds(txt, scale);
|
||||||
|
if (test.x < max.x) {
|
||||||
|
return txt;
|
||||||
|
}
|
||||||
|
std::string ext;
|
||||||
|
std::string ph = "(...)"; // placeholder
|
||||||
|
std::string tmp = txt;
|
||||||
|
std::string ret;
|
||||||
|
auto maxlen = max.x;
|
||||||
|
size_t ext_ = tmp.find_last_of('.');
|
||||||
|
if (ext_ != tmp.npos) {
|
||||||
|
ext = tmp.substr(ext_);
|
||||||
|
tmp = tmp.substr(0, ext_);
|
||||||
|
}
|
||||||
|
maxlen -= GetTextBounds(ext, scale).x;
|
||||||
|
maxlen -= GetTextBounds(ph, scale).x;
|
||||||
|
|
||||||
|
for (auto &it : tmp) {
|
||||||
|
if (GetTextBounds(ret, scale).x > maxlen) {
|
||||||
|
ret += ph;
|
||||||
|
ret += ext;
|
||||||
|
dim = GetTextBounds(ret, scale);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
ret += it;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Li
|
} // namespace Li
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
Reference in New Issue
Block a user