feat: added separator option to the combined view (#2215)

This commit is contained in:
Serhiy Mytrovtsiy
2024-12-09 18:22:03 +01:00
parent 1925ce423a
commit 720e0ac328
2 changed files with 25 additions and 0 deletions

View File

@@ -23,6 +23,9 @@ internal class CombinedView: NSObject, NSGestureRecognizerDelegate {
private var spacing: CGFloat {
CGFloat(Int(Store.shared.string(key: "CombinedModules_spacing", defaultValue: "")) ?? 0)
}
private var separator: Bool {
Store.shared.bool(key: "CombinedModules_separator", defaultValue: false)
}
private var activeModules: [Module] {
modules.filter({ $0.enabled }).sorted(by: { $0.combinedPosition < $1.combinedPosition })
@@ -115,6 +118,15 @@ internal class CombinedView: NSObject, NSGestureRecognizerDelegate {
self.view.subviews[i].setFrameOrigin(NSPoint(x: w, y: 0))
w += m.menuBar.view.frame.width + self.spacing
i += 1
if self.separator && i < self.activeModules.count {
let separator = NSView(frame: NSRect(x: w, y: 3, width: 1, height: Constants.Widget.height-6))
separator.wantsLayer = true
separator.layer?.backgroundColor = (separator.isDarkMode ? NSColor.black : NSColor.white).cgColor
self.view.addSubview(separator)
w += 3 + self.spacing
i += 1
}
}
self.view.setFrameSize(NSSize(width: w, height: self.view.frame.height))
self.menuBarItem?.length = w