Skip to content

Commit

Permalink
Add more debugging colors to debug macOS target
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Oct 26, 2024
1 parent b20362d commit 1c24a1f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 14 deletions.
14 changes: 14 additions & 0 deletions ExampleProject/ExampleProject/ExampleProjectApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import SplitViewKit
import HybridColor
/**
* We use this xcode project to test with simulator and compact mode etc
* - Note: To hide the title bar for a macOS app in SwiftUI, you can use the .windowStyle() modifier on the WindowGroup within your App structure. Specifically, you can apply the HiddenTitleBarWindowStyle() to achieve this effect. This will remove the title bar from the window, giving your app a more modern, clean appearance.
* - Note: More info regarding windowStyle: https://developer.apple.com/documentation/swiftui/windowgroup/windowstyle(_:)
* - Note: More info regarding windowStyle: https://stackoverflow.com/questions/70501890/how-can-i-hide-title-bar-in-swiftui-for-macos-app
*/
@main
struct ExampleProjectApp: App { // App Protocol: Conforms to the App protocol which is required for SwiftUI apps.
Expand All @@ -16,5 +19,16 @@ struct ExampleProjectApp: App { // App Protocol: Conforms to the App protocol wh
#endif
// .persistentSystemOverlays(.hidden) // Hide the Home Indicator (looks better for demos)
}
// This line applies the HiddenTitleBarWindowStyle to the window, effectively hiding the title bar when the app runs on macOS.
#if os(macOS) // Not available on macOS
.windowStyle(HiddenTitleBarWindowStyle()) // Apply hidden title bar style
#endif
}
}
/**
* Debugging with background colors
* - Description: This section is used for debugging purposes, allowing
* developers to visually identify different areas of the
* interface by applying distinct background colors.
*/
internal var isTest: Bool = true
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import HybridColor
* - Note: Preview does not seem to support resizing window atm
* - Note: We have to add the statusBar remover for this preview, to simulate exactly how it looks like in simulator etc
*/
#Preview(traits: .fixedLayout(width: 700, height: 500)) {
#Preview(traits: .fixedLayout(width: 800, height: 500)) {
ExampleView()
.background(Color.blackOrWhite.opacity(1))
.environment(\.colorScheme, .dark) // dark
Expand Down
8 changes: 1 addition & 7 deletions ExampleProject/ExampleProject/example/ExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,4 @@ struct ExampleView: View {
self.selectedMainItem = selectedMainItem
}
}
/**
* Debugging with background colors
* - Description: This section is used for debugging purposes, allowing
* developers to visually identify different areas of the
* interface by applying distinct background colors.
*/
internal var isTest: Bool = false

Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ extension DetailHeader {
* Body
*/
var body: some View {
VStack {
VStack(spacing: .zero) {
HStack { // hstack
backButton // btn to left
Spacer()
fullScreenToggleButton // btn to right
}
.background(isTest ? .pink.opacity(0.5) : .clear) // ⚠️️ debug
HStack { // hstack with title to left
titleText
Spacer()
}
.background(isTest ? .purple.opacity(0.5) : .clear) // ⚠️️ debug
}
.padding(.horizontal) // Adds left and right padding
.padding(.vertical)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension DetailList {
let screenSize = NSApplication.shared.windows.first?.frame.size ?? CGSize(width: 600, height: 400)
button.frame(width: screenSize.width * 0.6, height: screenSize.height * 0.6)
#else
button // no sizing needed for iPad
button // No sizing needed for iPad
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ extension MainHeader {
* button for the sidebar and a title.
*/
var body: some View {
VStack {
VStack(spacing: .zero) {
HStack { // button (top-left)
button
Spacer()
}
.background(isTest ? .pink.opacity(0.5) : .clear) // ⚠️️ debug
HStack { // title (bottom-left)
titleText
Spacer()
}
.background(isTest ? .purple.opacity(0.5) : .clear) // ⚠️️ debug
}
// - Fixme: ⚠️️ Could this cause an issue, is it needed?
.frame(maxWidth: .infinity) // Forces the view to not shrink to text, but rather expand to it's parent width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ extension SideBarHeader {
* - Description: The header of the sidebar, which includes the title and a size class indicator.
*/
var body: some View {
VStack {
VStack(spacing: .zero) {
HStack {
sideBarToggleButton // Top-left
Spacer()
}
.background(isTest ? .pink.opacity(0.5) : .clear) // ⚠️️ debug
HStack {
titleText // Bottom-left
Spacer()
}
.background(isTest ? .purple.opacity(0.5) : .clear) // ⚠️️ debug
}
.padding(.horizontal) // Adds left and right padding
.padding(.vertical) // Adds top and bottom padding to the VStack.
Expand Down Expand Up @@ -52,7 +54,8 @@ extension SideBarHeader {
// Animate opacity changes smoothly with .easeInOut(duration: 0.3) based on sidebar visibility.
.animation(.easeInOut(duration: 0.3), value: splitConfig.columnVisibility == .all)
} else { // hide button in compact mode
Color.clear.frame(width: 36, height: 36) // Creates a ghost area, to avoid collapsing the space when button is hidden
(isTest ? Color.blue : Color.clear) // Creates a ghost area, to avoid collapsing the space when button is hidden
.frame(width: 36, height: 36)
}
}
}
9 changes: 8 additions & 1 deletion Sources/SplitViewKit/SplitViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ public struct SplitViewWrapper<SideBar: View, Content: View, Detail: View, Overl
* ensure accurate detection of the mode, as incorrect scope
* access can lead to misidentification between compact and
* regular modes.
* - Important: ⚠️ Needs to be called from the correct scope. Jumps to compact when it should be regular in the wrong scope etc. So param drilling is probably better to avoid future hard to find bugs
* - Important: ⚠️ Needs to be called from the correct scope. Jumps to
* compact when it should be regular in the wrong scope etc.
* So param drilling is probably better to avoid future hard
* to find bugs
* - Important: ⚠️️ `UserInterfaceSizeClass` is not natively available on
* macOS. When you try to use `@Environment(\.horizontalSizeClass)`
* or `@Environment(\.verticalSizeClass)` on macOS, you'll
* encounter errors stating that these properties are unavailable.
*/
@Environment(\.horizontalSizeClass) internal var sizeClass: UserInterfaceSizeClass?
/**
Expand Down

0 comments on commit 1c24a1f

Please sign in to comment.