Repo // Let tooltip window auto-disappear after given seconds.

This commit is contained in:
ShikiSuen 2022-10-19 10:22:07 +08:00
parent 751824feef
commit 4e124e6aac
3 changed files with 11 additions and 6 deletions

View File

@ -53,7 +53,7 @@ public class TooltipUI: NSWindowController {
public func show( public func show(
tooltip: String = "", at point: NSPoint, tooltip: String = "", at point: NSPoint,
bottomOutOfScreenAdjustmentHeight heightDelta: Double, bottomOutOfScreenAdjustmentHeight heightDelta: Double,
direction: NSAttributedTooltipTextView.writingDirection = .horizontal direction: NSAttributedTooltipTextView.writingDirection = .horizontal, duration: Double = 0
) { ) {
self.direction = direction self.direction = direction
self.tooltip = tooltip self.tooltip = tooltip
@ -61,6 +61,11 @@ public class TooltipUI: NSWindowController {
window?.orderFront(nil) window?.orderFront(nil)
set(windowTopLeftPoint: point, bottomOutOfScreenAdjustmentHeight: heightDelta, useGCD: false) set(windowTopLeftPoint: point, bottomOutOfScreenAdjustmentHeight: heightDelta, useGCD: false)
window?.setIsVisible(true) window?.setIsVisible(true)
if duration > 0 {
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
self.window?.orderOut(nil)
}
}
} }
public func setColor(state: TooltipColorState) { public func setColor(state: TooltipColorState) {

View File

@ -40,7 +40,7 @@ extension SessionCtl {
return lineHeightRect return lineHeightRect
} }
public func showTooltip(_ tooltip: String) { public func showTooltip(_ tooltip: String, duration: Double = 0) {
guard client() != nil else { return } guard client() != nil else { return }
if tooltip.isEmpty { if tooltip.isEmpty {
tooltipInstance.hide() tooltipInstance.hide()
@ -66,8 +66,8 @@ extension SessionCtl {
} }
// //
tooltipInstance.show( tooltipInstance.show(
tooltip: tooltip, at: finalOrigin, tooltip: tooltip, at: finalOrigin, bottomOutOfScreenAdjustmentHeight: delta,
bottomOutOfScreenAdjustmentHeight: delta, direction: tooltipContentDirection direction: tooltipContentDirection, duration: duration
) )
} }

View File

@ -76,7 +76,7 @@ extension SessionCtl {
if previous.hasComposition, ![.ofAbortion, .ofCommitting].contains(newState.type) { if previous.hasComposition, ![.ofAbortion, .ofCommitting].contains(newState.type) {
commit(text: previous.displayedText) commit(text: previous.displayedText)
} }
showTooltip(newState.tooltip) // showTooltip(newState.tooltip, duration: 1) //
clearInlineDisplay() clearInlineDisplay()
// //
inputHandler.clear() inputHandler.clear()
@ -84,7 +84,7 @@ extension SessionCtl {
ctlCandidateCurrent.visible = false ctlCandidateCurrent.visible = false
commit(text: newState.textToCommit) commit(text: newState.textToCommit)
setInlineDisplayWithCursor() setInlineDisplayWithCursor()
showTooltip(newState.tooltip) // showTooltip(newState.tooltip, duration: 1) //
case .ofMarking: case .ofMarking:
ctlCandidateCurrent.visible = false ctlCandidateCurrent.visible = false
setInlineDisplayWithCursor() setInlineDisplayWithCursor()