Compare commits
	
		
			5 Commits
		
	
	
		
			4814c6e7c2
			...
			main
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| acc2245865 | |||
| 7c3ba17a36 | |||
| 17020fcab4 | |||
| 5901b5f4c9 | |||
| d41f72280a | 
@@ -17,15 +17,29 @@ let package = Package(
 | 
			
		||||
            name: "PMCalc",
 | 
			
		||||
            dependencies: [
 | 
			
		||||
                .product(name: "Adwaita", package: "adwaita-swift"),
 | 
			
		||||
                .product(name: "Localized", package: "localized")
 | 
			
		||||
                .product(name: "Localized", package: "localized"),
 | 
			
		||||
                "CMath"
 | 
			
		||||
            ],
 | 
			
		||||
            path: "Sources",
 | 
			
		||||
            path: "Sources/PMCalc",
 | 
			
		||||
            resources: [
 | 
			
		||||
                .process("Localized.yml")
 | 
			
		||||
            ],
 | 
			
		||||
            cSettings: [
 | 
			
		||||
                .headerSearchPath("Sources/CMath/include")
 | 
			
		||||
            ],
 | 
			
		||||
            linkerSettings: [
 | 
			
		||||
                .unsafeFlags([
 | 
			
		||||
                    "-L./Sources/CMath/lib/"
 | 
			
		||||
                ])
 | 
			
		||||
            ],
 | 
			
		||||
            plugins: [
 | 
			
		||||
                .plugin(name: "GenerateLocalized", package: "localized")
 | 
			
		||||
            ]
 | 
			
		||||
        ),
 | 
			
		||||
        .systemLibrary(
 | 
			
		||||
            name: "CMath",
 | 
			
		||||
            path: "Sources/CMath",
 | 
			
		||||
            providers: []
 | 
			
		||||
        )
 | 
			
		||||
    ],
 | 
			
		||||
    swiftLanguageModes: [.v5]
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										61
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								README.md
									
									
									
									
									
								
							@@ -1,62 +1,7 @@
 | 
			
		||||
<p align="center">
 | 
			
		||||
  <img width="256" alt="Adwaita Template Icon" src="data/icons/io.github.AparokshaUI.AdwaitaTemplate.svg">
 | 
			
		||||
  <h1 align="center">Adwaita Template</h1>
 | 
			
		||||
  <h1 align="center">Bachelorproef | Fase 4</h1>
 | 
			
		||||
</p>
 | 
			
		||||
 | 
			
		||||
