diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-02-11 13:37:20 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-02-11 13:37:20 +0100 |
| commit | 768e492ea13d8c0f62e0334c4c626db4596a66d8 (patch) | |
| tree | a6027ff28e371f90bfb1d22c576dbd36dd0a632d /Flat Bezel/FlatBezelCollectingSearchObjectView.swift | |
| parent | 285ac7c2364f90a6bfc7853e25ec7f592d2009bc (diff) | |
Port more files to swift
Diffstat (limited to 'Flat Bezel/FlatBezelCollectingSearchObjectView.swift')
| -rw-r--r-- | Flat Bezel/FlatBezelCollectingSearchObjectView.swift | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Flat Bezel/FlatBezelCollectingSearchObjectView.swift b/Flat Bezel/FlatBezelCollectingSearchObjectView.swift new file mode 100644 index 0000000..26586be --- /dev/null +++ b/Flat Bezel/FlatBezelCollectingSearchObjectView.swift @@ -0,0 +1,38 @@ +class FlatBezelCollectingSearchObjectView: QSCollectingSearchObjectView { + override static var cellClass : AnyClass? { + get { return BBObjectCell.self } + set { super.cellClass = newValue } + } + + override func draw(_ rect: NSRect) { + var frame = frame + + // These properties aren't available to Swift, so they need to be accessed in this way. + let collection = (value(forKey: "collection") as! NSMutableArray) + let collecting = (value(forKey: "collecting") as! Bool) + + let count = collection.count + if self.currentEditor() == nil && count != 0 { + frame.origin = NSZeroPoint + cell?.draw(withFrame: frame, in: self) + let iconSize = collectionSpace() != 0 ? collectionSpace() : 16 + let opacity = collecting ? 1.0 : 0.75 + let totalWidth = iconSize + 2 + for i in 0..<count { + let object = collection.object(at: i) as! QSObject + var icon = object.icon() + let size = NSMakeSize(16, 16) + icon?.size = size + let inRect = NSMakeRect( + frame.size.width - totalWidth * CGFloat(count - i), + frame.origin.y + 2, + iconSize, + iconSize + ) + icon?.draw(in: inRect, from: rectFromSize(size), operation: .sourceOver, fraction: opacity) + } + } else { + super.draw(rect) + } + } +} |