mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-17 15:21:50 +00:00
Add extensions to help finding private subviews
This commit is contained in:
29
macos/Sources/Helpers/NSView+Extension.swift
Normal file
29
macos/Sources/Helpers/NSView+Extension.swift
Normal file
@@ -0,0 +1,29 @@
|
||||
import AppKit
|
||||
|
||||
extension NSView {
|
||||
func firstSubview(withClassName name: String) -> NSView? {
|
||||
for subview in subviews {
|
||||
if String(describing: type(of: subview)) == name {
|
||||
return subview
|
||||
} else if let found = subview.firstSubview(withClassName: name) {
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func subviews(withClassName name: String) -> [NSView] {
|
||||
var result = [NSView]()
|
||||
|
||||
for subview in subviews {
|
||||
if String(describing: type(of: subview)) == name {
|
||||
result.append(subview)
|
||||
}
|
||||
|
||||
result += subview.subviews(withClassName: name)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user