diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-02-09 22:51:47 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-02-09 22:51:47 +0100 |
| commit | 953623b990fb65a0a9676071022ae8ce50436d53 (patch) | |
| tree | d5135717f0e63bdd760a69cedf6703638b517095 /Flat Bezel/BBSearchObjectView.m | |
| parent | fc2c05420021064af5e322f5e59cf0995239349a (diff) | |
Improve drawing, add padding to bezel
Diffstat (limited to 'Flat Bezel/BBSearchObjectView.m')
| -rw-r--r-- | Flat Bezel/BBSearchObjectView.m | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/Flat Bezel/BBSearchObjectView.m b/Flat Bezel/BBSearchObjectView.m index ba88b0b..0722e0c 100644 --- a/Flat Bezel/BBSearchObjectView.m +++ b/Flat Bezel/BBSearchObjectView.m @@ -169,8 +169,33 @@ [titleString drawInRect:centerRectInRect(centerRect, textDrawRect)]; } -@end - - +- (void)drawSearchPlaceholderWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { + NSString *defaultText = NSLocalizedStringWithDefaultValue(@"Type to search", nil, [NSBundle mainBundle], @"Type to search", @"Hint that appears in the first pane of the QS interface when it's empty."); + NSSize textSize = [defaultText sizeWithAttributes:nameAttributes]; + NSRect textRect = centerRectInRect(rectFromSize(textSize), cellFrame); + BOOL isFirstResponder = [[controlView window] firstResponder] == controlView && ![controlView isKindOfClass:[NSTableView class]]; + + if (isFirstResponder && [controlView isKindOfClass:[QSSearchObjectView class]]) { + NSImage *find = [NSImage imageWithSystemSymbolName:@"magnifyingglass.circle.fill" accessibilityDescription:nil]; + + + [find setSize:QSSize16]; + NSRect findImageRect = expelRectFromRectOnEdge(centerRectInRect(rectFromSize([find size]), cellFrame), textRect, NSRectEdgeMinX, -2); + + + NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext]; + [graphicsContext saveGraphicsState]; + CGContextRef context = [graphicsContext CGContext]; + CGContextBeginTransparencyLayerWithRect(context, findImageRect, nil); + CGContextSetBlendMode(context, kCGBlendModeNormal); + [find drawInRect:findImageRect fromRect:rectFromSize([find size]) operation:NSCompositingOperationSourceOver fraction:1]; + CGContextSetBlendMode(context, kCGBlendModeSourceIn); + CGContextSetFillColorWithColor(context, [[NSColor textColor] CGColor]); + CGContextFillRect(context, findImageRect); + CGContextEndTransparencyLayer(context); + [defaultText drawInRect:textRect withAttributes:nameAttributes]; + } +} +@end |