-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ #94 Initial ability to apply custom window padding
- Loading branch information
Showing
13 changed files
with
298 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// | ||
// PaddingConfigurationView.swift | ||
// Loop | ||
// | ||
// Created by Kai Azim on 2024-02-01. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct PaddingConfigurationView: View { | ||
@Binding var isSheetShown: Bool | ||
@Binding var paddingModel: PaddingModel | ||
@State var useSteppers: Bool = false | ||
|
||
var body: some View { | ||
VStack { | ||
Form { | ||
Section("Padding") { | ||
Toggle("Custom Screen Padding", isOn: $paddingModel.configureScreenPadding) | ||
Toggle("Use Custom Values", isOn: $useSteppers) | ||
} | ||
|
||
Section(content: { | ||
ZStack { | ||
WallpaperView().equatable() | ||
PaddingPreviewView($paddingModel) | ||
} | ||
.ignoresSafeArea() | ||
.padding(-10) | ||
.aspectRatio(16/10, contentMode: .fit) | ||
}, footer: { | ||
HStack { | ||
Text("This preview is not to scale.") | ||
.font(.caption) | ||
.foregroundStyle(.secondary) | ||
Spacer() | ||
} | ||
}) | ||
|
||
if paddingModel.configureScreenPadding { | ||
Section { | ||
paddingAdjuster("Window Gaps", value: $paddingModel.window.toDoubleBinding()) | ||
} | ||
|
||
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()) | ||
} | ||
} else { | ||
paddingAdjuster( | ||
"Padding", | ||
value: Binding( | ||
get: { | ||
paddingModel.window | ||
}, | ||
set: { | ||
paddingModel.window = $0 | ||
paddingModel.top = $0 | ||
paddingModel.bottom = $0 | ||
paddingModel.right = $0 | ||
paddingModel.left = $0 | ||
} | ||
) | ||
) | ||
} | ||
} | ||
.formStyle(.grouped) | ||
.scrollDisabled(true) | ||
|
||
HStack { | ||
Button { | ||
isSheetShown = false | ||
} label: { | ||
Text("Done") | ||
} | ||
.controlSize(.large) | ||
} | ||
.offset(y: -14) | ||
} | ||
.frame(width: 400) | ||
.fixedSize(horizontal: false, vertical: true) | ||
.background(.background) | ||
} | ||
|
||
@ViewBuilder | ||
func paddingAdjuster(_ title: String, value: Binding<Double>) -> some View { | ||
if self.useSteppers { | ||
paddingStepper(title, value: value) | ||
} else { | ||
paddingSlider(title, value: value) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
func paddingSlider(_ title: String, value: Binding<Double>) -> some View { | ||
Slider( | ||
value: value, | ||
in: 0...50, | ||
step: 5, | ||
minimumValueLabel: Text("0px"), | ||
maximumValueLabel: Text("50px") | ||
) { | ||
Text(title) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
func paddingStepper(_ title: String, value: Binding<Double>) -> some View { | ||
HStack { | ||
Stepper( | ||
title, | ||
value: value, | ||
in: 0...100, | ||
format: .number | ||
) | ||
Text("px") | ||
} | ||
} | ||
} | ||
|
||
extension Binding where Value == CGFloat { | ||
fileprivate func toDoubleBinding() -> Binding<Double> { | ||
Binding<Double>(get: { | ||
Double(self.wrappedValue) | ||
}, set: { | ||
self.wrappedValue = CGFloat($0) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// PaddingPreviewView.swift | ||
// Loop | ||
// | ||
// Created by Kai Azim on 2024-02-01. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct PaddingPreviewView: View { | ||
|
||
@Binding var paddingModel: PaddingModel | ||
|
||
init(_ paddingModel: Binding<PaddingModel>) { | ||
self._paddingModel = paddingModel | ||
} | ||
|
||
var body: some View { | ||
ZStack { | ||
HStack(spacing: paddingModel.window) { | ||
blurredWindow() | ||
|
||
VStack(spacing: paddingModel.window) { | ||
blurredWindow() | ||
blurredWindow() | ||
} | ||
} | ||
.padding(.top, paddingModel.top) | ||
.padding(.bottom, paddingModel.bottom) | ||
.padding(.leading, paddingModel.right) | ||
.padding(.trailing, paddingModel.left) | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
func blurredWindow() -> some View { | ||
VisualEffectView(material: .hudWindow, blendingMode: .withinWindow) | ||
.overlay { | ||
RoundedRectangle(cornerRadius: 10) | ||
.strokeBorder(.white.opacity(0.1), lineWidth: 2) | ||
} | ||
.clipShape(.rect(cornerRadius: 10)) | ||
} | ||
} |
Oops, something went wrong.