Skip to content

Commit

Permalink
update layer
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed Jul 4, 2023
1 parent d4e2031 commit 4fe9fc4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions SquirrelPanel.m
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ @interface SquirrelView : NSView
@property(nonatomic, assign) CGFloat seperatorWidth;
@property(nonatomic, readonly) CAShapeLayer *shape;
@property(nonatomic, getter=isFlipped, readonly) BOOL flipped;
@property(nonatomic, readonly) BOOL wantsUpdateLayer;

- (void) drawViewWith:(NSArray<NSValue *> *)candidateRanges
highlightedIndex:(NSUInteger)highlightedIndex
Expand All @@ -297,6 +298,10 @@ - (BOOL)isFlipped {
return YES;
}

- (BOOL)wantsUpdateLayer {
return YES;
}

- (BOOL)isDark {
if (@available(macOS 10.14, *)) {
if ([NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]] == NSAppearanceNameDarkAqua) {
Expand All @@ -320,6 +325,7 @@ - (instancetype)initWithFrame:(NSRect)frameRect {
self.wantsLayer = YES;
self.layer.masksToBounds = YES;
self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay;
self.layerContentsPlacement = NSViewLayerContentsPlacementCenter;
}

if (@available(macOS 12.0, *)) {
Expand Down Expand Up @@ -728,7 +734,7 @@ - (void)multilineRectForRange:(NSRange)charRange leadingRect:(NSRect *)leadingRe
}

// All draws happen here
- (void)drawRect:(NSRect)dirtyRect {
- (void)updateLayer {
NSBezierPath *backgroundPath;
NSBezierPath *borderPath;
NSBezierPath *textContainerPath;
Expand All @@ -741,7 +747,7 @@ - (void)drawRect:(NSRect)dirtyRect {
SquirrelTheme *theme = self.currentTheme;
NSPoint lineOrigin = NSZeroPoint;

NSRect backgroundRect = dirtyRect;
NSRect backgroundRect = self.bounds;
NSRect textContainerRect = NSInsetRect(backgroundRect, theme.edgeInset.width, theme.edgeInset.height);
NSRect preeditRect = NSZeroRect;
NSRect candidateBlockRect = NSZeroRect;
Expand Down Expand Up @@ -1395,12 +1401,13 @@ - (void)show {
[textContainer setSize:NSMakeSize(_maxSize.width + theme.hilitedCornerRadius * 2, maxTextHeight)];
}
}
if (theme.vertical ? (NSMinX(_position) < MAX(NSHeight(maxContentRect), _maxSize.height) + theme.edgeInset.height * 2 + (sweepVertical ? kOffsetHeight : 0)) :
(NSMinY(_position) < MAX(NSHeight(maxContentRect), _maxSize.height) + theme.edgeInset.height * 2 + (sweepVertical ? 0 : kOffsetHeight))) {
if (theme.vertical ? (NSMinX(_position) - NSMinX(screenRect) < MAX(NSHeight(maxContentRect), _maxSize.height) + theme.edgeInset.height * 2 + (sweepVertical ? kOffsetHeight : 0)) :
(NSMinY(_position) - NSMinY(screenRect) < MAX(NSHeight(maxContentRect), _maxSize.height) + theme.edgeInset.height * 2 + (sweepVertical ? 0 : kOffsetHeight))) {
if (NSHeight(maxContentRect) >= _maxSize.height) {
_maxSize.height = NSHeight(maxContentRect);
} else {
maxContentRect.size.height = _maxSize.height;
[textContainer setSize:NSMakeSize(_maxTextWidth + theme.hilitedCornerRadius * 2, _maxSize.height)];
}
}
}
Expand Down

0 comments on commit 4fe9fc4

Please sign in to comment.