refactor: move built-in icon upload into imgui backend
This commit is contained in:
32
editor/src/UI/BuiltInIconLayoutUtils.h
Normal file
32
editor/src/UI/BuiltInIconLayoutUtils.h
Normal 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
|
||||
Reference in New Issue
Block a user