refactor: move built-in icon upload into imgui backend

This commit is contained in:
2026-04-01 20:03:44 +08:00
parent bc6e20de48
commit 6cd4cd9be9
5 changed files with 385 additions and 273 deletions

View File

@@ -0,0 +1,32 @@
#pragma once
#include <imgui.h>
#include <algorithm>
namespace XCEngine {
namespace Editor {
namespace UI {
inline ImVec2 ComputeFittedIconSize(
int textureWidth,
int textureHeight,
const ImVec2& min,
const ImVec2& max) {
const float availableWidth = max.x - min.x;
const float availableHeight = max.y - min.y;
if (availableWidth <= 0.0f || availableHeight <= 0.0f || textureWidth <= 0 || textureHeight <= 0) {
return ImVec2(0.0f, 0.0f);
}
const float scale = (std::min)(
availableWidth / static_cast<float>(textureWidth),
availableHeight / static_cast<float>(textureHeight));
return ImVec2(
static_cast<float>(textureWidth) * scale,
static_cast<float>(textureHeight) * scale);
}
} // namespace UI
} // namespace Editor
} // namespace XCEngine