forked from ole/swiftui-layout-inspector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSelectedViewHighlight.swift
34 lines (30 loc) · 1.1 KB
/
SelectedViewHighlight.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import SwiftUI
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
struct DebugLayoutSelectedViewID: EnvironmentKey {
static var defaultValue: String? { nil }
}
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
extension EnvironmentValues {
var debugLayoutSelectedViewID: String? {
get { self[DebugLayoutSelectedViewID.self] }
set { self[DebugLayoutSelectedViewID.self] = newValue }
}
}
/// Draws a highlight (dashed border) around the view that's selected
/// in the DebugLayout log table.
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
struct DebugLayoutSelectionHighlight: ViewModifier {
var viewID: String
@Environment(\.debugLayoutSelectedViewID) private var selection: String?
func body(content: Content) -> some View {
content
.overlay {
let isSelected = viewID == selection
if isSelected {
Rectangle()
.strokeBorder(style: StrokeStyle(lineWidth: 2, dash: [5]))
.foregroundColor(.pink)
}
}
}
}