Skip to content

Commit 96a3278

Browse files
committed
Inspector scroll view positioning/sizing
1 parent 35e0b39 commit 96a3278

File tree

2 files changed

+70
-61
lines changed

2 files changed

+70
-61
lines changed

Sources/LayoutInspector/DebugLayoutImpl.swift

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct InspectLayout: ViewModifier {
77
@State private var generation: Int = 0
88
@State private var inspectorFrame: CGRect = CGRect(x: 0, y: 0, width: 300, height: 300)
99
@State private var contentSize: CGSize? = nil
10+
@State private var tableSize: CGSize? = nil
1011
@State private var isPresentingInfoPanel: Bool = false
1112

1213
private static let coordSpaceName = "InspectLayout"
@@ -34,23 +35,31 @@ struct InspectLayout: ViewModifier {
3435
}
3536

3637
@ViewBuilder private var inspectorUI: some View {
37-
LogEntriesGrid(logEntries: logStore.log, highlight: $selectedView)
38-
.safeAreaInset(edge: .bottom) {
39-
toolbar
40-
}
41-
.resizableAndDraggable(
42-
frame: $inspectorFrame,
43-
coordinateSpace: .named(Self.coordSpaceName)
44-
)
45-
.background {
46-
Rectangle().fill(.thickMaterial)
47-
.shadow(radius: 5)
48-
}
49-
.cornerRadius(4)
50-
.overlay {
51-
RoundedRectangle(cornerRadius: 4)
52-
.strokeBorder(.quaternary)
53-
}
38+
ScrollView([.vertical, .horizontal]) {
39+
LogEntriesGrid(logEntries: logStore.log, highlight: $selectedView)
40+
.measureSize { size in
41+
tableSize = size
42+
}
43+
}
44+
.frame(maxWidth: tableSize?.width, maxHeight: tableSize?.height)
45+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
46+
.safeAreaInset(edge: .bottom) {
47+
toolbar
48+
}
49+
.font(.subheadline)
50+
.resizableAndDraggable(
51+
frame: $inspectorFrame,
52+
coordinateSpace: .named(Self.coordSpaceName)
53+
)
54+
.background {
55+
Rectangle().fill(.thickMaterial)
56+
.shadow(radius: 5)
57+
}
58+
.cornerRadius(4)
59+
.overlay {
60+
RoundedRectangle(cornerRadius: 4)
61+
.strokeBorder(.quaternary)
62+
}
5463
}
5564

5665
@ViewBuilder private var toolbar: some View {

Sources/LayoutInspector/LogEntriesGrid.swift

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,59 +19,59 @@ public struct LogEntriesGrid: View {
1919
}
2020

2121
public var body: some View {
22-
ScrollView([.vertical, .horizontal]) {
23-
Grid(alignment: .leadingFirstTextBaseline, horizontalSpacing: 0, verticalSpacing: 0) {
24-
// Table header row
25-
GridRow {
26-
Text("View")
27-
Text("Proposal")
28-
Text("Response")
29-
}
30-
.font(.headline)
22+
Grid(
23+
alignment: .leadingFirstTextBaseline,
24+
horizontalSpacing: 0,
25+
verticalSpacing: 0
26+
) {
27+
// Table header row
28+
GridRow {
29+
Text("View")
30+
Text("Proposal")
31+
Text("Response")
32+
}
33+
.bold()
34+
.padding(.vertical, Self.tableRowVerticalPadding)
35+
.padding(.horizontal, Self.tableRowHorizontalPadding)
36+
37+
// Table header separator line
38+
Rectangle().fill(.secondary)
39+
.frame(height: 1)
40+
.gridCellUnsizedAxes(.horizontal)
3141
.padding(.vertical, Self.tableRowVerticalPadding)
3242
.padding(.horizontal, Self.tableRowHorizontalPadding)
3343

34-
// Table header separator line
35-
Rectangle().fill(.secondary)
36-
.frame(height: 1)
37-
.gridCellUnsizedAxes(.horizontal)
38-
.padding(.vertical, Self.tableRowVerticalPadding)
39-
.padding(.horizontal, Self.tableRowHorizontalPadding)
44+
// Table rows
45+
ForEach(logEntries) { item in
46+
let isSelected = highlight == item.label
47+
GridRow {
48+
HStack(spacing: 0) {
49+
indentation(level: item.indent)
50+
Text(item.label)
51+
}
52+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
4053

41-
// Table rows
42-
ForEach(logEntries) { item in
43-
let isSelected = highlight == item.label
44-
GridRow {
45-
HStack(spacing: 0) {
46-
indentation(level: item.indent)
47-
Text(item.label)
48-
.font(.body)
49-
}
54+
Text(item.proposal?.pretty ?? "")
55+
.monospacedDigit()
56+
.fixedSize()
5057
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
5158

52-
Text(item.proposal?.pretty ?? "")
53-
.monospacedDigit()
54-
.fixedSize()
55-
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
56-
57-
Text(item.response?.pretty ?? "")
58-
.monospacedDigit()
59-
.fixedSize()
60-
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
61-
}
62-
.font(.callout)
63-
.padding(.vertical, Self.tableRowVerticalPadding)
64-
.padding(.horizontal, Self.tableRowHorizontalPadding)
65-
.foregroundColor(isSelected ? .white : nil)
66-
.background(isSelected ? Color.accentColor : .clear)
67-
.contentShape(Rectangle())
68-
.onTapGesture {
69-
highlight = isSelected ? nil : item.label
70-
}
59+
Text(item.response?.pretty ?? "")
60+
.monospacedDigit()
61+
.fixedSize()
62+
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
63+
}
64+
.padding(.vertical, Self.tableRowVerticalPadding)
65+
.padding(.horizontal, Self.tableRowHorizontalPadding)
66+
.foregroundColor(isSelected ? .white : nil)
67+
.background(isSelected ? Color.accentColor : .clear)
68+
.contentShape(Rectangle())
69+
.onTapGesture {
70+
highlight = isSelected ? nil : item.label
7171
}
7272
}
73-
.padding(.vertical, 8)
7473
}
74+
.padding(.vertical, 8)
7575
}
7676

7777
private func indentation(level: Int) -> some View {

0 commit comments

Comments
 (0)