Skip to content

Commit

Permalink
Show tool tip when label is truncated.
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Aug 30, 2024
1 parent e7d9849 commit 115b8f9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Packages/MacUI/Sources/ControlUI/FilenameTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ public final class FilenameTextField: NSTextField {
}


public override var stringValue: String {

didSet {
self.invalidateToolTip()
}
}


public override func setFrameSize(_ newSize: NSSize) {

super.setFrameSize(newSize)

self.invalidateToolTip()
}


public override func mouseDown(with event: NSEvent) {

super.mouseDown(with: event)
Expand All @@ -56,6 +72,18 @@ public final class FilenameTextField: NSTextField {

return true
}


/// Invalidates whether showing the tool tip if the label is truncated.
private func invalidateToolTip() {

guard let cell else { return }

let expansionFrame = cell.expansionFrame(withFrame: self.frame, in: self)
let isTruncated = !expansionFrame.isEmpty

self.toolTip = isTruncated ? self.stringValue : nil
}
}


Expand Down

0 comments on commit 115b8f9

Please sign in to comment.