1
0
forked from MeloNX/MeloNX

Fix of stretch aspect ratio

This commit is contained in:
Daniil Vinogradov 2025-07-14 23:05:00 +02:00
parent a8994d8b50
commit eb010fa380

View File

@ -17,11 +17,10 @@ struct MetalViewContainer: View {
GeometryReader { geo in GeometryReader { geo in
ZStack { ZStack {
if shouldStretchToFillScreen { if shouldStretchToFillScreen {
stretchedView Color.black
stretchedView(containerSize: geo.size)
} else if oldView { } else if oldView {
Color.black.edgesIgnoringSafeArea(.all) Color.black
oldStyleView(containerSize: geo.size) oldStyleView(containerSize: geo.size)
} else { } else {
modernView(containerSize: geo.size) 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: ryujinx.aspectRatio)
.animation(.easeInOut(duration: 0.3), value: oldView) .animation(.easeInOut(duration: 0.3), value: oldView)
} }
.ignoresSafeArea()
} }
// MARK: - View Components // MARK: - View Components
private var stretchedView: some View { private func stretchedView(containerSize: CGSize) -> some View {
MetalView() let size = targetSize(for: containerSize, ignoreSafeArea: true)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.aspectRatio(contentMode: .fill) return MetalView()
.edgesIgnoringSafeArea(.all) .frame(width: size.width, height: size.height)
} }
private func oldStyleView(containerSize: CGSize) -> some View { private func oldStyleView(containerSize: CGSize) -> some View {
@ -114,7 +114,7 @@ struct MetalViewContainer: View {
return isPortrait ? baseScale : baseScale * 0.92 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 = { let targetAspect: CGFloat = {
switch ryujinx.aspectRatio { switch ryujinx.aspectRatio {
case .fixed4x3: return 4.0 / 3.0 case .fixed4x3: return 4.0 / 3.0
@ -122,20 +122,16 @@ struct MetalViewContainer: View {
case .fixed16x10: return 16.0 / 10.0 case .fixed16x10: return 16.0 / 10.0
case .fixed21x9: return 21.0 / 9.0 case .fixed21x9: return 21.0 / 9.0
case .fixed32x9: return 32.0 / 10.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( let adjustedContainer = CGSize(
width: containerSize.width - safeArea.left - safeArea.right, width: containerSize.width - safeArea.left - safeArea.right,
height: containerSize.height - safeArea.top - safeArea.bottom height: containerSize.height - safeArea.top - safeArea.bottom
) )
if ryujinx.aspectRatio == .stretched {
return adjustedContainer
}
let containerAspect = adjustedContainer.width / adjustedContainer.height let containerAspect = adjustedContainer.width / adjustedContainer.height
if containerAspect > targetAspect { if containerAspect > targetAspect {