feat: update editor ui framework and assets

This commit is contained in:
2026-03-28 15:07:19 +08:00
parent 4a12e26860
commit 4717b595c4
45 changed files with 2434 additions and 461 deletions

View File

@@ -13,16 +13,18 @@ namespace UI {
class ImGuiSession {
public:
void Initialize(const std::string& projectPath) {
void Initialize(const std::string& projectPath, float mainDpiScale = 1.0f) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.ConfigDpiScaleFonts = true;
io.ConfigDpiScaleViewports = true;
ConfigureIniFile(projectPath, io);
ConfigureStyle(ImGui::GetStyle(), mainDpiScale);
ConfigureFonts(io);
ApplyBaseTheme(ImGui::GetStyle());
}
void Shutdown() {
@@ -47,6 +49,10 @@ public:
}
private:
static constexpr float kUiFontSize = 18.0f;
static constexpr const char* kPrimaryUiFontPath = "C:/Windows/Fonts/segoeui.ttf";
static constexpr const char* kChineseFallbackFontPath = "C:/Windows/Fonts/msyh.ttc";
void ConfigureIniFile(const std::string& projectPath, ImGuiIO& io) {
const std::filesystem::path configDir = std::filesystem::path(projectPath) / ".xceditor";
std::error_code ec;
@@ -56,17 +62,54 @@ private:
io.IniFilename = m_iniPath.c_str();
}
void ConfigureStyle(ImGuiStyle& style, float mainDpiScale) const {
ApplyBaseTheme(style);
const float dpiScale = mainDpiScale < 1.0f ? 1.0f : (mainDpiScale > 4.0f ? 4.0f : mainDpiScale);
style.ScaleAllSizes(dpiScale);
style.FontScaleDpi = dpiScale;
}
void ConfigureFonts(ImGuiIO& io) const {
if (ImFont* uiFont = io.Fonts->AddFontFromFileTTF("C:/Windows/Fonts/msyh.ttc", 15.0f)) {
io.FontDefault = uiFont;
ImFontAtlas* atlas = io.Fonts;
atlas->Clear();
ImFontConfig baseConfig;
baseConfig.OversampleH = 2;
baseConfig.OversampleV = 1;
baseConfig.PixelSnapH = true;
ImFont* uiFont = atlas->AddFontFromFileTTF(
kPrimaryUiFontPath,
kUiFontSize,
&baseConfig,
atlas->GetGlyphRangesDefault());
if (uiFont) {
ImFontConfig mergeConfig = baseConfig;
mergeConfig.MergeMode = true;
mergeConfig.PixelSnapH = true;
atlas->AddFontFromFileTTF(
kChineseFallbackFontPath,
kUiFontSize,
&mergeConfig,
atlas->GetGlyphRangesChineseSimplifiedCommon());
} else {
io.FontDefault = io.Fonts->AddFontDefault();
uiFont = atlas->AddFontFromFileTTF(
kChineseFallbackFontPath,
kUiFontSize,
&baseConfig,
atlas->GetGlyphRangesChineseSimplifiedCommon());
}
unsigned char* pixels = nullptr;
int width = 0;
int height = 0;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
if (!uiFont) {
ImFontConfig fallbackConfig = baseConfig;
fallbackConfig.SizePixels = kUiFontSize;
uiFont = atlas->AddFontDefault(&fallbackConfig);
}
io.FontDefault = uiFont;
atlas->Build();
}
std::string m_iniPath;