Repo // Let tooltip window auto-disappear after given seconds.
This commit is contained in:
parent
751824feef
commit
4e124e6aac
|
@ -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) {
|
||||||
|
|
|
@ -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
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue