Skip to content

Commit

Permalink
inverse color to match dark/light appearance
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed Jul 4, 2023
1 parent 244fe91 commit d95f2f9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions SquirrelPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,14 @@ - (void)hideStatus:(NSTimer *)timer {
colorWithAlphaComponent:foregroundColor.alphaComponent];
}

static inline NSColor *inverseColor(NSColor *color) {
return [NSColor colorWithColorSpace:color.colorSpace
hue:color.hueComponent
saturation:color.saturationComponent
brightness:1-color.brightnessComponent
alpha:color.alphaComponent];
}

static NSFontDescriptor *getFontDescriptor(NSString *fullname) {
if (fullname == nil) {
return nil;
Expand Down Expand Up @@ -2266,6 +2274,26 @@ + (void)updateTheme:(SquirrelTheme *)theme withConfig:(SquirrelConfig *)config f
highlightedTextColor = highlightedTextColor ? highlightedTextColor : [NSColor selectedTextColor];
highlightedBackColor = highlightedBackColor ? highlightedBackColor : isNative ? [NSColor selectedTextBackgroundColor] : nil;

if (@available(macOS 10.14, *)) {
if (theme.translucency > 0 &&
((backgroundColor.brightnessComponent >= 0.5 && isDark) ||
(backgroundColor.brightnessComponent < 0.5 && !isDark))) {
backgroundColor = inverseColor(backgroundColor);
borderColor = borderColor ? inverseColor(borderColor) : nil;
preeditBackgroundColor = preeditBackgroundColor ? inverseColor(preeditBackgroundColor) : nil;
candidateTextColor = inverseColor(candidateTextColor);
highlightedCandidateTextColor = [inverseColor(highlightedCandidateTextColor) highlightWithLevel:highlightedCandidateTextColor.brightnessComponent];
highlightedCandidateBackColor = highlightedCandidateBackColor ? [inverseColor(highlightedCandidateBackColor) shadowWithLevel:1-highlightedCandidateBackColor.brightnessComponent] : nil;
candidateLabelColor = inverseColor(candidateLabelColor);
highlightedCandidateLabelColor = [inverseColor(highlightedCandidateLabelColor) highlightWithLevel:highlightedCandidateLabelColor.brightnessComponent];
commentTextColor = inverseColor(commentTextColor);
highlightedCommentTextColor = [inverseColor(highlightedCommentTextColor) highlightWithLevel:highlightedCommentTextColor.brightnessComponent];
textColor = inverseColor(textColor);
highlightedTextColor = [inverseColor(highlightedTextColor) highlightWithLevel:highlightedTextColor.brightnessComponent];
highlightedBackColor = highlightedBackColor ? [inverseColor(highlightedBackColor) shadowWithLevel:1-highlightedBackColor.brightnessComponent] : nil;
}
}

attrs[NSForegroundColorAttributeName] = candidateTextColor;
highlightedAttrs[NSForegroundColorAttributeName] = highlightedCandidateTextColor;
labelAttrs[NSForegroundColorAttributeName] = candidateLabelColor;
Expand Down

0 comments on commit d95f2f9

Please sign in to comment.