mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-11 05:05:23 +03:00
Fix z positions test
This commit is contained in:
parent
da870907a7
commit
149332e6e6
@ -13,27 +13,38 @@ class AnimationUtilsTests: XCTestCase {
|
||||
|
||||
func testIndex() {
|
||||
let rootGroup = Group()
|
||||
let a = Node()
|
||||
let a = Shape(form: Locus())
|
||||
rootGroup.contents.append(a)
|
||||
|
||||
let aGroup = Group()
|
||||
let b = Node()
|
||||
let c = Node()
|
||||
aGroup.contents.append(b)
|
||||
aGroup.contents.append(c)
|
||||
rootGroup.contents.append(aGroup)
|
||||
let bGroup = Group()
|
||||
let c = Shape(form: Locus())
|
||||
let d = Shape(form: Locus())
|
||||
bGroup.contents.append(c)
|
||||
bGroup.contents.append(d)
|
||||
rootGroup.contents.append(bGroup)
|
||||
|
||||
let d = Node()
|
||||
let e = Node()
|
||||
rootGroup.contents.append(d)
|
||||
let e = Shape(form: Locus())
|
||||
let f = Shape(form: Locus())
|
||||
rootGroup.contents.append(e)
|
||||
rootGroup.contents.append(f)
|
||||
|
||||
let view = MacawView()
|
||||
view.node = rootGroup
|
||||
view.draw(CGRect(x: 0, y: 0, width: 100, height: 100))
|
||||
let rootRenderer = view.renderer as? GroupRenderer
|
||||
let aRenderer = rootRenderer?.renderers[0]
|
||||
let bRenderer = rootRenderer?.renderers[1] as? GroupRenderer
|
||||
let cRenderer = bRenderer?.renderers[0]
|
||||
let dRenderer = bRenderer?.renderers[1]
|
||||
let eRenderer = rootRenderer?.renderers[2]
|
||||
let fRenderer = rootRenderer?.renderers[3]
|
||||
|
||||
XCTAssert(AnimationUtils.absoluteIndex(rootGroup) == 0)
|
||||
XCTAssert(AnimationUtils.absoluteIndex(a) == 1)
|
||||
XCTAssert(AnimationUtils.absoluteIndex(aGroup) == 2)
|
||||
XCTAssert(AnimationUtils.absoluteIndex(b) == 3)
|
||||
XCTAssert(AnimationUtils.absoluteIndex(c) == 4 )
|
||||
XCTAssert(AnimationUtils.absoluteIndex(d) == 5 )
|
||||
XCTAssert(AnimationUtils.absoluteIndex(e) == 6 )
|
||||
XCTAssert(rootRenderer?.zPosition == 0)
|
||||
XCTAssert(aRenderer?.zPosition == 1)
|
||||
XCTAssert(bRenderer?.zPosition == 2)
|
||||
XCTAssert(cRenderer?.zPosition == 3)
|
||||
XCTAssert(dRenderer?.zPosition == 4 )
|
||||
XCTAssert(eRenderer?.zPosition == 5 )
|
||||
XCTAssert(fRenderer?.zPosition == 6 )
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class AnimationCache {
|
||||
return ShapeLayer()
|
||||
}
|
||||
|
||||
if let cachedLayer = layerCache[renderer] {
|
||||
if let cachedLayer = layerCache[renderer] {
|
||||
cachedLayer.linksCounter += 1
|
||||
return cachedLayer.layer
|
||||
}
|
||||
@ -148,7 +148,7 @@ class AnimationCache {
|
||||
|
||||
func isAnimating(_ node: Node) -> Bool {
|
||||
|
||||
let renderer = layerCache.keys.filter{ $0.node() === node }.first
|
||||
let renderer = layerCache.keys.filter { $0.node() === node }.first
|
||||
if let renderer = renderer, let _ = layerCache[renderer] {
|
||||
return true
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ enum ColoringMode {
|
||||
case rgb, greyscale, alphaOnly
|
||||
}
|
||||
|
||||
class NodeRenderer{
|
||||
class NodeRenderer {
|
||||
|
||||
weak var view: MView?
|
||||
weak var parentRenderer: NodeRenderer?
|
||||
@ -72,7 +72,7 @@ class NodeRenderer{
|
||||
|
||||
open func dispose() {
|
||||
removeObservers()
|
||||
node()?.animationObservers = node()?.animationObservers.filter{ !($0 as? NodeRenderer === self) } ?? []
|
||||
node()?.animationObservers = node()?.animationObservers.filter { !($0 as? NodeRenderer === self) } ?? []
|
||||
}
|
||||
|
||||
open func node() -> Node? {
|
||||
|
@ -196,13 +196,16 @@ open class MacawView: MView, MGestureRecognizerDelegate {
|
||||
renderer.render(in: ctx, force: false, opacity: node.opacity)
|
||||
}
|
||||
|
||||
private func calculateZPosition(_ nodeRenderer: NodeRenderer?, currentIndex: Int = 0) {
|
||||
private func calculateZPosition(_ nodeRenderer: NodeRenderer?, currentIndex: Int = 0) -> Int {
|
||||
nodeRenderer?.zPosition = currentIndex
|
||||
if let groupRenderer = nodeRenderer as? GroupRenderer {
|
||||
for (i, child) in groupRenderer.renderers.enumerated() {
|
||||
calculateZPosition(child, currentIndex: currentIndex + i + 1)
|
||||
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? {
|
||||
|
Loading…
Reference in New Issue
Block a user