ctlCandUniv // Fixes the corpse_notify issue on macOS 10.x.
This commit is contained in:
parent
85c8c3b275
commit
958308b841
|
@ -439,17 +439,15 @@ public class ctlCandidateUniversal: ctlCandidate {
|
||||||
|
|
||||||
// MARK: Add Page Counter
|
// MARK: Add Page Counter
|
||||||
|
|
||||||
contentRect.size = NSSize(width: 40.0, height: 20.0)
|
contentRect = NSRect(x: 128.0, y: 128.0, width: 48.0, height: 20.0)
|
||||||
pageCounterLabel = .init(frame: contentRect)
|
pageCounterLabel = .init(frame: contentRect)
|
||||||
|
NSColor.controlBackgroundColor.setFill()
|
||||||
|
NSBezierPath.fill(pageCounterLabel.bounds)
|
||||||
pageCounterLabel.isEditable = false
|
pageCounterLabel.isEditable = false
|
||||||
pageCounterLabel.isSelectable = false
|
pageCounterLabel.isSelectable = false
|
||||||
pageCounterLabel.isBezeled = false
|
pageCounterLabel.isBezeled = false
|
||||||
pageCounterLabel.textColor = NSColor(
|
pageCounterLabel.attributedStringValue = NSMutableAttributedString(
|
||||||
red: 0.86, green: 0.86, blue: 0.86, alpha: 1.00
|
string: " ", attributes: buttonAttribute
|
||||||
)
|
|
||||||
pageCounterLabel.drawsBackground = true
|
|
||||||
pageCounterLabel.backgroundColor = NSColor(
|
|
||||||
red: 0.18, green: 0.18, blue: 0.18, alpha: 1.00
|
|
||||||
)
|
)
|
||||||
panel.contentView?.addSubview(pageCounterLabel)
|
panel.contentView?.addSubview(pageCounterLabel)
|
||||||
|
|
||||||
|
@ -466,8 +464,6 @@ public class ctlCandidateUniversal: ctlCandidate {
|
||||||
|
|
||||||
prevPageButton.target = self
|
prevPageButton.target = self
|
||||||
prevPageButton.action = #selector(pageButtonAction(_:))
|
prevPageButton.action = #selector(pageButtonAction(_:))
|
||||||
|
|
||||||
pageCounterLabel.font = pageCounterFont
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(*, unavailable)
|
@available(*, unavailable)
|
||||||
|
@ -554,30 +550,6 @@ extension ctlCandidateUniversal {
|
||||||
return totalCount / keyLabelCount + ((totalCount % keyLabelCount) != 0 ? 1 : 0)
|
return totalCount / keyLabelCount + ((totalCount % keyLabelCount) != 0 ? 1 : 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用來顯示頁面計數器的 NSFont。因為結果可 nil,所以最好 guard-let 再用。
|
|
||||||
private var pageCounterFont: NSFont? {
|
|
||||||
var pointSize: CGFloat { candidateView.fractionFontSize }
|
|
||||||
let systemFontDesc = NSFont.systemFont(ofSize: pointSize, weight: .light).fontDescriptor
|
|
||||||
let fractionFontDesc = systemFontDesc.addingAttributes(
|
|
||||||
[
|
|
||||||
NSFontDescriptor.AttributeName.traits: [
|
|
||||||
[
|
|
||||||
NSFontDescriptor.FeatureKey.typeIdentifier: kFractionsType,
|
|
||||||
NSFontDescriptor.FeatureKey.selectorIdentifier: kDiagonalFractionsSelector,
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
)
|
|
||||||
return NSFont(descriptor: fractionFontDesc, size: pointSize) ?? nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 用來生成拿給頁面計數器用的顯示字串。
|
|
||||||
// TODO: 這衰洨的 pageCount 總是返回空字串,需要調查。
|
|
||||||
private var pageCounterText: String {
|
|
||||||
if pageCount < 2 { return .init() }
|
|
||||||
return "\(currentPageIndex + 1)/"
|
|
||||||
}
|
|
||||||
|
|
||||||
private func layoutCandidateView() {
|
private func layoutCandidateView() {
|
||||||
guard let delegate = delegate else {
|
guard let delegate = delegate else {
|
||||||
return
|
return
|
||||||
|
@ -627,11 +599,11 @@ extension ctlCandidateUniversal {
|
||||||
prevPageButton.isHidden = true
|
prevPageButton.isHidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !pageCounterText.isEmpty {
|
if pageCount >= 2 {
|
||||||
let attrString = NSAttributedString(
|
let attrString = NSMutableAttributedString(
|
||||||
string: pageCounterText.appending(String(pageCount)),
|
string: "\(currentPageIndex + 1)/\(pageCount)",
|
||||||
attributes: [
|
attributes: [
|
||||||
.font: pageCounterFont as AnyObject
|
.font: NSFont.systemFont(ofSize: candidateView.fractionFontSize)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
pageCounterLabel.attributedStringValue = attrString
|
pageCounterLabel.attributedStringValue = attrString
|
||||||
|
@ -641,6 +613,7 @@ extension ctlCandidateUniversal {
|
||||||
)
|
)
|
||||||
|
|
||||||
rect.size.height += 3
|
rect.size.height += 3
|
||||||
|
rect.size.width += 4
|
||||||
let rectOriginY: CGFloat =
|
let rectOriginY: CGFloat =
|
||||||
(currentLayout == .horizontal)
|
(currentLayout == .horizontal)
|
||||||
? (newSize.height - rect.height) / 2
|
? (newSize.height - rect.height) / 2
|
||||||
|
|
Loading…
Reference in New Issue