fix: imitate system-settings dropdown more

This commit is contained in:
lwouis committed 2024-08-14 15:19:10 +02:00
1 parent a3f02e4963
commit 71eb7a6d40
4 files changed
+37 -2

No files matched your search

+4
View File
@@ -78,6 +78,7 @@
BF0C828D53D429C2B8B22391 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C883EBA8FDA9CB61C91FD /* Localizable.strings */; };
BF0C829583ED47E458528F3A /* accessibility@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C889529FF19620EDAC295 /* accessibility@2x.png */; };
BF0C832C5BF4C8E9C95F7767 /* MissionControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C82E4DE5A28800F1DA6E6 /* MissionControl.swift */; };
BF0C83578F7292F307E30751 /* PopupButtonLikeSystemSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF0C8A479D2B7FB80531F037 /* PopupButtonLikeSystemSettings.swift */; };
BF0C8382435C0087E131BD83 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8A900DA32A7F62457CC2 /* InfoPlist.strings */; };
BF0C83AB0186CC48FADF66A7 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = BF0C847B2D68EACFAC1B06D1 /* Localizable.strings */; };
BF0C83E902F75A97E8FD374A /* menubar-2@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = BF0C8D3333653ACAEF730DD8 /* menubar-2@2x.png */; };
@@ -347,6 +348,7 @@
BF0C899605B39AB4EE0E8EB8 /* icon_512x512.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon_512x512.png; sourceTree = "<group>"; };
BF0C89A541FBEA23E7CB1D94 /* lb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = lb; path = Localizable.strings; sourceTree = "<group>"; };
BF0C89F6EA16DD7322626E20 /* FUNDING.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.yaml; path = FUNDING.yml; sourceTree = "<group>"; };
BF0C8A479D2B7FB80531F037 /* PopupButtonLikeSystemSettings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopupButtonLikeSystemSettings.swift; sourceTree = "<group>"; };
BF0C8A50151A4EF88E494357 /* da */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = da; path = InfoPlist.strings; sourceTree = "<group>"; };
BF0C8AF53097C87EDC6F5FA6 /* nb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = nb; path = Localizable.strings; sourceTree = "<group>"; };
BF0C8B15FFB262ECC54B5AA4 /* sl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = sl; path = InfoPlist.strings; sourceTree = "<group>"; };
@@ -1104,6 +1106,7 @@
BF0C8B2C057099EDABE46779 /* Button.swift */,
BF0C8343C1F6FCA82552DCB7 /* TableView.swift */,
1C961FB3DCF4906FEEF4A23D /* TableGroupView.swift */,
BF0C8A479D2B7FB80531F037 /* PopupButtonLikeSystemSettings.swift */,
);
path = "generic-components";
sourceTree = "<group>";
@@ -1991,6 +1994,7 @@
BF0C86BA26EFA59DEE24C70B /* Support.md in Sources */,
1C96108A0CB2565233FE100B /* TableGroupView.swift in Sources */,
1C9618872DD3863A8EFE8414 /* Appearance.swift in Sources */,
BF0C83578F7292F307E30751 /* PopupButtonLikeSystemSettings.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
+1
View File
@@ -84,6 +84,7 @@ class App: AppCenterApplication, NSApplicationDelegate {
self.preloadWindows()
#if DEBUG
self.showPreferencesWindow()
self.preferencesWindow.selectTab("controls")
#endif
}
}
@@ -0,0 +1,31 @@
import Cocoa
class PopupButtonLikeSystemSettings: NSPopUpButton {
convenience init() {
self.init(frame: .zero)
translatesAutoresizingMaskIntoConstraints = false
showsBorderOnlyWhileMouseInside = true
// isBordered = false
// setButtonType(.switch)
// alignment = .right
// let cell = cell! as! NSPopUpButtonCell
// onAction = { _ in self.sizeToFit() }
// cell.bezelStyle = .regularSquare
// cell.arrowPosition = .arrowAtBottom
// cell.imagePosition = .imageOverlaps
}
override var intrinsicContentSize: NSSize {
let fakePopUpButton = NSPopUpButton()
fakePopUpButton.addItem(withTitle: title)
fakePopUpButton.selectedItem!.image = selectedItem!.image
let fakeCell = fakePopUpButton.cell! as! NSPopUpButtonCell
let currentCell = cell! as! NSPopUpButtonCell
fakeCell.bezelStyle = currentCell.bezelStyle
fakeCell.arrowPosition = currentCell.arrowPosition
fakeCell.imagePosition = currentCell.imagePosition
// fakePopUpButton.showsBorderOnlyWhileMouseInside = true
fakePopUpButton.sizeToFit()
return fakePopUpButton.intrinsicContentSize
}
}
@@ -254,8 +254,7 @@ class LabelAndControl: NSObject {
}
static func dropdown_(_ rawName: String, _ macroPreferences: [MacroPreference]) -> NSPopUpButton {
let popUp = NSPopUpButton()
popUp.translatesAutoresizingMaskIntoConstraints = false
let popUp = PopupButtonLikeSystemSettings()
popUp.addItems(withTitles: macroPreferences.map { $0.localizedString })
popUp.selectItem(at: defaults.int(rawName))
return popUp