Skip to content

Commit

Permalink
fix: fixed switch buttons visibility on macOS 10.13 (exelban#559)
Browse files Browse the repository at this point in the history
  • Loading branch information
exelban authored and gmcinalli committed Feb 28, 2022
1 parent 4f37ef9 commit 238c2f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions Kit/extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 state: NSControl.StateValue = state ? .on : .off
let row: NSStackView = NSStackView(frame: frame)
row.orientation = .horizontal
row.spacing = 0
row.distribution = .fillProportionally

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
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
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
Expand Down
2 changes: 1 addition & 1 deletion Stats/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>291</string>
<string>292</string>
<key>Description</key>
<string>Simple macOS system monitor in your menu bar</string>
<key>LSApplicationCategoryType</key>
Expand Down

0 comments on commit 238c2f8

Please sign in to comment.