vChewing-macOS/Source/Modules/UIModules/PrefUI/CtlPrefUI.swift

92 lines
2.6 KiB
Swift

// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
// ====================
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
// ... with NTL restriction stating that:
// No trademark license is granted to use the trade names, trademarks, service
// marks, or product names of Contributor, except as required to fulfill notice
// requirements defined in MIT License.
import SSPreferences
import SwiftExtension
import SwiftUI
@available(macOS 10.15, *)
extension PrefUITabs {
var ssPaneIdentifier: SSPreferences.PaneIdentifier { .init(rawValue: rawValue) }
}
@available(macOS 10.15, *)
struct VwrPrefPage: View {
@State var tabType: PrefUITabs
var body: some View {
Group {
switch tabType {
case .tabGeneral: VwrPrefPaneGeneral()
case .tabCandidates: VwrPrefPaneCandidates()
case .tabBehavior: VwrPrefPaneBehavior()
case .tabOutput: VwrPrefPaneOutput()
case .tabDictionary: VwrPrefPaneDictionary()
case .tabPhrases: VwrPrefPanePhrases()
case .tabCassette: VwrPrefPaneCassette()
case .tabKeyboard: VwrPrefPaneKeyboard()
case .tabDevZone, .tabExperience: VwrPrefPaneDevZone()
}
}.fixedSize()
}
}
@available(macOS 10.15, *)
class CtlPrefUI {
var controller = PreferencesWindowController(
panes: {
var result = [PreferencePaneConvertible]()
PrefUITabs.allCases.forEach { neta in
if [.tabExperience].contains(neta) { return }
let item: PreferencePaneConvertible = SSPreferences.Pane(
identifier: SSPreferences.PaneIdentifier(rawValue: neta.rawValue),
title: neta.i18nTitle, toolbarIcon: neta.icon,
contentView: { VwrPrefPage(tabType: neta) }
)
result.append(item)
}
return result
}(),
style: .toolbarItems
)
static let shared = CtlPrefUI()
static let sentenceSeparator: String = {
switch PrefMgr.shared.appleLanguages[0] {
case "ja":
return ""
default:
if PrefMgr.shared.appleLanguages[0].contains("zh-Han") {
return ""
} else {
return " "
}
}
}()
static let contentMaxHeight: Double = 490
static let contentWidth: Double = {
switch PrefMgr.shared.appleLanguages[0] {
case "ja":
return 520
default:
if PrefMgr.shared.appleLanguages[0].contains("zh-Han") {
return 500
} else {
return 580
}
}
}()
}
@available(macOS 10.15, *)
public extension View {
func prefDescriptionWidthLimited() -> some View {
frame(maxWidth: CtlPrefUI.contentWidth * 0.8, alignment: .leading)
}
}