Git Product home page Git Product logo

settingskit-macos's Introduction

SettingsKit Icon

SettingsKit

GitHub · Contributor Docs

SettingsKit makes it easier to add a settings window to a SwiftUI app for macOS.

GitHub Banner

Table of Contents

Elements

Name Description
Settings A scene modifier for adding a settings window.
Settings Image Button Style The button style of an image picker in the settings.
Settings Action Contains a function for showing the settings window manually and another function for getting the active settings tab and subtabs selection.

Installation

Swift Package

  1. Open your Swift package in Xcode.
  2. Navigate to File > Add Packages.
  3. Paste this URL into the search field: https://github.com/david-swift/SettingsKit-macOS
  4. Click on Copy Dependency.
  5. Navigate to the Package.swift file.
  6. In the Package initializer, under dependencies, paste the dependency into the array.

 Xcode Project

  1. Open your Xcode project in Xcode.
  2. Navigate to File > Add Packages.
  3. Paste this URL into the search field: https://github.com/david-swift/SettingsKit-macOS
  4. Click on Add Package.

Usage

You can add settings to any SwiftUI scene, for example to a Window or WindowGroup in a standard SwiftUI app.

The following example creates a simple settings window:

@main
struct SuperCoolApp: App {

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .settings {
            // 1.1 - The "General" settings tab.
            SettingsTab(.init("General", systemSymbol: .gearshape), id: "general-tab") {
                // 1.2 - The "General" > "Appearance" settings subtab.
                SettingsSubtab(.init("Appearance", systemSymbol: .circleLefthalfFilled), id: "appearance") {
                    AppearanceSettings()
                }
                // 1.2 - The "General" > "Composer" settings subtab.
                SettingsSubtab(.init("Composer", systemSymbol: .person), id: "composer") {
                    ComposerSettings()
                }
            }

            // 1.3 - An extension for the "General" settings tab.
            SettingsTab(.extend(id: "general-tab"), id: "general-tab-extension") {
                // 1.4 - The "General" settings subtab for no selection.
                SettingsSubtab(.noSelection, id: "no-selection") {
                    NoSelectionInformation()
                }
            }

            // 1.1 - The "Themes" settings tab.
            SettingsTab(.init("Themes", systemSymbol: .paintbrush)) {
                for theme in themes {
                    // 1.2 - A "Themes" > "THEME_NAME" settings subtab for each theme.
                    SettingsSubtab(.init(theme.title, systemSymbol: .paintbrush), id: theme.id) {

                    }
                }
            }
            // 2.1 - The "+" and "-" buttons in the sidebar's toolbar.
            .standardActions {
                themes.append(.init())
            } remove: { index in
                if let index {
                    themes.remove(at: index)
                }
            }

        }
    }

}
  • 1.1 - Create a new settings tab with the initializer for SettingsTab inside the settings(_:) modifier on a scene.
  • 1.2 - Create a new settings subtab with the initializer for SettingsSubtab inside a SettingsTab initializer.
  • 1.3 - Extend an existing tab by using .extend(id:) and providing the ID of the settings tab to extend.
  • 1.4 - Create a new settings subtab by using .noSelection that is displayed if there is not a selected subtab.
  • 2.1 - Use the .standardActions(add:remove:options:) modifier on a settings tab for adding a „+“, „-„ and optionally „⋯“ toolbar button to the sidebar. You can also add a custom toolbar with .actions(content:).

Thanks

Dependencies

Other Thanks

settingskit-macos's People

Contributors

david-swift avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.