Change line number view border in high-contrast mode

This commit is contained in:
1024jp 2020-03-26 13:07:09 +09:00
parent 2f41131a3b
commit 97ca807e40
2 changed files with 15 additions and 12 deletions

View File

@ -12,7 +12,7 @@ Change Log
- Duplicate lines more intelligently.
- Use mirrored pilcrow sign “⁋” for an invisible line ending symbol in RTL mode.
- Improve drawing performance.
- [trivial] Make the outlines of opacity sample tips more distinct in the high-contrast mode.
- Make borders of line number views and opacity sample tips more distinct in the high-contrast mode.
- [dev] Update build environment to Xcode 11.4 (Swift 5.2).

View File

@ -100,6 +100,8 @@ final class LineNumberView: NSView {
case normal = 0.75
case bold = 0.9
case stroke = 0.2
static let highContrastCoefficient: CGFloat = 0.5
}
@ -234,7 +236,7 @@ final class LineNumberView: NSView {
width: dirtyRect.width, height: 1)
@unknown default: fatalError()
}
self.textColor(.stroke).setFill()
self.foregroundColor(.stroke).setFill()
dividerRect.fill()
NSGraphicsContext.restoreGraphicsState()
@ -257,16 +259,17 @@ final class LineNumberView: NSView {
}
/// return text color considering current accesibility setting
private func textColor(_ strength: ColorStrength = .normal) -> NSColor {
/// return foreground color by considering the current accesibility setting
private func foregroundColor(_ strength: ColorStrength = .normal) -> NSColor {
let textColor = self.textView?.textColor ?? .textColor
let fraction = NSWorkspace.shared.accessibilityDisplayShouldIncreaseContrast
? strength.rawValue + ColorStrength.highContrastCoefficient
: strength.rawValue
if NSWorkspace.shared.accessibilityDisplayShouldIncreaseContrast, strength != .stroke {
return textColor
}
guard fraction < 1 else { return textColor }
return self.backgroundColor.blended(withFraction: strength.rawValue, of: textColor) ?? textColor
return self.backgroundColor.blended(withFraction: fraction, of: textColor) ?? textColor
}
@ -297,8 +300,8 @@ final class LineNumberView: NSView {
context.setFont(Self.lineNumberFont)
context.setFontSize(drawingInfo.fontSize)
context.setFillColor(self.textColor().cgColor)
context.setStrokeColor(self.textColor(.stroke).cgColor)
context.setFillColor(self.foregroundColor().cgColor)
context.setStrokeColor(self.foregroundColor(.stroke).cgColor)
let isVerticalText = textView.layoutOrientation == .vertical
let scale = textView.scale
@ -339,12 +342,12 @@ final class LineNumberView: NSView {
// draw
if isSelected {
context.setFillColor(self.textColor(.bold).cgColor)
context.setFillColor(self.foregroundColor(.bold).cgColor)
context.setFont(Self.boldLineNumberFont)
}
context.showGlyphs(glyphs, at: positions)
if isSelected {
context.setFillColor(self.textColor().cgColor)
context.setFillColor(self.foregroundColor().cgColor)
context.setFont(Self.lineNumberFont)
}
}