mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-05-23 22:45:05 -04:00
26 lines
678 B
C++
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};
|
|
}
|