SPB Git

Repository Public MIT

FeatureRegistry.swift 3.1 KB 103 lines swift

1// ORIX Calc2// File: App/Sources/FeatureRegistry.swift3// Description: Maps each environment to its screen. Feature packages are optional at compile time so that each can be built and tested alone.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI8import ORIXUI9import ORIXExpression10import ORIXFeatureCalculator11#if ORIX_HAS_FINANCIAL12import ORIXFeatureFinancial13#endif14#if ORIX_HAS_CONVERT15import ORIXFeatureConvert16#endif17#if ORIX_HAS_GRAPH18import ORIXFeatureGraph19#endif20#if ORIX_HAS_MATH21import ORIXFeatureMath22#endif23#if ORIX_HAS_STATISTICS24import ORIXFeatureStatistics25#endif26#if ORIX_HAS_WORKSPACE27import ORIXFeatureWorkspace28#endif2930@MainActor31enum FeatureRegistry {32    /// Functions that other environments contribute to the shared expression engine (e.g. normcdf from Statistics).33    static func registerNatives(_ app: AppModel) {34        #if ORIX_HAS_STATISTICS35        app.registerNatives(StatisticsNatives.all)36        #endif37    }3839    /// The real plot renderer that other environments embed (Workspace graph cells, Math plots).40    static var graphPreview: GraphPreviewProvider? {41        #if ORIX_HAS_GRAPH42        GraphPreviewFactory.provider43        #else44        nil45        #endif46    }4748    @ViewBuilder49    static func screen(for mode: CalcMode, calculator: CalculatorModel, options: LaunchOptions) -> some View {50        let section = options.mode == mode ? options.section : nil51        let demo = options.demo52        switch mode {53        case .standard: CalculatorScreen(model: calculator, kind: .standard)54        case .scientific: CalculatorScreen(model: calculator, kind: .scientific)55        case .financial:56            #if ORIX_HAS_FINANCIAL57            FinancialScreen(section: section, demo: demo)58            #else59            UnavailableFeature(mode: mode)60            #endif61        case .graph:62            #if ORIX_HAS_GRAPH63            GraphScreen(section: section, demo: demo)64            #else65            UnavailableFeature(mode: mode)66            #endif67        case .math:68            #if ORIX_HAS_MATH69            MathScreen(section: section, demo: demo)70            #else71            UnavailableFeature(mode: mode)72            #endif73        case .statistics:74            #if ORIX_HAS_STATISTICS75            StatisticsScreen(section: section, demo: demo)76            #else77            UnavailableFeature(mode: mode)78            #endif79        case .convert:80            #if ORIX_HAS_CONVERT81            ConvertScreen(category: section, demo: demo)82            #else83            UnavailableFeature(mode: mode)84            #endif85        case .workspace:86            #if ORIX_HAS_WORKSPACE87            WorkspaceScreen(demo: demo)88            #else89            UnavailableFeature(mode: mode)90            #endif91        }92    }93}9495/// Only reachable in a development build where a feature package was left out of the project.96struct UnavailableFeature: View {97    let mode: CalcMode98    var body: some View {99        ContentUnavailableView("\(mode.title) is not included in this build", systemImage: mode.symbol,100                               description: Text("This environment is disabled in the current build configuration."))101    }102}103
Files main
Menu

Theme