Skip to content

Commit

Permalink
Merge pull request #392 from zonble/master
Browse files Browse the repository at this point in the history
Tunes the UI for the candidate
  • Loading branch information
lukhnos authored Nov 29, 2023
2 parents 4764a32 + ed66196 commit 0e34add
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fileprivate class HorizontalCandidateView: NSView {

keyLabelAttrDict = [.font: labelFont,
.paragraphStyle: paraStyle,
.foregroundColor: NSColor.secondaryLabelColor]
.foregroundColor: NSColor.labelColor]
candidateAttrDict = [.font: candidateFont,
.paragraphStyle: paraStyle,
.foregroundColor: NSColor.labelColor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fileprivate class VerticalKeyLabelStripView: NSView {

let textAttr: [NSAttributedString.Key: AnyObject] = [
.font: keyLabelFont,
.foregroundColor: NSColor.secondaryLabelColor,
.foregroundColor: NSColor.labelColor,
.paragraphStyle: paraStyle]
let textAttrHighlighted: [NSAttributedString.Key: AnyObject] = [
.font: keyLabelFont,
Expand Down Expand Up @@ -134,6 +134,7 @@ public class VerticalCandidateController: CandidateController {
scrollView.verticalScrollElasticity = .none
scrollView.drawsBackground = false
scrollView.contentView.drawsBackground = false
scrollView.contentView.postsBoundsChangedNotifications = true

tableView = NSTableView(frame: contentRect)
let column = NSTableColumn(identifier: NSUserInterfaceItemIdentifier(rawValue: "candidate"))
Expand Down Expand Up @@ -171,6 +172,11 @@ public class VerticalCandidateController: CandidateController {
tableView.delegate = self
tableView.doubleAction = #selector(rowDoubleClicked(_:))
tableView.target = self

NotificationCenter.default.addObserver(self,
selector: #selector(boundsChange),
name: NSView.boundsDidChangeNotification,
object: scrollView.contentView)
}

required init?(coder: NSCoder) {
Expand Down Expand Up @@ -256,6 +262,27 @@ public class VerticalCandidateController: CandidateController {
tableView.selectRowIndexes(IndexSet(integer: Int(newIndex)), byExtendingSelection: false)
}
}

var scrollTimer: Timer?

@objc func boundsChange() {
let visibleRect = tableView.visibleRect
let visibleRowIndexes = tableView.rows(in: visibleRect)
let selected = selectedCandidateIndex

scrollTimer?.invalidate()
if visibleRowIndexes.contains(Int(selected)) == false {
selectedCandidateIndex = UInt(visibleRowIndexes.lowerBound)
tableView.scrollRowToVisible(visibleRowIndexes.lowerBound)
} else {
scrollTimer = Timer.scheduledTimer(withTimeInterval: 0.25, repeats: false) { timer in
self.tableView.reloadData()
self.tableView.scrollRowToVisible(visibleRowIndexes.lowerBound)
self.scrollTimer?.invalidate()
self.scrollTimer = nil
}
}
}
}

extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegate {
Expand Down Expand Up @@ -414,7 +441,6 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat
return
}


var tooltipHeight: CGFloat = 0
var tooltipWidth: CGFloat = 0

Expand Down Expand Up @@ -483,6 +509,8 @@ extension VerticalCandidateController: NSTableViewDataSource, NSTableViewDelegat
tooltipView.frame = NSRect(x: tooltipPadding, y: windowHeight - tooltipHeight + tooltipPadding, width: windowWidth, height: tooltipHeight)
self.window?.setFrame(frameRect, display: false)
}


}

extension NSImage {
Expand Down

0 comments on commit 0e34add

Please sign in to comment.