Works a lot better now

This commit is contained in:
PJB3005
2026-03-29 00:19:56 +01:00
parent bb92f955c8
commit b17b5fe405
6 changed files with 252 additions and 34 deletions
+25
View File
@@ -0,0 +1,25 @@
#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};
}