Skip to content

Commit

Permalink
#207 Initial self-made stepper
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Feb 16, 2024
1 parent 396bb3e commit 658f41c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 40 deletions.
4 changes: 4 additions & 0 deletions Loop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
A80900D52AA3F9F30085C63B /* VisualEffectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A80900D32AA3F9F20085C63B /* VisualEffectView.swift */; };
A81989062AC8EDB300EFF7A1 /* MenuBarHeaderText.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81989052AC8EDB300EFF7A1 /* MenuBarHeaderText.swift */; };
A81989082AC8F2AE00EFF7A1 /* MenuBarResizeButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A81989072AC8F2AE00EFF7A1 /* MenuBarResizeButton.swift */; };
A82436062B7EE55C0052FBFB /* CrispValueAdjuster.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82436052B7EE55C0052FBFB /* CrispValueAdjuster.swift */; };
A82521EC29E234EB00139654 /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82521EB29E234EB00139654 /* AboutViewController.swift */; };
A82521EE29E235AC00139654 /* PermissionsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82521ED29E235AC00139654 /* PermissionsManager.swift */; };
A82740982AB00FCE00B9BDC5 /* Color+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82740972AB00FCE00B9BDC5 /* Color+Extensions.swift */; };
Expand Down Expand Up @@ -95,6 +96,7 @@
A80900D32AA3F9F20085C63B /* VisualEffectView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VisualEffectView.swift; sourceTree = "<group>"; };
A81989052AC8EDB300EFF7A1 /* MenuBarHeaderText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarHeaderText.swift; sourceTree = "<group>"; };
A81989072AC8F2AE00EFF7A1 /* MenuBarResizeButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarResizeButton.swift; sourceTree = "<group>"; };
A82436052B7EE55C0052FBFB /* CrispValueAdjuster.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrispValueAdjuster.swift; sourceTree = "<group>"; };
A82521EB29E234EB00139654 /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
A82521ED29E235AC00139654 /* PermissionsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionsManager.swift; sourceTree = "<group>"; };
A82740972AB00FCE00B9BDC5 /* Color+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -195,6 +197,7 @@
A8D6D3002B6C894C0061B11F /* PaddingModel.swift */,
A8D6D3042B6C92F20061B11F /* WallpaperView.swift */,
A8063A722B19891900EAB3D9 /* grid.metal */,
A82436052B7EE55C0052FBFB /* CrispValueAdjuster.swift */,
);
path = Utilities;
sourceTree = "<group>";
Expand Down Expand Up @@ -544,6 +547,7 @@
A82740982AB00FCE00B9BDC5 /* Color+Extensions.swift in Sources */,
A869C1A12B38C6E600AD1A84 /* StageManager.swift in Sources */,
A8DCC9882981B9E100D41065 /* RadialMenuSettingsView.swift in Sources */,
A82436062B7EE55C0052FBFB /* CrispValueAdjuster.swift in Sources */,
A8F0636D2985AF1F0010C33D /* MoreSettingsView.swift in Sources */,
A8330ACD2A3AC1D100673C8D /* CGGeometry+Extensions.swift in Sources */,
A8330AC72A3AC19500673C8D /* NSScreen+Extensions.swift in Sources */,
Expand Down
50 changes: 10 additions & 40 deletions Loop/Settings/Padding/PaddingConfigurationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@ struct PaddingConfigurationView: View {

if paddingModel.configureScreenPadding {
Section {
paddingAdjuster("Window Gaps", value: $paddingModel.window.toDoubleBinding())
paddingAdjuster(
CrispValueAdjuster("Window Gaps", value: $paddingModel.window, postfix: "px")
CrispValueAdjuster(
"External Bar",
value: $paddingModel.externalBar.toDoubleBinding(),
description: "Use this if you are using a custom menubar."
description: "Use this if you are using a custom menubar.",
value: $paddingModel.window,
postfix: "px"
)
}

Section("Screen Padding") {
paddingAdjuster("Top", value: $paddingModel.top.toDoubleBinding())
paddingAdjuster("Bottom", value: $paddingModel.bottom.toDoubleBinding())
paddingAdjuster("Right", value: $paddingModel.right.toDoubleBinding())
paddingAdjuster("Left", value: $paddingModel.left.toDoubleBinding())
CrispValueAdjuster("Top", value: $paddingModel.top, postfix: "px")
CrispValueAdjuster("Bottom", value: $paddingModel.bottom, postfix: "px")
CrispValueAdjuster("Right", value: $paddingModel.right, postfix: "px")
CrispValueAdjuster("Left", value: $paddingModel.left, postfix: "px")
}
} else {
paddingAdjuster(
CrispValueAdjuster(
"Padding",
value: Binding(
get: {
Expand Down Expand Up @@ -94,35 +95,4 @@ struct PaddingConfigurationView: View {
.fixedSize(horizontal: false, vertical: true)
.background(.background)
}

@ViewBuilder
func paddingAdjuster(_ title: String, value: Binding<Double>, description: String? = nil) -> some View {
VStack(alignment: .leading) {
HStack {
Stepper(
title,
value: value,
in: 0...100,
format: .number
)
Text("px")
}

if let description = description {
Text(description)
.font(.caption)
.foregroundStyle(.secondary)
}
}
}
}

extension Binding where Value == CGFloat {
fileprivate func toDoubleBinding() -> Binding<Double> {
Binding<Double>(get: {
Double(self.wrappedValue)
}, set: {
self.wrappedValue = CGFloat($0)
})
}
}
76 changes: 76 additions & 0 deletions Loop/Utilities/CrispValueAdjuster.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// CrispValueAdjuster.swift
// Loop
//
// Created by Kai Azim on 2024-02-15.
//

import SwiftUI

// TODO: CHANGE NAME
struct CrispValueAdjuster<V>: View where V: Strideable {

let title: String
let description: String?
@Binding var value: V
let postfix: String?

init(_ title: String, description: String? = nil, value: Binding<V>, postfix: String? = nil) {
self.title = title
self.description = description
self._value = value
self.postfix = postfix
}

var body: some View {
HStack {
VStack(alignment: .leading) {
Text(title)

if let description = description {
Text(description)
.font(.caption)
.foregroundStyle(.secondary)
}
}

Spacer()

TextField("", value: $value, formatter: NumberFormatter())
.labelsHidden()
.textFieldStyle(.plain)
.padding(4)
.padding(.trailing, 12)
.background {
ZStack {
RoundedRectangle(cornerRadius: 6)
.foregroundStyle(.background)
RoundedRectangle(cornerRadius: 6)
.strokeBorder(
.tertiary.opacity(0.5),
lineWidth: 1
)
}
}
.frame(minWidth: 20, maxWidth: 200)
.overlay {
HStack {
Spacer()

Stepper("", value: $value, step: 10)
.labelsHidden()
}
.padding(.horizontal, 1)
}
.fixedSize()

if let postfix = postfix {
Text(postfix)
}
}
}
}

//#Preview {
// CrispValueAdjuster()
//}

0 comments on commit 658f41c

Please sign in to comment.