_Adwaita Template_ is a template application for the [Adwaita for Swift package](https://adwaita-swift.aparoksha.dev/documentation/adwaita/).
 | 
			
		||||
Deze repository bevat PMCalc, een simpele calculator-app, geschreven met [Adwaita for Swift](https://adwaita-swift.aparoksha.dev/documentation/adwaita/) en CMath.
 | 
			
		||||
 | 
			
		||||
## Table of Contents
 | 
			
		||||
 | 
			
		||||
- [Installation](#Installation)
 | 
			
		||||
- [Usage](#Usage)
 | 
			
		||||
- [Thanks](#Thanks)
 | 
			
		||||
 | 
			
		||||
## Installation
 | 
			
		||||
 | 
			
		||||
Install the [GNOME Builder](https://flathub.org/apps/org.gnome.Builder) IDE.
 | 
			
		||||
 | 
			
		||||
For designing an app icon, [App Icon Preview](https://flathub.org/apps/org.gnome.design.AppIconPreview) and [Inkscape](https://flathub.org/apps/org.inkscape.Inkscape) are recommended.
 | 
			
		||||
 | 
			
		||||
> [!NOTE]
 | 
			
		||||
> You do not have to install any dependencies of Adwaita for Swift, including Swift, on your system.
 | 
			
		||||
> The Adwaita template runs in a [Flatpak](https://flatpak.org/).
 | 
			
		||||
> The GNOME Builder will automatically download dependencies from [Flathub](https://flathub.org).
 | 
			
		||||
> You can also use [Visual Studio Code](https://code.visualstudio.com/) with a Docker [dev container](https://code.visualstudio.com/docs/devcontainers/containers) hosting the Swift toolchain and Adwaita libraries.
 | 
			
		||||
 | 
			
		||||
## Usage
 | 
			
		||||
 | 
			
		||||
1. Open this project in the GNOME Builder. It will start downloading the dependencies.
 | 
			
		||||
    - GNOME Builder will start downloading dependencies when opened.
 | 
			
		||||
    - For Visual Studio Code, enable the [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers), the [Swift extension](https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang) and the [CodeLLDB extension](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) and reopen the project window with the dev container. It may take a couple minutes to build.
 | 
			
		||||
2. Build and run the application.
 | 
			
		||||
    - For GNOME Builder, use the "run" icon in the toolbar.
 | 
			
		||||
    - For Visual Studio Code, select the "run and debug" tab in the leftmost sidebar, and then tap the run icon next to "Debug AdwaitaTemplate".
 | 
			
		||||
3. Change the app's name and other information about the application in the following files (and file names):
 | 
			
		||||
    - `README.md`
 | 
			
		||||
    - `Package.swift`
 | 
			
		||||
    - `io.github.AparokshaUI.AdwaitaTemplate.json`
 | 
			
		||||
    - `Sources/AdwaitaTemplate.swift`
 | 
			
		||||
    - `data/io.github.AparokshaUI.AdwaitaTemplate.metainfo.xml`
 | 
			
		||||
    - `data/io.github.AparokshaUI.AdwaitaTemplate.desktop`
 | 
			
		||||
    - `data/icons/io.github.AparokshaUI.AdwaitaTemplate.Source.svg`
 | 
			
		||||
    - `data/icons/io.github.AparokshaUI.AdwaitaTemplate.svg`
 | 
			
		||||
    - `data/icons/io.github.AparokshaUI.AdwaitaTemplate-symbolic.svg`
 | 
			
		||||
4. Edit the code. Help is available [here](https://adwaita-swift.aparoksha.dev/), ask questions in the [forums](https://forums.aparoksha.dev/).
 | 
			
		||||
5. You can edit the app's icons using the previously installed tools according to [this](https://blogs.gnome.org/tbernard/2019/12/30/designing-an-icon-for-your-app/) tutorial.
 | 
			
		||||
6. In GNOME Builder, click on the dropdown next to the hammer and then on `Export`. Wait until the file manager appears, open the `.flatpak` file and install the app on your device!
 | 
			
		||||
7. If you want to publish your app, replace `debug` in the following build commands by `release`:
 | 
			
		||||
```
 | 
			
		||||
"swift build -c debug --static-swift-stdlib",
 | 
			
		||||
"install -Dm755 .build/debug/AdwaitaTemplate /app/bin/AdwaitaTemplate",
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Flatpak SPM Generator
 | 
			
		||||
 | 
			
		||||
If you want to e.g. publish your app on Flathub where no internet connection is allowed while running the build commands,
 | 
			
		||||
you can use [this tool](https://github.com/flatpak/flatpak-builder-tools/tree/master/spm) that lets you generate a Flatpak manifest JSON from a Swift package.
 | 
			
		||||
 | 
			
		||||
## Thanks
 | 
			
		||||
 | 
			
		||||
### Dependencies
 | 
			
		||||
- [Adwaita for Swift](https://git.aparoksha.dev/aparoksha/adwaita-swift) licensed under the [MIT License](https://git.aparoksha.dev/aparoksha/adwaita-swift/src/branch/main/LICENSE.md)
 | 
			
		||||
- [Localized](https://git.aparoksha.dev/aparoksha/localized) licensed under the [MIT License](https://git.aparoksha.dev/aparoksha/localized/src/branch/main/LICENSE.md)
 | 
			
		||||
Als GUI maakt deze applicatie gebruik van de Calculator-UI die gemaakt werd voor [Fase 2](https://repo.thealgorithm476.me/Bachelorproef/bap-poc-phase-2) van deze bachelerproef. Als domeinlogica wordt CMath gebruikt, dat werd ontwikkeld om interoperability tussen Swift en C te testen in [Fase 3](https://repo.thealgorithm476.me/Bachelorproef/bap-poc-phase-3).
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										13
									
								
								Sources/CMath/include/add_nums.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Sources/CMath/include/add_nums.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
//
 | 
			
		||||
//  add_nums.h
 | 
			
		||||
//  CMath
 | 
			
		||||
//
 | 
			
		||||
//  Created by TheAlgorithm476 on 28/03/2025.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef __ADD_NUMS_H
 | 
			
		||||
#define __ADD_NUMS_H
 | 
			
		||||
 | 
			
		||||
double add_nums(double a, double b);
 | 
			
		||||
 | 
			
		||||
#endif // __ADD_NUMS_H
 | 
			
		||||
							
								
								
									
										13
									
								
								Sources/CMath/include/div_nums.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Sources/CMath/include/div_nums.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
//
 | 
			
		||||
//  div_nums.h
 | 
			
		||||
//  CMath
 | 
			
		||||
//
 | 
			
		||||
//  Created by TheAlgorithm476 on 28/03/2025.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef __DIV_NUMS_H
 | 
			
		||||
#define __DIV_NUMS_H
 | 
			
		||||
 | 
			
		||||
double div_nums(double a, double b);
 | 
			
		||||
 | 
			
		||||
#endif // __DIV_NUMS_H
 | 
			
		||||
							
								
								
									
										13
									
								
								Sources/CMath/include/mul_nums.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Sources/CMath/include/mul_nums.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
//
 | 
			
		||||
//  mul_nums.h
 | 
			
		||||
//  CMath
 | 
			
		||||
//
 | 
			
		||||
//  Created by TheAlgorithm476 on 28/03/2025.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef __MUL_NUMS_H
 | 
			
		||||
#define __MUL_NUMS_H
 | 
			
		||||
 | 
			
		||||
double mul_nums(double a, double b);
 | 
			
		||||
 | 
			
		||||
#endif // __MUL_NUMS_H
 | 
			
		||||
							
								
								
									
										17
									
								
								Sources/CMath/include/spc_nums.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								Sources/CMath/include/spc_nums.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
//
 | 
			
		||||
//  spc_nums.h
 | 
			
		||||
//  CMath
 | 
			
		||||
//
 | 
			
		||||
//  Created by TheAlgorithm476 on 28/03/2025.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef __SPC_NUMS_H
 | 
			
		||||
#define __SPC_NUMS_H
 | 
			
		||||
 | 
			
		||||
#define POOR_MANS_POW_GUESSES 12
 | 
			
		||||
#define NEWTONIAN_DIV_GUESSES 12
 | 
			
		||||
 | 
			
		||||
double pow(double x, double exp);
 | 
			
		||||
double sqrt(double x);
 | 
			
		||||
 | 
			
		||||
#endif // __SPC_NUMS_H
 | 
			
		||||
							
								
								
									
										13
									
								
								Sources/CMath/include/sub_nums.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Sources/CMath/include/sub_nums.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
//
 | 
			
		||||
//  sub_nums.h
 | 
			
		||||
//  CMath
 | 
			
		||||
//
 | 
			
		||||
//  Created by TheAlgorithm476 on 28/03/2025.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef __SUB_NUMS_H
 | 
			
		||||
#define __SUB_NUMS_H
 | 
			
		||||
 | 
			
		||||
double sub_nums(double a, double b);
 | 
			
		||||
 | 
			
		||||
#endif // __SUB_NUMS_H
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								Sources/CMath/lib/libcmath.so
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Sources/CMath/lib/libcmath.so
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										9
									
								
								Sources/CMath/module.modulemap
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								Sources/CMath/module.modulemap
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
module CMath {
 | 
			
		||||
    header "include/add_nums.h"
 | 
			
		||||
    header "include/sub_nums.h"
 | 
			
		||||
    header "include/mul_nums.h"
 | 
			
		||||
    header "include/div_nums.h"
 | 
			
		||||
    header "include/spc_nums.h"
 | 
			
		||||
    export *
 | 
			
		||||
    link "cmath"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								Sources/PMCalc/Operator.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Sources/PMCalc/Operator.swift
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
enum Operator {
 | 
			
		||||
    case add
 | 
			
		||||
    case sub
 | 
			
		||||
    case mul
 | 
			
		||||
    case div
 | 
			
		||||
    case pow
 | 
			
		||||
    case sqrt
 | 
			
		||||
}
 | 
			
		||||
@@ -2,89 +2,130 @@
 | 
			
		||||
// https://docs.swift.org/swift-book
 | 
			
		||||
 | 
			
		||||
import Adwaita
 | 
			
		||||
import CMath
 | 
			
		||||
 | 
			
		||||
@main
 | 
			
		||||
struct PMCalc: App {
 | 
			
		||||
    let app = AdwaitaApp(id: "me.thealgorithm476.PMCalc.PMCalc")
 | 
			
		||||
    @State
 | 
			
		||||
    var vm = ViewModel()
 | 
			
		||||
 | 
			
		||||
    var scene: Scene {
 | 
			
		||||
        Window(id: "main") { window in
 | 
			
		||||
            VStack(spacing: 8) {
 | 
			
		||||
                Text("Calculations here...")
 | 
			
		||||
                Text(vm.display)
 | 
			
		||||
                    .selectable(false)
 | 
			
		||||
                    .title2()
 | 
			
		||||
                    .halign(.end)
 | 
			
		||||
                VStack(spacing: 8) {
 | 
			
		||||
                    HStack(spacing: 8) {
 | 
			
		||||
                        Button("AC") {}
 | 
			
		||||
                        Button("AC") {
 | 
			
		||||
                            vm.clear()
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("c", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                            .destructive()
 | 
			
		||||
                        Button("") {}
 | 
			
		||||
                        Button("^") {
 | 
			
		||||
                            vm.operation(.pow)
 | 
			
		||||
                        }
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                            .flat()
 | 
			
		||||
                        Button("%") {}
 | 
			
		||||
                            .keyboardShortcut("percent", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("/") {}
 | 
			
		||||
                        Button("/") {
 | 
			
		||||
                            vm.operation(.div)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("slash", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                    }
 | 
			
		||||
                    .vexpand()
 | 
			
		||||
                    HStack(spacing: 8) {
 | 
			
		||||
                        Button("7") {}
 | 
			
		||||
                        Button("7") {
 | 
			
		||||
                            vm.addNumber(7)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("7", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("8") {}
 | 
			
		||||
                        Button("8") {
 | 
			
		||||
                            vm.addNumber(8)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("8", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("9") {}
 | 
			
		||||
                        Button("9") {
 | 
			
		||||
                            vm.addNumber(9)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("9", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("*") {}
 | 
			
		||||
                        Button("*") {
 | 
			
		||||
                            vm.operation(.mul)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("asterisk", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                    }
 | 
			
		||||
                    .vexpand()
 | 
			
		||||
                    HStack(spacing: 8) {
 | 
			
		||||
                        Button("4") {}
 | 
			
		||||
                        Button("4") {
 | 
			
		||||
                            vm.addNumber(4)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("4", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("5") {}
 | 
			
		||||
                        Button("5") {
 | 
			
		||||
                            vm.addNumber(5)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("5", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("6") {}
 | 
			
		||||
                        Button("6") {
 | 
			
		||||
                            vm.addNumber(6)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("6", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("-") {}
 | 
			
		||||
                        Button("-") {
 | 
			
		||||
                            vm.operation(.sub)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("minus", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                    }
 | 
			
		||||
                    .vexpand()
 | 
			
		||||
                    HStack(spacing: 8) {
 | 
			
		||||
                        Button("1") {}
 | 
			
		||||
                        Button("1") {
 | 
			
		||||
                            vm.addNumber(1)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("1", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("2") {}
 | 
			
		||||
                        Button("2") {
 | 
			
		||||
                            vm.addNumber(2)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("2", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("3") {}
 | 
			
		||||
                        Button("3") {
 | 
			
		||||
                            vm.addNumber(3)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("3", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("+") {}
 | 
			
		||||
                        Button("+") {
 | 
			
		||||
                            vm.operation(.add)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("plus", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                    }
 | 
			
		||||
                    .vexpand()
 | 
			
		||||
                    HStack(spacing: 8) {
 | 
			
		||||
                        Button("0") {}
 | 
			
		||||
                        Button("0") {
 | 
			
		||||
                            vm.addNumber(0)
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("0", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("") {}
 | 
			
		||||
                        Button("sq") {
 | 
			
		||||
                            vm.operation(.sqrt)
 | 
			
		||||
                        }
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                            .flat()
 | 
			
		||||
                        Button(",") {}
 | 
			
		||||
                        Button(",") {
 | 
			
		||||
                            vm.addComma()
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("comma", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                        Button("=") {}
 | 
			
		||||
                        Button("=") {
 | 
			
		||||
                            vm.calculate()
 | 
			
		||||
                        }
 | 
			
		||||
                            .keyboardShortcut("equal", app: app)
 | 
			
		||||
                            .hexpand()
 | 
			
		||||
                    }
 | 
			
		||||
							
								
								
									
										73
									
								
								Sources/PMCalc/ViewModel.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								Sources/PMCalc/ViewModel.swift
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,73 @@
 | 
			
		||||
import Adwaita
 | 
			
		||||
import CMath
 | 
			
		||||
 | 
			
		||||
struct ViewModel {
 | 
			
		||||
    private var numberBuffer: String = ""
 | 
			
		||||
    private var number1: Double? = nil
 | 
			
		||||
    private var number2: Double? = nil
 | 
			
		||||
    private var op: Operator? = nil
 | 
			
		||||
    @State
 | 
			
		||||
    private(set) var display: String = ""
 | 
			
		||||
 | 
			
		||||
    mutating func clear() {
 | 
			
		||||
        numberBuffer = ""
 | 
			
		||||
        number1 = nil
 | 
			
		||||
        number2 = nil
 | 
			
		||||
        op = nil
 | 
			
		||||
        display = ""
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mutating func addComma() {
 | 
			
		||||
        guard !numberBuffer.isEmpty else { return }
 | 
			
		||||
 | 
			
		||||
        numberBuffer.append(",")
 | 
			
		||||
        display = numberBuffer
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mutating func addNumber(_ number: UInt8) {
 | 
			
		||||
        if numberBuffer.isEmpty { display = "" } // Reset display after new number is added to cleared buffer
 | 
			
		||||
 | 
			
		||||
        numberBuffer.append(String(number))
 | 
			
		||||
        display = numberBuffer
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mutating func operation(_ op: Operator) {
 | 
			
		||||
        guard !numberBuffer.isEmpty && number1 == nil else { return }
 | 
			
		||||
 | 
			
		||||
        self.op = op
 | 
			
		||||
        if number1 == nil { number1 = Double(numberBuffer) }
 | 
			
		||||
        else { number2 = Double(numberBuffer) }
 | 
			
		||||
        numberBuffer = ""
 | 
			
		||||
 | 
			
		||||
        if op == .sqrt {
 | 
			
		||||
            display = String(sqrt(number1!))
 | 
			
		||||
            number1 = nil
 | 
			
		||||
            self.op = nil
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mutating func calculate() {
 | 
			
		||||
        number2 = Double(numberBuffer)
 | 
			
		||||
        numberBuffer = ""
 | 
			
		||||
 | 
			
		||||
        var result: Double = 0.0
 | 
			
		||||
 | 
			
		||||
        switch op {
 | 
			
		||||
        case .add:
 | 
			
		||||
            result = add_nums(number1!, number2!)
 | 
			
		||||
        case .sub:
 | 
			
		||||
            result = sub_nums(number1!, number2!)
 | 
			
		||||
        case .mul:
 | 
			
		||||
            result = mul_nums(number1!, number2!)
 | 
			
		||||
        case .div:
 | 
			
		||||
            result = div_nums(number1!, number2!)
 | 
			
		||||
        case .pow:
 | 
			
		||||
            result = pow(number1!, number2!)
 | 
			
		||||
        case .sqrt, .none:
 | 
			
		||||
            // do nothing
 | 
			
		||||
            print("Attempting to apply Square Root to nothing!")
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        display = String(result)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -46,7 +46,8 @@
 | 
			
		||||
        "install -Dm644 data/me.thealgorithm476.PMCalc.PMCalc.metainfo.xml $DESTDIR/app/share/metainfo/me.thealgorithm476.PMCalc.PMCalc.metainfo.xml",
 | 
			
		||||
        "install -Dm644 data/me.thealgorithm476.PMCalc.PMCalc.desktop $DESTDIR/app/share/applications/me.thealgorithm476.PMCalc.PMCalc.desktop",
 | 
			
		||||
        "install -Dm644 data/icons/me.thealgorithm476.PMCalc.PMCalc.svg $DESTDIR/app/share/icons/hicolor/scalable/apps/me.thealgorithm476.PMCalc.PMCalc.svg",
 | 
			
		||||
        "install -Dm644 data/icons/me.thealgorithm476.PMCalc.PMCalc-symbolic.svg $DESTDIR/app/share/icons/hicolor/symbolic/apps/me.thealgorithm476.PMCalc.PMCalc-symbolic.svg"
 | 
			
		||||
        "install -Dm644 data/icons/me.thealgorithm476.PMCalc.PMCalc-symbolic.svg $DESTDIR/app/share/icons/hicolor/symbolic/apps/me.thealgorithm476.PMCalc.PMCalc-symbolic.svg",
 | 
			
		||||
        "install -Dm644 Sources/CMath/lib/libcmath.so /app/lib/libcmath.so"
 | 
			
		||||
      ]
 | 
			
		||||
    }
 | 
			
		||||
  ]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user