mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 05:05:23 +03:00
Fix renderers' z positions
a
This commit is contained in:
parent
e30a1f1fc4
commit
52dc2d9bc8
@ -68,6 +68,12 @@ class GroupRenderer: NodeRenderer {
|
||||
}) {
|
||||
renderers = updatedRenderers
|
||||
}
|
||||
|
||||
var parent: NodeRenderer = self
|
||||
while let parentRenderer = parent.parentRenderer {
|
||||
parent = parentRenderer
|
||||
}
|
||||
parent.calculateZPositionRecursively()
|
||||
}
|
||||
|
||||
override func replaceNode(with replacementNode: Node) {
|
||||
|
@ -282,6 +282,10 @@ class NodeRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
func calculateZPositionRecursively() {
|
||||
calculateZPosition(self)
|
||||
}
|
||||
|
||||
private func applyClip(in context: CGContext) {
|
||||
guard let node = node() else {
|
||||
return
|
||||
@ -358,3 +362,17 @@ extension NodeRenderer: AnimationObserver {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@discardableResult fileprivate func calculateZPosition(_ nodeRenderer: NodeRenderer?, currentIndex: Int = 0) -> Int {
|
||||
nodeRenderer?.zPosition = currentIndex
|
||||
let tag = nodeRenderer?.node()?.tag.first
|
||||
if let groupRenderer = nodeRenderer as? GroupRenderer {
|
||||
var i = currentIndex + 1
|
||||
for child in groupRenderer.renderers {
|
||||
let tag = child.node()?.tag.first
|
||||
i = calculateZPosition(child, currentIndex: i)
|
||||
}
|
||||
return i
|
||||
}
|
||||
return currentIndex + 1
|
||||
}
|
||||
|
@ -178,8 +178,6 @@ open class MacawView: MView, MGestureRecognizerDelegate {
|
||||
}
|
||||
|
||||
override open func draw(_ rect: CGRect) {
|
||||
calculateZPosition(renderer)
|
||||
|
||||
context.cgContext = MGraphicsGetCurrentContext()
|
||||
guard let ctx = context.cgContext else {
|
||||
return
|
||||
@ -192,22 +190,11 @@ open class MacawView: MView, MGestureRecognizerDelegate {
|
||||
guard let renderer = renderer else {
|
||||
return
|
||||
}
|
||||
renderer.calculateZPositionRecursively()
|
||||
ctx.concatenate(layoutHelper.getTransform(renderer, contentLayout, bounds.size.toMacaw()))
|
||||
renderer.render(in: ctx, force: false, opacity: node.opacity)
|
||||
}
|
||||
|
||||
@discardableResult private func calculateZPosition(_ nodeRenderer: NodeRenderer?, currentIndex: Int = 0) -> Int {
|
||||
nodeRenderer?.zPosition = currentIndex
|
||||
if let groupRenderer = nodeRenderer as? GroupRenderer {
|
||||
var i = currentIndex + 1
|
||||
for child in groupRenderer.renderers {
|
||||
i = calculateZPosition(child, currentIndex: i)
|
||||
}
|
||||
return i
|
||||
}
|
||||
return currentIndex + 1
|
||||
}
|
||||
|
||||
public final func findNodeAt(location: CGPoint) -> Node? {
|
||||
guard let ctx = context.cgContext else {
|
||||
return .none
|
||||
|
Loading…
Reference in New Issue
Block a user