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

Custom Layout Engine for Fiber Reconciler #472

Merged
merged 73 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
84018db
Initial Reconciler using visitor pattern
carson-katri Feb 6, 2022
aa8c4dd
Preliminary static HTML renderer using the new reconciler
carson-katri Feb 6, 2022
67b3509
Add environment
carson-katri Feb 7, 2022
7f96bc1
Initial DOM renderer
carson-katri Feb 7, 2022
4ea2247
Nearly-working and simplified reconciler
carson-katri Feb 11, 2022
026f00b
Working reconciler for HTML/DOM renderers
carson-katri Feb 15, 2022
e340ed5
Rename files, and split code across files
carson-katri Feb 15, 2022
885ba06
Add some documentation and refinements
carson-katri Feb 16, 2022
dd8a2eb
Remove GraphRendererTests
carson-katri Feb 16, 2022
88f689f
Initial layout engine (only implemented for the TestRenderer)
carson-katri Feb 19, 2022
a9af988
Layout engine for the DOM renderer
carson-katri Feb 21, 2022
26ce229
Refined layout pass
carson-katri Mar 3, 2022
2891e6b
Revise positioning and restoration of position styles on .update
carson-katri Mar 3, 2022
055c826
Re-add Optional.body for StackReconciler-based renderers
carson-katri Mar 3, 2022
7b98447
Merge branch 'fiber/core' of https://github.com/TokamakUI/Tokamak int…
carson-katri Mar 7, 2022
9902ace
Add text measurement
carson-katri Mar 7, 2022
d576798
Add spacing to StackLayout
carson-katri Mar 7, 2022
c457dce
Add benchmarks to compare the stack/fiber reconcilers
carson-katri Apr 5, 2022
be6aa89
Fix some issues created for the StackReconciler, and add update bench…
carson-katri Apr 5, 2022
ac5c110
Add BenchmarkState.measure to only calculate the time to update
carson-katri Apr 6, 2022
0d82cec
Fix hang in update shallow benchmark
carson-katri Apr 6, 2022
42c7c01
Merge branch 'main' into fiber/core
MaxDesiatov Apr 10, 2022
7ef9bed
Fix build errors
MaxDesiatov Apr 10, 2022
34cd9d7
Address build issues
MaxDesiatov Apr 10, 2022
6a846f4
Merge branch 'main' into fiber/core
MaxDesiatov May 12, 2022
7d705eb
Merge branch 'main' of https://github.com/TokamakUI/Tokamak into fibe…
carson-katri May 19, 2022
a70a938
Remove File.swift headers
carson-katri May 19, 2022
485da76
Rename Element -> FiberElement and Element.Data -> FiberElement.Content
carson-katri May 20, 2022
81deb5a
Add doc comment explaining unowned usage
carson-katri May 20, 2022
74ee853
Add doc comments explaining implicitly unwrapped optionals
carson-katri May 21, 2022
8a8c075
Attempt to use Swift instead of JS for applying mutations
carson-katri May 22, 2022
b7cc779
Fix issue with not applying updates to DOMFiberElement
carson-katri May 22, 2022
78d0bf5
Add comment explaining manual implementation of Hashable for Property…
carson-katri May 22, 2022
4becea3
Fix linter issues
carson-katri May 22, 2022
8c9141b
Remove dynamicMember label from subscript
carson-katri May 23, 2022
33f0e67
Re-enable carton test
carson-katri May 23, 2022
316468c
Merge fiber/core
carson-katri May 23, 2022
4d86f89
Attempt GTK fix
carson-katri May 23, 2022
3189e77
Add option to disable layout in the FiberReconciler
carson-katri May 23, 2022
104f14f
Re-enable TokamakDemo with StackReconciler
carson-katri May 23, 2022
0d0a9c7
Merge fiber/core
carson-katri May 24, 2022
836ac36
Merge main (take ours)
carson-katri May 24, 2022
389b3e8
Restore CI config
carson-katri May 24, 2022
a20d94b
Restore CI config
carson-katri May 24, 2022
05d5a24
Add file headers and cleanup structure
carson-katri May 24, 2022
f628cba
Merge branch 'main' of github.com:tokamakui/tokamak into fiber/layout
carson-katri May 26, 2022
d507848
Add 'px' to font-size in test outputs
carson-katri May 26, 2022
65e78e8
Remove extra newlines
carson-katri May 26, 2022
f94d733
Keep track of 'elementChildren' so children are positioned in the cor…
carson-katri May 27, 2022
001cd4b
Use a ViewVisitor to pass the correct View type to the proposeSize fu…
carson-katri May 27, 2022
f89d24d
Add support for view modifiers
carson-katri May 28, 2022
10368b1
Add frame modifier to demonstrate modifiers
carson-katri May 28, 2022
f926fbe
Fix TestRenderer
carson-katri May 28, 2022
4d96217
Remove unused property
carson-katri May 28, 2022
aeb5983
Fix doc comment
carson-katri May 28, 2022
3265b74
Fix linter issues and refactor slightly
carson-katri May 28, 2022
b6c5d8e
Fix benchmark builds
carson-katri May 28, 2022
8ca135c
Attempt to fix benchmarks
carson-katri May 28, 2022
8779df6
Fix sibling layout issues
carson-katri May 28, 2022
90e1c5d
Restore original demo
carson-katri May 28, 2022
0cf20a0
Address review comments
carson-katri May 29, 2022
8a96570
Remove maxAxis and fitAxis properties
carson-katri May 30, 2022
ca7fb6b
Use switch instead of ternary operators
carson-katri May 30, 2022
e90f1a1
Add more documentation to layout steps
carson-katri May 30, 2022
a0b71d3
Resolve reconciler issue due to alternate child not being cleared/rel…
carson-katri May 30, 2022
8cd570a
Apply suggestions from code review
carson-katri May 30, 2022
c0567d4
Reuse Text resolution code.
carson-katri May 30, 2022
7a56023
Merge branch 'fiber/layout' of github.com:tokamakui/tokamak into fibe…
carson-katri May 30, 2022
e9671c3
Add more documentation
carson-katri May 30, 2022
3c92483
Fix typo
carson-katri May 30, 2022
cfaf990
Use structs for LayoutComputers
carson-katri May 30, 2022
cff213d
Update AlignmentID demo
carson-katri May 30, 2022
cdb5df2
Fix weird formatting
carson-katri May 30, 2022
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
20 changes: 20 additions & 0 deletions Sources/TokamakCore/Fiber/AlignmentID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,27 @@

