38 lines
1.0 KiB
Swift
38 lines
1.0 KiB
Swift
//
|
|
// ParentViewProtocol.swift
|
|
// VDS
|
|
//
|
|
// Created by Matt Bruce on 8/23/24.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
|
|
/// This is used in a View or Control to denote subviews of the ViewProtocol
|
|
/// type, more or less for composite views/controls.
|
|
public protocol ParentViewProtocol: ViewProtocol {
|
|
var children: [any ViewProtocol] { get }
|
|
}
|
|
|
|
extension ParentViewProtocol {
|
|
|
|
/// This will get all of the children for yourself as well as all
|
|
/// of the children within the full tree hierarchy.
|
|
/// - Returns: All children within the hierachy
|
|
public func getAllChildren() -> [any ViewProtocol] {
|
|
var allChildren = [any ViewProtocol]()
|
|
|
|
func traverse(view: any ViewProtocol) {
|
|
if let parentView = view as? any ParentViewProtocol {
|
|
for child in parentView.children {
|
|
allChildren.append(child)
|
|
traverse(view: child)
|
|
}
|
|
}
|
|
}
|
|
|
|
traverse(view: self)
|
|
return children
|
|
}
|
|
}
|