Files
dusklight/src/dusk/layout.cpp
T
2026-03-29 00:19:56 +01:00

26 lines
678 B
C++

#include "dusk/layout.hpp"
using namespace dusk;
LayoutRect LayoutRect::FitRectInRect(
const f32 widthOuter,
const f32 heightOuter,
const f32 widthInner,
const f32 heightInner) {
// Try as if constrained vertically first.
auto width = widthInner * (heightOuter / heightInner);
auto height = heightOuter;
if (width > widthOuter) {
// Otherwise, constrained horizontally.
width = widthOuter;
height = heightOuter * (widthOuter / widthInner);
}
// Center it
const auto posX = (widthOuter - width) / 2;
const auto posY = (heightOuter - height) / 2;
return {posX, posY, posX + width, posY + height};
}