-
-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add search bar #2278
base: master
Are you sure you want to change the base?
feat: Add search bar #2278
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import Cocoa | |
|
||
class ThumbnailsView: NSVisualEffectView { | ||
let scrollView = ScrollView() | ||
let searchField = SearchField() | ||
static var recycledViews = [ThumbnailView]() | ||
var rows = [[ThumbnailView]]() | ||
|
||
|
@@ -11,6 +12,7 @@ class ThumbnailsView: NSVisualEffectView { | |
state = .active | ||
wantsLayer = true | ||
updateRoundedCorners(Preferences.windowCornerRadius) | ||
addSubview(searchField) | ||
addSubview(scrollView) | ||
// TODO: think about this optimization more | ||
(1...100).forEach { _ in ThumbnailsView.recycledViews.append(ThumbnailView()) } | ||
|
@@ -67,9 +69,17 @@ class ThumbnailsView: NSVisualEffectView { | |
} | ||
} | ||
|
||
var lastOpenMaxX: CGFloat = 0 | ||
var lastOpenMaxY: CGFloat = 0 | ||
func updateItemsAndLayout(_ screen: NSScreen) { | ||
let widthMax = ThumbnailsPanel.widthMax(screen).rounded() | ||
if let (maxX, maxY) = layoutThumbnailViews(screen, widthMax) { | ||
if let (maxXThumbnails, maxYThumbnails) = layoutThumbnailViews(screen, widthMax) { | ||
if !searchField.isTextChangeCallback { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to check that |
||
lastOpenMaxX = maxXThumbnails | ||
lastOpenMaxY = maxYThumbnails | ||
} | ||
let maxX = searchField.isTextChangeCallback ? lastOpenMaxX : maxXThumbnails | ||
let maxY = searchField.isTextChangeCallback ? lastOpenMaxY : maxYThumbnails | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are not needed. You can just reuse |
||
layoutParentViews(screen, maxX, widthMax, maxY) | ||
if Preferences.alignThumbnails == .center { | ||
centerRows(maxX) | ||
|
@@ -143,8 +153,12 @@ class ThumbnailsView: NSVisualEffectView { | |
|
||
private func layoutParentViews(_ screen: NSScreen, _ maxX: CGFloat, _ widthMax: CGFloat, _ maxY: CGFloat) { | ||
let heightMax = ThumbnailsPanel.heightMax(screen).rounded() | ||
frame.size = NSSize(width: min(maxX, widthMax) + Preferences.windowPadding * 2, height: min(maxY, heightMax) + Preferences.windowPadding * 2) | ||
scrollView.frame.size = NSSize(width: min(maxX, widthMax), height: min(maxY, heightMax)) | ||
frame.size = NSSize(width: min(maxX, widthMax) + Preferences.windowPadding * 2, height: min(maxY + 40, heightMax) + Preferences.windowPadding * 2) | ||
|
||
searchField.frame.size = NSSize(width: min(maxX, widthMax), height: 40) | ||
searchField.frame.origin = CGPoint(x: Preferences.windowPadding, y: min(maxY + 40, heightMax) - Preferences.windowPadding) | ||
|
||
scrollView.frame.size = NSSize(width: min(maxX, widthMax), height: min(maxY, heightMax - 40)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use a constant for the height of the search field. |
||
scrollView.frame.origin = CGPoint(x: Preferences.windowPadding, y: Preferences.windowPadding) | ||
scrollView.contentView.frame.size = scrollView.frame.size | ||
if App.shared.userInterfaceLayoutDirection == .rightToLeft { | ||
|
@@ -296,3 +310,32 @@ enum Direction { | |
return self == .leading ? 1 : -1 | ||
} | ||
} | ||
|
||
class SearchField: NSTextField { | ||
convenience init() { | ||
self.init(string: "") | ||
placeholderString = "Search" | ||
drawsBackground = false | ||
isBezeled = false | ||
font = NSFont.systemFont(ofSize: 30) | ||
focusRingType = .none | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could set |
||
} | ||
override func draw(_ dirtyRect: NSRect) { | ||
super.draw(dirtyRect) | ||
|
||
let borderColor = NSColor(red: 1, green: 1, blue: 1, alpha: 0.2) | ||
let borderRect = NSMakeRect(0, 39, dirtyRect.size.width, 1) | ||
|
||
borderColor.set() | ||
NSBezierPath.fill(borderRect) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could set
|
||
override func textDidChange(_ notification: Notification) { | ||
let screen = NSScreen.preferred() | ||
Windows.refreshWhichWindowsToShowTheUser(screen) | ||
isTextChangeCallback = true | ||
App.app.refreshOpenUi() | ||
isTextChangeCallback = false | ||
} | ||
var isTextChangeCallback = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not needed. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be
lowercased()
.