mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-07-30 15:43:19 -04:00
Works a lot better now
This commit is contained in:
@@ -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};
|
||||
}
|
||||
Reference in New Issue
Block a user