Skip to content

Commit

Permalink
Update TestApp to build with SettingsKit 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Sep 21, 2023
1 parent 0a6d4d8 commit 3b47c57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
9 changes: 6 additions & 3 deletions Tests/TestApp/TestApp/TestAppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ struct TestAppApp: App {

/// The app model for testing the ``SettingsKit``.
@StateObject private var appModel = TestAppModel.shared
/// Whether the sidebar design should be used for the settings window.
@AppStorage("sidebar-design")
var sidebarDesign = false

/// The main view of the test app.
var body: some Scene {
Window("Window", id: "Window") {
ContentView()
}
.settings {
.settings(design: sidebarDesign ? .sidebar : .default) {
for settingsTab in appModel.allSettings {
settingsTab
}
SettingsTab(.new(label: .init("Test", systemSymbol: .arrowLeftCircle)), id: "test") {
SettingsTab(.new(title: "Test", icon: .arrowLeftCircle), id: "test") {
SettingsSubtab(.noSelection, id: "subtab") {
let width = 500.0
let height = 100.0
Text("Hello!")
Toggle("Sidebar Design", isOn: $sidebarDesign)
.frame(width: width, height: height)
}
}
Expand Down
24 changes: 12 additions & 12 deletions Tests/TestApp/TestApp/ViewModel/TestAppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class TestAppModel: ObservableObject {
/// All the settings: the "Settings" tab + the ``settings``.
@ArrayBuilder<SettingsTab> var allSettings: [SettingsTab] {
SettingsTab(
.init(
.init("Settings", comment: "TestAppModel (Name of the settings for testing purposes)"),
systemSymbol: .gearshape
.new(
title: "Settings",
icon: .gearshape
),
id: "settings-tab"
) {
Expand Down Expand Up @@ -56,9 +56,9 @@ class TestAppModel: ObservableObject {
/// The subtabs in the "Setttings" tab that represent the other tabs.
@ArrayBuilder<SettingsSubtab> private var tabsGeneralSubtabs: [SettingsSubtab] {
for settingsTab in settings {
if case let .new(label: label) = settingsTab.type {
SettingsSubtab(label, id: settingsTab.id) {
label
if case let .new(title: title, icon: icon) = settingsTab.type {
SettingsSubtab(.new(title: title, icon: icon), id: settingsTab.id) {
Label(title, systemSymbol: icon)
}
}
}
Expand All @@ -78,26 +78,26 @@ class TestAppModel: ObservableObject {

/// Generates a new settings tab.
var newTab: SettingsTab {
.init(randomLabel, id: UUID().uuidString) {
.init(.new(title: randomLabel.0, icon: randomLabel.1), id: UUID().uuidString) {
SettingsSubtab(.noSelection, id: "no-selection-subtab") {
randomLabel
Label(randomLabel.0, systemSymbol: randomLabel.1)
}
}
}

/// Generates a new settings tab.
var colorTab: SettingsTab {
.init(randomLabel, id: UUID().uuidString) {
.init(.new(title: randomLabel.0, icon: randomLabel.1), id: UUID().uuidString) {
SettingsSubtab(.noSelection, id: "no-selection-subtab") {
Color.accentColor
}
}
}

/// Generates a random label.
private var randomLabel: Label<Text, Image> {
private var randomLabel: (String, SFSymbol) {
var dot = false
return .init(
return (
randomSymbol.rawValue.compactMap { char -> String? in
if char == "." {
dot = true
Expand All @@ -107,7 +107,7 @@ class TestAppModel: ObservableObject {
return nil
}
.joined(),
systemSymbol: randomSymbol
randomSymbol
)
}

Expand Down

0 comments on commit 3b47c57

Please sign in to comment.