From eb010fa3806394d244352d5d7f0cc403b0bbd939 Mon Sep 17 00:00:00 2001 From: Daniil Vinogradov Date: Mon, 14 Jul 2025 23:05:00 +0200 Subject: [PATCH] Fix of stretch aspect ratio --- .../Container/MetalViewContainer.swift | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/MeloNX/MeloNX/App/Views/Main/Emulation/MetalView/Container/MetalViewContainer.swift b/src/MeloNX/MeloNX/App/Views/Main/Emulation/MetalView/Container/MetalViewContainer.swift index 8cba7e6a3..3548885a6 100644 --- a/src/MeloNX/MeloNX/App/Views/Main/Emulation/MetalView/Container/MetalViewContainer.swift +++ b/src/MeloNX/MeloNX/App/Views/Main/Emulation/MetalView/Container/MetalViewContainer.swift @@ -17,11 +17,10 @@ struct MetalViewContainer: View { GeometryReader { geo in ZStack { if shouldStretchToFillScreen { - stretchedView + Color.black + stretchedView(containerSize: geo.size) } else if oldView { - Color.black.edgesIgnoringSafeArea(.all) - - + Color.black oldStyleView(containerSize: geo.size) } else { modernView(containerSize: geo.size) @@ -30,15 +29,16 @@ struct MetalViewContainer: View { .animation(.easeInOut(duration: 0.3), value: ryujinx.aspectRatio) .animation(.easeInOut(duration: 0.3), value: oldView) } + .ignoresSafeArea() } // MARK: - View Components - private var stretchedView: some View { - MetalView() - .frame(maxWidth: .infinity, maxHeight: .infinity) - .aspectRatio(contentMode: .fill) - .edgesIgnoringSafeArea(.all) + private func stretchedView(containerSize: CGSize) -> some View { + let size = targetSize(for: containerSize, ignoreSafeArea: true) + + return MetalView() + .frame(width: size.width, height: size.height) } private func oldStyleView(containerSize: CGSize) -> some View { @@ -114,7 +114,7 @@ struct MetalViewContainer: View { return isPortrait ? baseScale : baseScale * 0.92 } - private func targetSize(for containerSize: CGSize) -> CGSize { + private func targetSize(for containerSize: CGSize, ignoreSafeArea: Bool = false) -> CGSize { let targetAspect: CGFloat = { switch ryujinx.aspectRatio { case .fixed4x3: return 4.0 / 3.0 @@ -122,20 +122,16 @@ struct MetalViewContainer: View { case .fixed16x10: return 16.0 / 10.0 case .fixed21x9: return 21.0 / 9.0 case .fixed32x9: return 32.0 / 10.0 - case .stretched: return containerSize.width / containerSize.height + case .stretched: return 16.0 / 9.0 } }() - let safeArea = UIApplication.shared.windows.first?.safeAreaInsets ?? .zero + let safeArea: UIEdgeInsets = ignoreSafeArea ? .zero : UIApplication.shared.windows.first?.safeAreaInsets ?? .zero let adjustedContainer = CGSize( width: containerSize.width - safeArea.left - safeArea.right, height: containerSize.height - safeArea.top - safeArea.bottom ) - if ryujinx.aspectRatio == .stretched { - return adjustedContainer - } - let containerAspect = adjustedContainer.width / adjustedContainer.height if containerAspect > targetAspect {