Adding and fixing stuff

- Fix HexChar2Int
- Remove some devisions in tween engine
- Add PathAdd function for x, y seperated instead of fvec2
- Readd text wrapping (rd7-palladium maybe)
This commit is contained in:
2025-12-15 22:16:19 +01:00
parent f19c947fc3
commit 6c38aa6f21
6 changed files with 56 additions and 17 deletions

View File

@@ -281,7 +281,7 @@ PD_LITHIUM_API void DrawList::DrawText(const fvec2 &pos,
PD_LITHIUM_API void DrawList::DrawTextEx(const fvec2 &p,
const std::string &text, u32 color,
LiTextFlags flags, fvec2 box) {
LiTextFlags flags, const fvec2 &box) {
if (!pCurrentFont) {
return;
}

View File

@@ -250,6 +250,10 @@ PD_LITHIUM_API void Font::CmdTextEx(std::vector<Command::Ref> &cmds,
fvec2 td;
fvec2 rpos = pos;
fvec2 rbox = box;
std::string txt = text;
if (flags & LiTextFlags_Wrap) {
txt = pWrapText(txt, scale, box, td);
}
if (flags & (LiTextFlags_AlignMid | LiTextFlags_AlignRight)) {
td = GetTextBounds(text, scale);
}
@@ -261,7 +265,7 @@ PD_LITHIUM_API void Font::CmdTextEx(std::vector<Command::Ref> &cmds,
}
std::vector<std::string> lines;
std::istringstream iss(text);
std::istringstream iss(txt);
std::string tmp;
while (std::getline(iss, tmp)) {
lines.push_back(tmp);
@@ -315,5 +319,30 @@ PD_LITHIUM_API void Font::CmdTextEx(std::vector<Command::Ref> &cmds,
}
}
PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale,
const PD::fvec2 &max,
PD::fvec2 &dim) {
std::string ret;
std::string line;
int lx = 0;
std::stringstream s(txt);
std::string tmp;
// Simply go over every word
while (s >> tmp) {
auto d = GetTextBounds(tmp, scale);
if (lx + d.x <= max.x) {
line += tmp + ' ';
lx += d.x;
} else {
ret += line + '\n';
line = tmp + ' ';
lx = GetTextBounds(line, scale).x;
}
}
ret += line;
dim = GetTextBounds(ret, scale);
return ret;
}
} // namespace Li
} // namespace PD
} // namespace PD