Skip to content

Commit 96af6cc

Browse files
committed
Use continuous slider (no steps)
This improves the look *and* performance on macOS because macOS renders a tick mark for each step. Especially noticeable during window resizing: ~1,000 tick marks slow it down to a crawl. We still propose rounded values to the inspected view.
1 parent a8741c2 commit 96af6cc

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

LayoutInspector/ContentView.swift

+8-5
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@ struct Inspector<Subject: View>: View {
5151
@State private var selectedView: String? = nil
5252
@State private var generation: Int = 0
5353

54+
private var roundedWidth: CGFloat { width.rounded() }
55+
private var roundedHeight: CGFloat { height.rounded() }
56+
5457
var body: some View {
5558
VStack {
5659
VStack {
5760
subject
5861
.startDebugLayout(selection: selectedView)
5962
.id(generation)
60-
.frame(width: width, height: height)
63+
.frame(width: roundedWidth, height: roundedHeight)
6164
.overlay {
6265
Rectangle()
6366
.strokeBorder(style: StrokeStyle(dash: [5]))
@@ -67,23 +70,23 @@ struct Inspector<Subject: View>: View {
6770
VStack {
6871
LabeledContent {
6972
HStack {
70-
Slider(value: $width, in: 0...500, step: 1)
73+
Slider(value: $width, in: 0...500)
7174
Stepper("Width", value: $width)
7275
}
7376
.labelsHidden()
7477
} label: {
75-
Text("W \(width, format: .number.precision(.fractionLength(0)))")
78+
Text("W \(roundedWidth, format: .number.precision(.fractionLength(0)))")
7679
.monospacedDigit()
7780
}
7881

7982
LabeledContent {
8083
HStack {
81-
Slider(value: $height, in: 0...500, step: 1)
84+
Slider(value: $height, in: 0...500)
8285
Stepper("Height", value: $height)
8386
}
8487
.labelsHidden()
8588
} label: {
86-
Text("H \(height, format: .number.precision(.fractionLength(0)))")
89+
Text("H \(roundedHeight, format: .number.precision(.fractionLength(0)))")
8790
.monospacedDigit()
8891
}
8992

0 commit comments

Comments
 (0)