-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix items not properly hidden prior to macOS 14
- Loading branch information
1 parent
449bf10
commit 684f371
Showing
8 changed files
with
149 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// HPMenuItem.swift | ||
// HeliPort | ||
// | ||
// Created by Bat.bat on 5/8/2024. | ||
// Copyright © 2024 OpenIntelWireless. All rights reserved. | ||
// | ||
|
||
/* | ||
* This program and the accompanying materials are licensed and made available | ||
* under the terms and conditions of the The 3-Clause BSD License | ||
* which accompanies this distribution. The full text of the license may be found at | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import Cocoa | ||
|
||
/// Use this class instead of `NSMenuItem` when applying a custom view | ||
class HPMenuItem: NSMenuItem { | ||
|
||
var highlightable: Bool = false | ||
|
||
convenience init(highlightable: Bool = false) { | ||
self.init() | ||
self.highlightable = highlightable | ||
} | ||
|
||
required init(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override init(title string: String, action selector: Selector?, keyEquivalent charCode: String) { | ||
super.init(title: string, action: selector, keyEquivalent: charCode) | ||
} | ||
|
||
override var isHidden: Bool { | ||
willSet { | ||
(self.view as? HidableMenuItemView)?.visible = !newValue | ||
} | ||
} | ||
|
||
override func _canBeHighlighted() -> Bool { | ||
return highlightable || super._canBeHighlighted() | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
HeliPort/Appearance/StatusMenu/MenuItemView/HidableMenuItemView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// HidableMenuItemView.swift | ||
// HeliPort | ||
// | ||
// Created by Bat.bat on 5/8/2024. | ||
// Copyright © 2024 OpenIntelWireless. All rights reserved. | ||
// | ||
|
||
/* | ||
* This program and the accompanying materials are licensed and made available | ||
* under the terms and conditions of the The 3-Clause BSD License | ||
* which accompanies this distribution. The full text of the license may be found at | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
class HidableMenuItemView: NSView { | ||
private let height: CGFloat | ||
private var heightConstraint: NSLayoutConstraint! | ||
|
||
var visible: Bool = true { | ||
willSet(visible) { | ||
// Manually adjust visibility for item views prior to macOS 14 | ||
if #unavailable(macOS 14) { | ||
isHidden = !visible | ||
heightConstraint.constant = visible ? height : 0 | ||
layoutSubtreeIfNeeded() | ||
} | ||
} | ||
} | ||
|
||
init(height: NSMenuItem.ItemHeight) { | ||
self.height = height.rawValue | ||
super.init(frame: .zero) | ||
|
||
translatesAutoresizingMaskIntoConstraints = false | ||
|
||
heightConstraint = heightAnchor.constraint(equalToConstant: height.rawValue) | ||
heightConstraint.priority = NSLayoutConstraint.Priority(rawValue: 1000) | ||
heightConstraint.isActive = true | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.