Skip to content

Commit

Permalink
feat: improve settings layout (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShlomoCode authored Jul 12, 2024
1 parent 0c0e939 commit 97a2ec4
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 88 deletions.
97 changes: 22 additions & 75 deletions DockDoor/Views/Settings/AppearanceSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct AppearanceSettingsView: View {
@Default(.showAnimations) var showAnimations
@Default(.uniformCardRadius) var uniformCardRadius
@Default(.windowTitleStyle) var windowTitleStyle
@Default(.bufferFromDock) var bufferFromDock
@Default(.windowTitlePosition) var windowTitlePosition
@Default(.showWindowTitle) var showWindowTitle
@Default(.windowTitleDisplayCondition) var windowTitleDisplayCondition
Expand All @@ -29,31 +28,26 @@ struct AppearanceSettingsView: View {
Text("Use Uniform Image Preview Radius")
})

VStack(alignment: .leading){
HStack {
Slider(value: $bufferFromDock, in: -200...200, step: 20) {
Text("Window Buffer")
}
.buttonStyle(PlainButtonStyle())
.frame(width: 400)
TextField("", value: $bufferFromDock, formatter: NumberFormatter())
.textFieldStyle(RoundedBorderTextFieldStyle())
.frame(width: 50)
}
Text("Adjust this if the preview is misaligned with dock")
.font(.footnote)
.foregroundColor(.gray)
}

SizePickerView()

Picker("Hover Window Title Style", selection: $windowTitleStyle) {
ForEach(WindowTitleStyle.allCases, id: \.self) { style in
Text(style.localizedName)
.tag(style.rawValue)
.tag(style)
}
}
.pickerStyle(MenuPickerStyle())
.scaledToFit()
.layoutPriority(1)

Picker("Traffic Light Buttons Visibility", selection: $trafficLightButtonsVisibility) {
ForEach(TrafficLightButtonsVisibility.allCases, id: \.self) { visibility in
Text(visibility.localizedName)
.tag(visibility)
}
}
.pickerStyle(MenuPickerStyle())
.scaledToFit()

Divider()

Toggle(isOn: $showWindowTitle) {
Text("Show Window Titles on Previews")
Expand All @@ -63,77 +57,30 @@ struct AppearanceSettingsView: View {
Picker("Show Window Titles", selection: $windowTitleDisplayCondition) {
ForEach(WindowTitleDisplayCondition.allCases, id: \.self) { condtion in
if condtion == .always {
Text(condtion.localizedName).tag(condtion)
Text(condtion.localizedName)
.tag(condtion)
Divider() // Separate from Window Switcher & Dock Previews
} else {
Text(condtion.localizedName).tag(condtion)
Text(condtion.localizedName)
.tag(condtion)
}
}
}
.pickerStyle(MenuPickerStyle())
.scaledToFit()

Picker("Window Title Position", selection: $windowTitlePosition) {
ForEach(WindowTitlePosition.allCases, id: \.self) { position in
Text(position.localizedName).tag(position).scaledToFit()
Text(position.localizedName)
.tag(position)
}
}
.scaledToFit()
.pickerStyle(SegmentedPickerStyle())
}
.disabled(!showWindowTitle)

Picker("Traffic Light Buttons Visibility", selection: $trafficLightButtonsVisibility) {
ForEach(TrafficLightButtonsVisibility.allCases, id: \.self) { visibility in
Text(visibility.localizedName)
.tag(visibility.rawValue)
}
}
.scaledToFit()
}
.padding(20)
.frame(minWidth: 650)
}
}

struct SizePickerView: View {
@Default(.sizingMultiplier) var sizingMultiplier
@Default(.bufferFromDock) var bufferFromDock

var body: some View {
VStack(spacing: 20) {
Picker("Window Size", selection: $sizingMultiplier) {
ForEach(2...10, id: \.self) { size in
Text(getLabel(for: CGFloat(size))).tag(CGFloat(size))
}
}
.scaledToFit()
.onChange(of: sizingMultiplier) { _, newValue in
SharedPreviewWindowCoordinator.shared.windowSize = getWindowSize()
}
}
}

private func getLabel(for size: CGFloat) -> String {
switch size {
case 2:
return String(localized: "Large", comment: "Window size option")
case 3:
return String(localized: "Default (Medium Large)", comment: "Window size option")
case 4:
return String(localized:"Medium", comment: "Window size option")
case 5:
return String(localized:"Small", comment: "Window size option")
case 6:
return String(localized:"Extra Small", comment: "Window size option")
case 7:
return String(localized:"Extra Extra Small", comment: "Window size option")
case 8:
return String(localized:"What is this? A window for ANTS?", comment: "Window size option")
case 9:
return String(localized:"Subatomic", comment: "Window size option")
case 10:
return String(localized:"Can you even see this?", comment: "Window size option")
default:
return "Unknown Size"
}
}
}
102 changes: 89 additions & 13 deletions DockDoor/Views/Settings/MainSettingsView.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// MainSettingsView.swift
// DockDoor
//
// Created by Ethan Bills on 6/13/24.
//

