diff --git a/Sources/OpenSwiftUICore/Render/DisplayList/DisplayList+String.swift b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayList+String.swift new file mode 100644 index 00000000..4cb5c48a --- /dev/null +++ b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayList+String.swift @@ -0,0 +1,91 @@ +// +// DisplayList+String.swift +// OpenSwiftUICore +// +// Audited for RELEASE_2024 +// Status: WIP +// ID: 11125C146A81D1913BFBD53B89D010C6 + +extension DisplayList.Item { + // TODO + var features: DisplayList.Features { [] } + var properties: DisplayList.Properties { [] } + + fileprivate func print(into printer: inout SExpPrinter) { + printer.push("item") + if identity.value != .zero { + printer.print("#:identity \(identity.value)", newline: false) + } + printer.print("#:version \(version.value)", newline: false) + if features.contains(.required) { + printer.print("#:required true", newline: false) + } + if features.contains(.views) { + printer.print("#:views true", newline: false) + } + printer.print("(frame (\(position.x) \(position.y); \(size.width) \(size.height)))") + switch value { + case .empty: + break + case let .content(content): + printer.print("(content-seed \(content.seed.value))") + switch content.value { + case let .placeholder(id: identity): + printer.print("(placeholder \(identity))") + default: + // TOOD + break + } + default: + // TODO + break + } + printer.pop() + } + + fileprivate func printMinimally(into printer: inout SExpPrinter) { + printer.push("I:\(identity.value)") + switch value { + case .empty: + break + case let .content(content): + switch content.value { + case let .placeholder(id: identity): + printer.print("@\(identity))") + default: + // TOOD + break + } + default: + // TODO + break + } + printer.pop() + } +} + + +extension DisplayList: CustomStringConvertible { + public var description: String { + var printer = SExpPrinter(tag: "display-list", singleLine: false) + for item in items { + item.print(into: &printer) + } + return printer.end() + } + + package var minimalDescription: String { + var printer = SExpPrinter(tag: "DL", singleLine: true) + for item in items { + item.printMinimally(into: &printer) + } + return printer.end() + } +} +extension DisplayList.Item: CustomStringConvertible { + package var description: String { + var printer = SExpPrinter(tag: "display-list-item", singleLine: false) + print(into: &printer) + return printer.end() + } +} diff --git a/Sources/OpenSwiftUICore/Render/DisplayList.GraphicsRenderer.swift b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.GraphicsRenderer.swift similarity index 100% rename from Sources/OpenSwiftUICore/Render/DisplayList.GraphicsRenderer.swift rename to Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.GraphicsRenderer.swift diff --git a/Sources/OpenSwiftUICore/Render/DisplayList.ViewRenderer.swift b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.ViewRenderer.swift similarity index 100% rename from Sources/OpenSwiftUICore/Render/DisplayList.ViewRenderer.swift rename to Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.ViewRenderer.swift diff --git a/Sources/OpenSwiftUICore/Render/DisplayList.ViewUpdater.swift b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.ViewUpdater.swift similarity index 100% rename from Sources/OpenSwiftUICore/Render/DisplayList.ViewUpdater.swift rename to Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.ViewUpdater.swift diff --git a/Sources/OpenSwiftUICore/Render/DisplayList.swift b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.swift similarity index 95% rename from Sources/OpenSwiftUICore/Render/DisplayList.swift rename to Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.swift index 59dced7e..621cb65b 100644 --- a/Sources/OpenSwiftUICore/Render/DisplayList.swift +++ b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayList.swift @@ -63,15 +63,29 @@ package struct DisplayList: Equatable { } package init(_ item: Item) { - fatalError("TODO") + switch item.value { + case .empty: + items = [] + features = [] + properties = [] + default: + items = [item] + features = item.features + properties = item.properties + } } + // TO BE VERIFIED package init(_ items: [Item]) { - guard !items.isEmpty else { - self.init() - return + var features: Features = [] + var properties: Properties = [] + for item in items { + features.formUnion(item.features) + properties.formUnion(item.properties) } - fatalError("TODO") + self.items = items + self.features = features + self.properties = properties } package mutating func append(_ item: Item) { @@ -264,7 +278,7 @@ extension DisplayList { package static let screencaptureProhibited = Properties(rawValue: 1 << 7) } - package struct Key : PreferenceKey { + package struct Key: PreferenceKey { package static let _includesRemovedValues: Bool = true package static let defaultValue = DisplayList() package static func reduce(value: inout DisplayList, nextValue: () -> DisplayList) { diff --git a/Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayList_StableIdentity.swift similarity index 100% rename from Sources/OpenSwiftUICore/Render/DisplayList_StableIdentity.swift rename to Sources/OpenSwiftUICore/Render/DisplayList/DisplayList_StableIdentity.swift diff --git a/Tests/OpenSwiftUICoreTests/Render/DisplayList/DisplayList+StringTests.swift b/Tests/OpenSwiftUICoreTests/Render/DisplayList/DisplayList+StringTests.swift new file mode 100644 index 00000000..577fefa6 --- /dev/null +++ b/Tests/OpenSwiftUICoreTests/Render/DisplayList/DisplayList+StringTests.swift @@ -0,0 +1,65 @@ +// +// DisplayList+StringTests.swift +// OpenSwiftUICoreTests + +import OpenSwiftUICore +import Testing + +struct DisplayList_StringTests { + @Test + func plain() { + let emptyList = DisplayList() + #expect(emptyList.description == "(display-list)") + #expect(emptyList.minimalDescription == "(DL)") + } + + @Test + func emptyItem() { + let item = DisplayList.Item(.empty, frame: .zero, identity: .init(decodedValue: 1), version: .init(decodedValue: 0)) + let d = item.description + print(d) + + #expect(item.description == """ + (display-list-item + (item #:identity 1 #:version 0 + (frame (0.0 0.0; 0.0 0.0)))) + """) + + let list = DisplayList(item) + #expect(list.description == "(display-list)") + #expect(list.minimalDescription == "(DL)") + + let list2 = DisplayList([item]) + #expect(list2.description == """ + (display-list + (item #:identity 1 #:version 0 + (frame (0.0 0.0; 0.0 0.0)))) + """) + #expect(list2.minimalDescription == "(DL(I:1))") + } + + func placeholdItem() { + let item = DisplayList.Item(.content(.init(.placeholder(id: .init(decodedValue: 2)), seed: .init(decodedValue: 4))), frame: .zero, identity: .init(decodedValue: 1), version: .init(decodedValue: 0)) + let expectedDescription = """ + (display-list + (item #:identity 1 #:version 0 #:views true + (frame (0.0 0.0; 0.0 0.0)) + (content-seed 4) + (placeholder #2))) + """ + + let expectedMinimalDescription = """ + (DL(I:1 @#2)) + """ + + + let list = DisplayList(item) + #expect(list.description == expectedDescription) + #expect(list.minimalDescription == expectedMinimalDescription) + + let list2 = DisplayList([item]) + #expect(list2.description == expectedDescription) + #expect(list2.minimalDescription == expectedMinimalDescription) + } + +} diff --git a/Tests/OpenSwiftUICoreTests/Render/DisplayList_StableIdentityTests.swift b/Tests/OpenSwiftUICoreTests/Render/DisplayList/DisplayList_StableIdentityTests.swift similarity index 94% rename from Tests/OpenSwiftUICoreTests/Render/DisplayList_StableIdentityTests.swift rename to Tests/OpenSwiftUICoreTests/Render/DisplayList/DisplayList_StableIdentityTests.swift index 7be601da..144c302d 100644 --- a/Tests/OpenSwiftUICoreTests/Render/DisplayList_StableIdentityTests.swift +++ b/Tests/OpenSwiftUICoreTests/Render/DisplayList/DisplayList_StableIdentityTests.swift @@ -5,8 +5,6 @@ import OpenSwiftUICore import Testing -@_spi(Debug) import OpenGraphShims - struct DisplayList_StableIdentityTests { @Test func formUnion() {