From d718ab2d49b655b20419098722d3b7fee1d36670 Mon Sep 17 00:00:00 2001 From: Dmytro Soldatov Date: Mon, 15 Jan 2024 11:31:59 +0200 Subject: [PATCH] fix: Contain story does not work proper way with more square images #69 (#70) --- src/controllers/SizeController.ts | 17 ++++++++--------- src/stories/fit/Contain.stories.ts | 4 +++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/controllers/SizeController.ts b/src/controllers/SizeController.ts index 6e2c506..7ebb0be 100644 --- a/src/controllers/SizeController.ts +++ b/src/controllers/SizeController.ts @@ -596,19 +596,18 @@ export class SizeController if (minWidth || minHeight) { - let finalMinScaleToFit = finalScaleToFit; - - if (layoutWidth * finalScaleToFit < minWidthVal) + if (minWidth && minHeight) { - finalMinScaleToFit = minFitScaleX; + finalScaleToFit = Math.max(minFitScaleX, minFitScaleY); } - - if (layoutHeight * finalScaleToFit < minHeightVal) + else if (minWidth) { - finalMinScaleToFit = minFitScaleY; + finalScaleToFit = finalScaleX; + } + else if (minHeight) + { + finalScaleToFit = minFitScaleY; } - - finalScaleToFit = Math.max(finalMinScaleToFit, finalMinScaleToFit); } this.layout.container.scale.set(finalScaleToFit); diff --git a/src/stories/fit/Contain.stories.ts b/src/stories/fit/Contain.stories.ts index d82949f..46be355 100644 --- a/src/stories/fit/Contain.stories.ts +++ b/src/stories/fit/Contain.stories.ts @@ -35,7 +35,9 @@ class LayoutStory styles: { position: 'center', maxWidth: '100%', - minHeight: '100%' + maxHeight: '100%', + minHeight: '100%', + minWidth: '100%', } }, styles: {