Decompile fn_16977 (UIWindow::FitDisplayText)

Batch #18472 by eAthena: 0 byte-identical, 1 confirmed by peer review.

- fn_16977 UIWindow::FitDisplayText: logic confirmed by peer review

Peer-reviewed-by: ragnarok-clanker, kyoshi, cremane
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
This commit is contained in:
ragnarok-clanker 2026-11-12 17:07:00 +00:00
commit 38b4389d0c

View file

@ -1453,36 +1453,23 @@ std::string UIWindow::FitDisplayText(int width, const char* text, int family, in
display = std::move(navigation);
display = DisplayQuestTextTag(display);
const auto textWidth = [this, family, height, bold](const char* value) {
if (!value) {
return 0;
}
const int textWidth = this->TextWidth(display.c_str(), 0, family, height, bold, 0);
const int ellipsisWidth = this->TextWidth("...", 3, family, height, bold, 0);
const unsigned bytes = static_cast<unsigned>(std::strlen(value));
if (!bytes) {
return 0;
}
TextContext context(*this->geometry.surface);
context.SetFont(family, height, bold, 0);
return static_cast<int>(context.Measure(value, bytes).cx);
};
const int extent = textWidth(display.c_str());
{
TextContext context(*this->geometry.surface);
context.SetFont(family, height, bold, 0);
context.Measure("...", 3);
}
if (extent <= width) {
if (textWidth <= width) {
return display;
}
std::string fitted(display);
std::wstring remaining(ATL::CA2WEX<128>(display.c_str(), CP_THREAD_ACP));
while (remaining.size() > 1) {
int extent;
do {
if (remaining.size() <= 1) {
fitted = std::string(ATL::CW2AEX<128>(remaining.c_str(), CP_THREAD_ACP)) + "...";
break;
}
if (remaining.size() >= 2) {
std::size_t length = remaining.size() - 1;
@ -1493,16 +1480,10 @@ std::string UIWindow::FitDisplayText(int width, const char* text, int family, in
remaining.resize(length);
}
ATL::CW2AEX<128> converted(remaining.c_str(), CP_THREAD_ACP);
fitted = std::string(converted) + "...";
fitted = std::string(ATL::CW2AEX<128>(remaining.c_str(), CP_THREAD_ACP)) + "...";
extent = this->TextWidth(fitted.c_str(), 0, family, height, bold, 0);
} while (width < extent);
if (textWidth(fitted.c_str()) <= width) {
return fitted;
}
}
ATL::CW2AEX<128> converted(remaining.c_str(), CP_THREAD_ACP);
fitted = std::string(converted) + "...";
return fitted;
}