new_editor: isolate project panel state and harden runtime reset

This commit is contained in:
2026-04-22 00:19:35 +08:00
parent fff33185b9
commit 8bfca5e8f2
11 changed files with 144 additions and 61 deletions

View File

@@ -1,6 +1,8 @@
#include <XCEditor/Collections/UIEditorTabStrip.h>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cmath>
#include <string>
#include <utility>
@@ -65,7 +67,55 @@ float ResolveEstimatedLabelWidth(
return item.desiredHeaderLabelWidth;
}
return static_cast<float>(item.title.size()) * ClampNonNegative(metrics.estimatedGlyphWidth);
const float baseGlyphWidth = ClampNonNegative(metrics.estimatedGlyphWidth);
if (item.title.empty() || baseGlyphWidth <= 0.0f) {
return 0.0f;
}
const auto estimateAsciiAdvance = [baseGlyphWidth](unsigned char ch) {
if (ch == ' ') {
return baseGlyphWidth * 0.55f;
}
if (std::isdigit(ch) != 0) {
return baseGlyphWidth * 1.08f;
}
if (std::strchr(".,:;!|'`ijlft()[]{}", static_cast<int>(ch)) != nullptr) {
return baseGlyphWidth * 0.58f;
}
if (std::strchr("mwMW@#%&QG", static_cast<int>(ch)) != nullptr) {
return baseGlyphWidth * 1.45f;
}
if (std::isupper(ch) != 0) {
return baseGlyphWidth * 1.18f;
}
if (std::strchr("_-+=/\\\\<>*", static_cast<int>(ch)) != nullptr) {
return baseGlyphWidth * 0.88f;
}
return baseGlyphWidth;
};
float width = 0.0f;
for (std::size_t index = 0; index < item.title.size();) {
const unsigned char ch = static_cast<unsigned char>(item.title[index]);
if (ch < 0x80u) {
width += estimateAsciiAdvance(ch);
++index;
continue;
}
width += baseGlyphWidth * 1.95f;
if ((ch & 0xE0u) == 0xC0u) {
index += 2u;
} else if ((ch & 0xF0u) == 0xE0u) {
index += 3u;
} else if ((ch & 0xF8u) == 0xF0u) {
index += 4u;
} else {
++index;
}
}
return width;
}
float ResolveTabTextTop(