fix: avoid crashing in rare cases

This commit is contained in:
lwouis
2024-10-11 11:59:16 +02:00
parent 8abb9b4358
commit 9980ec62fd
2 changed files with 17 additions and 11 deletions
+2
View File
@@ -138,6 +138,7 @@ They helped [localize the app](https://poeditor.com/join/project/8AOEZ0eAZE):
* Lcwhhh
* Lester
* Loïc
* Loic. peron
* LostInCompilation
* Lumaxis
* lwouis
@@ -197,6 +198,7 @@ They helped [localize the app](https://poeditor.com/join/project/8AOEZ0eAZE):
* shlomo
* Sippawit Thammawiset
* Sjur Moshagen
* Sjur.n. moshagen
* Stan Smits
* Stefan
* Svetoslav Stefanov
@@ -15,16 +15,20 @@ class PopupButtonLikeSystemSettings: NSPopUpButton {
}
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 = showsBorderOnlyWhileMouseInside
fakePopUpButton.sizeToFit()
return fakePopUpButton.intrinsicContentSize
if let selectedItem = selectedItem {
let fakePopUpButton = NSPopUpButton()
fakePopUpButton.addItem(withTitle: title)
fakePopUpButton.item(at: 0)!.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 = showsBorderOnlyWhileMouseInside
fakePopUpButton.sizeToFit()
return fakePopUpButton.intrinsicContentSize
} else {
return super.intrinsicContentSize
}
}
}