Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
Launcher: one size for the hero's Play and Build game buttons
v0lumehicc0a85a983fe
diff --git a/frontend/Sources/NSPortBuilder/LauncherStyles.swift b/frontend/Sources/NSPortBuilder/LauncherStyles.swiftindex dd456606..8d5e2870 100644--- a/frontend/Sources/NSPortBuilder/LauncherStyles.swift+++ b/frontend/Sources/NSPortBuilder/LauncherStyles.swift@@ -138,6 +138,35 @@ struct LauncherSwitchStyle: ToggleStyle {}}+/// The cream button of the library's hero (Play, Build game, Open on a device). It has one size in every state and language, so+/// the button does not change size when a game goes from not built to built. A long label shrinks, then ends in an ellipsis.+enum LauncherHeroAction {+ static let width: CGFloat = 200+ static let height: CGFloat = 54+ static let horizontalPadding: CGFloat = 24+ static let iconSlot: CGFloat = 28+ static let iconSpacing: CGFloat = 8+ static let labelWidth = width - 2 * horizontalPadding - iconSlot - iconSpacing+ static let minimumScale: CGFloat = 0.7+}++struct LauncherHeroActionLabel: View {+ let title: String+ let symbol: String++ var body: some View {+ HStack(spacing: LauncherHeroAction.iconSpacing) {+ Image(systemName: symbol).frame(width: LauncherHeroAction.iconSlot)+ Text(title).lineLimit(1).minimumScaleFactor(LauncherHeroAction.minimumScale)+ }+ .font(.manrope(18, .bold))+ .foregroundStyle(.black)+ .padding(.horizontal, LauncherHeroAction.horizontalPadding)+ .frame(width: LauncherHeroAction.width, height: LauncherHeroAction.height)+ .background(LauncherPalette.cream, in: Capsule())+ }+}+/// The width of a launch option's control (choices, list, slider with its value), so the controls of a card line up/// in one column whatever their labels.enum LaunchControl {diff --git a/frontend/Sources/NSPortBuilder/LauncherView.swift b/frontend/Sources/NSPortBuilder/LauncherView.swiftindex 8eebd9a0..570ba275 100644--- a/frontend/Sources/NSPortBuilder/LauncherView.swift+++ b/frontend/Sources/NSPortBuilder/LauncherView.swift@@ -432,14 +432,11 @@ struct ContentView: View {.tracking(-1.6).lineLimit(2).shadow(color: .black.opacity(0.25), radius: 12)HStack(spacing: 18) {Button { primaryAction(game) } label: {- Label(game.primary == .play ? m.t("library.play")+ LauncherHeroActionLabel(+ title: game.primary == .play ? m.t("library.play"): (game.primary == .openOnDevice ? String(format: m.t("dev.open"), m.deviceName(game.installedDevice)): m.t("library.newBuild")),- systemImage: game.primary == .play ? "play.fill" : (game.primary == .openOnDevice ? "iphone" : "hammer.fill"))- .font(.manrope(18, .bold))- .foregroundStyle(.black).padding(.horizontal, 30).padding(.vertical, 14)- .frame(minWidth: 164)- .background(LauncherPalette.cream, in: Capsule())+ symbol: game.primary == .play ? "play.fill" : (game.primary == .openOnDevice ? "iphone" : "hammer.fill"))}.buttonStyle(.plain).disabled(launching || (m.running && !game.isReady)).keyboardShortcut(.return, modifiers: [])diff --git a/frontend/Tests/NSPortBuilderTests/LauncherHeroActionTests.swift b/frontend/Tests/NSPortBuilderTests/LauncherHeroActionTests.swiftnew file mode 100644index 00000000..65dfde77--- /dev/null+++ b/frontend/Tests/NSPortBuilderTests/LauncherHeroActionTests.swift@@ -0,0 +1,46 @@+import CoreText+import SwiftUI+import XCTest+@testable import NSPortBuilder++/// The hero's cream button has one size (LauncherHeroAction) whatever the game's state and the language.+final class LauncherHeroActionTests: XCTestCase {+ private let languages: [Lang] = [.zh, .en, .sv, .de]++ private func width(_ text: String) throws -> CGFloat {+ let font = try XCTUnwrap(Typography.manropeFont(size: 18, weight: .bold))+ let line = CTLineCreateWithAttributedString(NSAttributedString(string: text, attributes: [.font: font]))+ return CTLineGetTypographicBounds(line, nil, nil, nil)+ }++ func testPlayAndBuildFitOnOneLineInEveryLanguage() throws {+ for key in ["library.play", "library.newBuild"] {+ for lang in languages {+ let text = L10n.string(key, lang)+ XCTAssertLessThanOrEqual(try width(text), LauncherHeroAction.labelWidth, "\(lang) \(key): \(text)")+ }+ }+ }++ func testOpenOnDeviceFitsAfterShrinkingForADeviceName() throws {+ for lang in languages {+ let text = String(format: L10n.string("dev.open", lang), "iPhone")+ XCTAssertLessThanOrEqual(try width(text) * LauncherHeroAction.minimumScale, LauncherHeroAction.labelWidth, "\(lang): \(text)")+ }+ }++ @MainActor func testEveryStateHasTheSameSize() throws {+ let states: [(String, String)] = [("play.fill", "library.play"), ("hammer.fill", "library.newBuild"), ("iphone", "dev.open")]+ for lang in languages {+ var sizes = Set<String>()+ for (symbol, key) in states {+ let title = String(format: L10n.string(key, lang), "iPhone 17 Pro Max of a very long name")+ let size = NSHostingView(rootView: LauncherHeroActionLabel(title: title, symbol: symbol)).fittingSize+ XCTAssertEqual(size.width, LauncherHeroAction.width, "\(lang) \(key)")+ XCTAssertEqual(size.height, LauncherHeroAction.height, "\(lang) \(key)")+ sizes.insert("\(size.width)x\(size.height)")+ }+ XCTAssertEqual(sizes.count, 1, "\(lang): \(sizes)")+ }+ }+}