Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate inspector #1

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 47 additions & 51 deletions LayoutInspector/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,61 @@ import SwiftUI
import DebugLayout

struct ContentView: View {
@State private var width: CGFloat = 300
@State private var height: CGFloat = 100
@State private var selectedView: String? = nil
@State private var generation: Int = 0

// MARK: - Edit here

/// The view tree whose layout you want to inspect. Add `.debugLayout()` calls at
/// each point where you want to inspect the layout algorithm, i.e. what sizes are
/// being proposed and returned. We call these **inspection points**.
///
/// ## Suggested examples
///
/// ### Padding
///
/// var subject: some View {
/// Text("Hello world")
/// .debugLayout("Text")
/// .padding(10)
/// .debugLayout("padding")
/// .border(Color.green)
/// .debugLayout("border")
/// }
///
/// ### Stacks
///
/// var subject: some View {
/// HStack(spacing: 10) {
/// Rectangle().fill(.green)
/// .debugLayout("green")
/// Text("Hello world")
/// .debugLayout("Text")
/// Rectangle().fill(.yellow)
/// .debugLayout("yellow")
/// }
/// .debugLayout("HStack")
/// }
///
/// ### fixedSize
///
/// var subject: some View {
/// Text("Lorem ipsum dolor sit amet")
/// .debugLayout("Text")
/// .fixedSize()
/// .debugLayout("fixedSize")
/// .frame(width: 100)
/// .debugLayout("frame")
/// .border(Color.green)
/// }
var subject: some View {
var suggestedExamplePadding: some View {
Text("Hello world")
.debugLayout("Text")
.padding(10)
.debugLayout("padding")
.border(Color.green)
.debugLayout("border")

}

var hstack: some View {
HStack(spacing: 10) {
Rectangle().fill(.green)
.debugLayout("green")
Text("Hello world")
.debugLayout("Text")
Rectangle().fill(.yellow)
.debugLayout("yellow")
}
.debugLayout("HStack")
}

// MARK: Edit end
var fixedSize: some View {
Text("Lorem ipsum dolor sit amet")
.debugLayout("Text")
.fixedSize()
.debugLayout("fixedSize")
.frame(width: 100)
.debugLayout("frame")
.border(Color.green)
}

var body: some View {
Inspector {
hstack
}
}
}

struct Inspector<Subject: View>: View {

/// The view tree whose layout you want to inspect. Add `.debugLayout()` calls at
/// each point where you want to inspect the layout algorithm, i.e. what sizes are
/// being proposed and returned. We call these **inspection points**.
@ViewBuilder var subject: Subject

init(@ViewBuilder subject: () -> Subject) {
self.subject = subject()
}

@State private var width: CGFloat = 300
@State private var height: CGFloat = 100
@State private var selectedView: String? = nil
@State private var generation: Int = 0


var body: some View {
VStack {
Expand Down