33 lines
830 B
C++
33 lines
830 B
C++
#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
|