-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
_ShapeView
and background
modifiers support to Fiber renderers (
#491) * Initial Reconciler using visitor pattern * Preliminary static HTML renderer using the new reconciler * Add environment * Initial DOM renderer * Nearly-working and simplified reconciler * Working reconciler for HTML/DOM renderers * Rename files, and split code across files * Add some documentation and refinements * Remove GraphRendererTests * Initial layout engine (only implemented for the TestRenderer) * Layout engine for the DOM renderer * Refined layout pass * Revise positioning and restoration of position styles on .update * Re-add Optional.body for StackReconciler-based renderers * Add text measurement * Add spacing to StackLayout * Add benchmarks to compare the stack/fiber reconcilers * Fix some issues created for the StackReconciler, and add update benchmarks * Add BenchmarkState.measure to only calculate the time to update * Fix hang in update shallow benchmark * Fix build errors * Address build issues * Remove File.swift headers * Rename Element -> FiberElement and Element.Data -> FiberElement.Content * Add doc comment explaining unowned usage * Add doc comments explaining implicitly unwrapped optionals * Attempt to use Swift instead of JS for applying mutations * Fix issue with not applying updates to DOMFiberElement * Add comment explaining manual implementation of Hashable for PropertyInfo * Fix linter issues * Remove dynamicMember label from subscript * Re-enable carton test * Attempt GTK fix * Add option to disable layout in the FiberReconciler * Re-enable TokamakDemo with StackReconciler * Restore CI config * Restore CI config * Add file headers and cleanup structure * Add 'px' to font-size in test outputs * Remove extra newlines * Keep track of 'elementChildren' so children are positioned in the correct order * Use a ViewVisitor to pass the correct View type to the proposeSize function * Add support for view modifiers * Add frame modifier to demonstrate modifiers * Fix TestRenderer * Remove unused property * Fix doc comment * Fix linter issues and refactor slightly * Fix benchmark builds * Attempt to fix benchmarks * Fix sibling layout issues * Restore original demo * Support overriding visit function in renderer and _ShapeView drawing * Support background modifier * Resolve reconciler issues due to Optionals and elementIndex being set at wrong phase * Remove Brewfile.lock.json * Attempt to fix rendering tests * Formatting nits * Fix Gradient rendering Co-authored-by: Max Desiatov <max@desiatov.com>
- Loading branch information
1 parent
6e2ccf7
commit c935744
Showing
22 changed files
with
666 additions
and
203 deletions.
There are no files selected for viewing
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
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
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
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
85 changes: 85 additions & 0 deletions
85
Sources/TokamakCore/Fiber/Layout/BackgroundLayoutComputer.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,85 @@ | ||
// Copyright 2021 Tokamak contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Created by Carson Katri on 5/24/22. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A `LayoutComputer` that constrains a background to a foreground. | ||
final class BackgroundLayoutComputer: LayoutComputer { | ||
let proposedSize: CGSize | ||
let alignment: Alignment | ||
|
||
init(proposedSize: CGSize, alignment: Alignment) { | ||
self.proposedSize = proposedSize | ||
self.alignment = alignment | ||
} | ||
|
||
func proposeSize<V>(for child: V, at index: Int, in context: LayoutContext) -> CGSize | ||
where V: View | ||
{ | ||
if index == 0 { | ||
// The foreground can pick their size. | ||
return proposedSize | ||
} else { | ||
// The background is constrained to the foreground. | ||
return context.children.first?.dimensions.size ?? .zero | ||
} | ||
} | ||
|
||
func position(_ child: LayoutContext.Child, in context: LayoutContext) -> CGPoint { | ||
let foregroundSize = ViewDimensions( | ||
size: .init( | ||
width: context.children.first?.dimensions.width ?? 0, | ||
height: context.children.first?.dimensions.height ?? 0 | ||
), | ||
alignmentGuides: [:] | ||
) | ||
return .init( | ||
x: foregroundSize[alignment.horizontal] - child.dimensions[alignment.horizontal], | ||
y: foregroundSize[alignment.vertical] - child.dimensions[alignment.vertical] | ||
) | ||
} | ||
|
||
func requestSize(in context: LayoutContext) -> CGSize { | ||
let childSize = context.children.reduce(CGSize.zero) { | ||
.init( | ||
width: max($0.width, $1.dimensions.width), | ||
height: max($0.height, $1.dimensions.height) | ||
) | ||
} | ||
return .init(width: childSize.width, height: childSize.height) | ||
} | ||
} | ||
|
||
public extension _BackgroundLayout { | ||
static func _makeView(_ inputs: ViewInputs<Self>) -> ViewOutputs { | ||
.init( | ||
inputs: inputs, | ||
layoutComputer: { | ||
BackgroundLayoutComputer(proposedSize: $0, alignment: inputs.content.alignment) | ||
} | ||
) | ||
} | ||
} | ||
|
||
public extension _BackgroundStyleModifier { | ||
static func _makeView(_ inputs: ViewInputs<Self>) -> ViewOutputs { | ||
.init( | ||
inputs: inputs, | ||
layoutComputer: { BackgroundLayoutComputer(proposedSize: $0, alignment: .center) } | ||
) | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.