import Foundation

/// Used identify an alignment guide.
///
/// Typically, you would define an alignment guide inside
/// an extension on `HorizontalAlignment` or `VerticalAlignment`:
///
/// extension HorizontalAlignment {
/// private enum MyAlignmentGuide: AlignmentID {
/// static func defaultValue(in context: ViewDimensions) -> CGFloat {
/// return 10.0
/// }
/// }
/// public static let myAlignmentGuide = Self(MyAlignmentGuide.self)
/// }
///
/// Which you can then use with the `alignmentGuide` modifier:
///
/// Text("Hello, world!")
/// .alignmentGuide(.myAlignmentGuide) { $0[.trailing] - 3 }
MaxDesiatov marked this conversation as resolved.
Show resolved Hide resolved
public protocol AlignmentID {
carson-katri marked this conversation as resolved.
Show resolved Hide resolved
/// The default value for this alignment guide
/// when not set via the `alignmentGuide` modifier.
static func defaultValue(in context: ViewDimensions) -> CGFloat
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/TokamakCore/Fiber/Fiber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import Foundation

@_spi(TokamakCore)
@_spi(TokamakCore)
public extension FiberReconciler {
/// A manager for a single `View`.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import Foundation

/// A `LayoutComputer` that takes the size of its children.
/// A `LayoutComputer` that shrinks to the size of its children.
final class ShrinkWrapLayoutComputer: LayoutComputer {
let proposedSize: CGSize

Expand Down
6 changes: 6 additions & 0 deletions Sources/TokamakCore/Fiber/Layout/StackLayoutComputer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

import Foundation

/// A `LayoutComputer` that aligns `Views` along a specified `Axis`
/// with a given spacing and alignment.
///
/// The specified main `Axis` will fit to the combined width/height (depending on the axis)
/// of the children.
/// The cross axis will fit to the child with the largest height/width.
final class StackLayoutComputer: LayoutComputer {
carson-katri marked this conversation as resolved.
Show resolved Hide resolved
let proposedSize: CGSize
let axis: Axis
Expand Down
14 changes: 7 additions & 7 deletions Sources/TokamakCore/Fiber/ViewGeometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@
import Foundation

public struct ViewGeometry: Equatable {
@_spi(TokamakCore)
@_spi(TokamakCore)
public let origin: ViewOrigin

@_spi(TokamakCore)
@_spi(TokamakCore)
public let dimensions: ViewDimensions
}

/// The position of the `View` relative to its parent.
public struct ViewOrigin: Equatable {
@_spi(TokamakCore)
@_spi(TokamakCore)
public let origin: CGPoint

@_spi(TokamakCore)
@_spi(TokamakCore)
public var x: CGFloat { origin.x }
@_spi(TokamakCore)
@_spi(TokamakCore)
public var y: CGFloat { origin.y }
}

public struct ViewDimensions: Equatable {
@_spi(TokamakCore)
@_spi(TokamakCore)
public let size: CGSize

@_spi(TokamakCore)
@_spi(TokamakCore)
public let alignmentGuides: [ObjectIdentifier: CGFloat]

public var width: CGFloat { size.width }
Expand Down
4 changes: 2 additions & 2 deletions Sources/TokamakDOM/DOMFiberRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import Foundation
import JavaScriptKit
@_spi(TokamakCore)
@_spi(TokamakCore)
import TokamakCore
@_spi(TokamakStaticHTML)
@_spi(TokamakStaticHTML)
import TokamakStaticHTML

public final class DOMElement: FiberElement {
Expand Down
2 changes: 1 addition & 1 deletion Sources/TokamakStaticHTML/Modifiers/LayoutModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extension _FrameLayout: DOMViewModifier {
}
}

@_spi(TokamakStaticHTML)
@_spi(TokamakStaticHTML)
extension _FrameLayout: HTMLConvertible {
public var tag: String { "div" }
public func attributes(shouldLayout: Bool) -> [HTMLAttribute: String] {
Expand Down
2 changes: 1 addition & 1 deletion Sources/TokamakStaticHTML/StaticHTMLFiberRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//

import Foundation
@_spi(TokamakCore)
@_spi(TokamakCore)
import TokamakCore

public final class HTMLElement: FiberElement, CustomStringConvertible {
Expand Down
21 changes: 1 addition & 20 deletions Sources/TokamakStaticHTML/Views/Text/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,7 @@ extension Text: AnyHTML {

@_spi(TokamakStaticHTML) extension Text: HTMLConvertible {
@_spi(TokamakStaticHTML) public var innerHTML: String? {
let proxy = _TextProxy(self)
let innerHTML: String
switch proxy.storage {
case let .verbatim(text):
innerHTML = proxy.environment.domTextSanitizer(text)
case let .segmentedText(segments):
innerHTML = segments
.map {
TextSpan(
content: proxy.environment.domTextSanitizer($0.0.rawText),
attributes: Self.attributes(
from: $0.1,
environment: proxy.environment
)
)
.outerHTML(shouldSortAttributes: false, children: [])
}
.reduce("", +)
}
return innerHTML.replacingOccurrences(of: "\n", with: "<br />")
innerHTML(shouldSortAttributes: false)
}

public func attributes(shouldLayout: Bool) -> [HTMLAttribute: String] {
Expand Down