import SwiftUI
import Defaults
import LaunchAtLogin
Expand All @@ -15,6 +22,7 @@ struct MainSettingsView: View {
@Default(.showMenuBarIcon) var showMenuBarIcon
@Default(.tapEquivalentInterval) var tapEquivalentInterval
@Default(.previewHoverAction) var previewHoverAction
@Default(.bufferFromDock) var bufferFromDock

var body: some View {
VStack(alignment: .leading, spacing: 10) {
Expand Down Expand Up @@ -45,44 +53,112 @@ struct MainSettingsView: View {
}
}

Divider()

HStack {
Text("Hover Window Open Delay")
.layoutPriority(1)
Spacer()
Slider(value: $hoverWindowOpenDelay, in: 0...2, step: 0.1)
TextField("", value: $hoverWindowOpenDelay, formatter: decimalFormatter)
.frame(width: 40)
.frame(width: 38)
.textFieldStyle(RoundedBorderTextFieldStyle())
Text("seconds")
}

VStack(alignment: .leading){
HStack {
Slider(value: $bufferFromDock, in: -200...200, step: 20) {
Text("Window Buffer")
}
.buttonStyle(PlainButtonStyle())
.frame(width: 400)
TextField("", value: $bufferFromDock, formatter: NumberFormatter())
.textFieldStyle(RoundedBorderTextFieldStyle())
.frame(width: 50)
}
Text("Adjust this if the preview is misaligned with dock")
.font(.footnote)
.foregroundColor(.gray)
}

SizePickerView()

HStack {
Text("Window Cache Lifespan")
.layoutPriority(1)
Spacer()
Slider(value: $screenCaptureCacheLifespan, in: 0...60, step: 5)
TextField("", value: $screenCaptureCacheLifespan, formatter: NumberFormatter())
.frame(width: 35)
.frame(width: 38)
.textFieldStyle(RoundedBorderTextFieldStyle())
Text("seconds")
}

HStack {
Text("Preview Hover Delay: \(tapEquivalentInterval, specifier: "%.1f") seconds")
Spacer()
Slider(value: $tapEquivalentInterval, in: 0...2, step: 0.1)
Picker("Preview Hover Action", selection: $previewHoverAction) {
ForEach(PreviewHoverAction.allCases, id: \.self) { action in
Text(action.localizedName).tag(action)
}
}
.pickerStyle(MenuPickerStyle())
.scaledToFit()

HStack {
Picker("Preview Hover Action", selection: $previewHoverAction) {
ForEach(PreviewHoverAction.allCases, id: \.self) { action in
Text(action.localizedName).tag(action)
}
}
.pickerStyle(MenuPickerStyle())
Text("Preview Hover Delay")
Spacer()
Slider(value: $tapEquivalentInterval, in: 0...2, step: 0.1)
TextField("", value: $tapEquivalentInterval, formatter: NumberFormatter())
.frame(width: 38)
.textFieldStyle(RoundedBorderTextFieldStyle())
Text("seconds")
}
.disabled(previewHoverAction == .none)
}
.padding(20)
.frame(minWidth: 650)
}
}
}

struct SizePickerView: View {
@Default(.sizingMultiplier) var sizingMultiplier
@Default(.bufferFromDock) var bufferFromDock

var body: some View {
VStack(spacing: 20) {
Picker("Window Size", selection: $sizingMultiplier) {
ForEach(2...10, id: \.self) { size in
Text(getLabel(for: CGFloat(size))).tag(CGFloat(size))
}
}
.scaledToFit()
.onChange(of: sizingMultiplier) { _, newValue in
SharedPreviewWindowCoordinator.shared.windowSize = getWindowSize()
}
}
}

private func getLabel(for size: CGFloat) -> String {
switch size {
case 2:
return String(localized: "Large", comment: "Window size option")
case 3:
return String(localized: "Default (Medium Large)", comment: "Window size option")
case 4:
return String(localized:"Medium", comment: "Window size option")
case 5:
return String(localized:"Small", comment: "Window size option")
case 6:
return String(localized:"Extra Small", comment: "Window size option")
case 7:
return String(localized:"Extra Extra Small", comment: "Window size option")
case 8:
return String(localized:"What is this? A window for ANTS?", comment: "Window size option")
case 9:
return String(localized:"Subatomic", comment: "Window size option")
case 10:
return String(localized:"Can you even see this?", comment: "Window size option")
default:
return "Unknown Size"
}
}
}

0 comments on commit 97a2ec4

Please sign in to comment.