From cba36e70f8fb08e76cbd28c079359cc069b5023d Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Tue, 27 Jul 2021 19:05:02 +0200 Subject: [PATCH] fix: fixed switch buttons visibility on macOS 10.13 (#559) --- Kit/extensions.swift | 27 ++++++++++++++++----------- Stats/Supporting Files/Info.plist | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Kit/extensions.swift b/Kit/extensions.swift index 33e74691..531f07e0 100644 --- a/Kit/extensions.swift +++ b/Kit/extensions.swift @@ -226,36 +226,41 @@ public extension NSView { } func toggleTitleRow(frame: NSRect, title: String, action: Selector, state: Bool) -> NSView { - let row: NSView = NSView(frame: frame) + let row: NSStackView = NSStackView(frame: frame) + row.orientation = .horizontal + row.spacing = 0 + row.distribution = .fillProportionally + + let title: NSTextField = LabelField(frame: NSRect(x: 0, y: 0, width: 0, height: 0), title) + title.font = NSFont.systemFont(ofSize: 13, weight: .light) + title.textColor = .textColor + let state: NSControl.StateValue = state ? .on : .off - - let rowTitle: NSTextField = LabelField(frame: NSRect(x: 0, y: (row.frame.height - 16)/2, width: row.frame.width - 52, height: 17), title) - rowTitle.font = NSFont.systemFont(ofSize: 13, weight: .light) - rowTitle.textColor = .textColor - var toggle: NSControl = NSControl() if #available(OSX 10.15, *) { - let switchButton = NSSwitch(frame: NSRect(x: row.frame.width - 50, y: 0, width: 50, height: row.frame.height)) + let switchButton = NSSwitch(frame: NSRect(x: 0, y: 0, width: 50, height: row.frame.height)) switchButton.state = state switchButton.action = action switchButton.target = self toggle = switchButton } else { - let button: NSButton = NSButton(frame: NSRect(x: row.frame.width - 30, y: 0, width: 30, height: row.frame.height)) + let button: NSButton = NSButton(frame: NSRect(x: 0, y: 0, width: 20, height: row.frame.height)) + button.widthAnchor.constraint(equalToConstant: button.bounds.width).isActive = true button.setButtonType(.switch) button.state = state button.title = "" button.action = action button.isBordered = false - button.isTransparent = true + button.isTransparent = false button.target = self + button.wantsLayer = true toggle = button } - row.addSubview(toggle) - row.addSubview(rowTitle) + row.addArrangedSubview(title) + row.addArrangedSubview(toggle) row.widthAnchor.constraint(equalToConstant: row.bounds.width).isActive = true row.heightAnchor.constraint(equalToConstant: row.bounds.height).isActive = true diff --git a/Stats/Supporting Files/Info.plist b/Stats/Supporting Files/Info.plist index a2511745..5ceef5fb 100755 --- a/Stats/Supporting Files/Info.plist +++ b/Stats/Supporting Files/Info.plist @@ -17,7 +17,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 291 + 292 Description Simple macOS system monitor in your menu bar LSApplicationCategoryType