-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic display list + String support (#146)
- Loading branch information
Showing
8 changed files
with
176 additions
and
8 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
Sources/OpenSwiftUICore/Render/DisplayList/DisplayList+String.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
65 changes: 65 additions & 0 deletions
65
Tests/OpenSwiftUICoreTests/Render/DisplayList/DisplayList+StringTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters