Skip to content

Commit

Permalink
Reverse layer children drawing order
Browse files Browse the repository at this point in the history
  • Loading branch information
rensbreur committed Jan 29, 2023
1 parent 98219cc commit c2c9198
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Sources/SwiftTUI/Drawing/Rendering/Layer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Layer {
var backgroundColor: Color? = nil

// Draw children
for child in children {
for child in children.reversed() {
guard child.frame.contains(position) else { continue }
let position = position - child.frame.position
if let cell = child.cell(at: position) {
Expand All @@ -65,19 +65,23 @@ class Layer {
inverted = cell.inverted
foregroundColor = cell.foregroundColor
}
if let color = cell.backgroundColor { backgroundColor = color }
if char != nil && backgroundColor != nil { break }
if let color = cell.backgroundColor {
backgroundColor = color
break
}
}
}

// Draw layer content as background
if (char == nil || backgroundColor == nil), let cell = content?.cell(at: position) {
if let cell = content?.cell(at: position) {
if char == nil {
char = cell.char
inverted = cell.inverted
foregroundColor = cell.foregroundColor
}
if backgroundColor == nil, let color = cell.backgroundColor { backgroundColor = color }
if backgroundColor == nil {
backgroundColor = cell.backgroundColor
}
}

return char.map { Cell(char: $0, foregroundColor: foregroundColor ?? .default, backgroundColor: backgroundColor, inverted: inverted) }
Expand Down

0 comments on commit c2c9198

Please sign in to comment.