From 34fa183148c53cfd30384624e1812a4f13c4ffa6 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 30 Aug 2022 11:59:40 +0800 Subject: [PATCH] ctlIME // Tweak tooltip axis during vertical typing. --- .../ctlInputMethod_HandleDisplay.swift | 11 ++++++++++- .../UIModules/TooltipUI/TooltipController.swift | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Source/Modules/ControllerModules/ctlInputMethod_HandleDisplay.swift b/Source/Modules/ControllerModules/ctlInputMethod_HandleDisplay.swift index a0c5e50f..017d4871 100644 --- a/Source/Modules/ControllerModules/ctlInputMethod_HandleDisplay.swift +++ b/Source/Modules/ControllerModules/ctlInputMethod_HandleDisplay.swift @@ -26,7 +26,16 @@ extension ctlInputMethod { ) cursor -= 1 } - ctlInputMethod.tooltipController.show(tooltip: tooltip, at: lineHeightRect.origin) + var finalOrigin: NSPoint = lineHeightRect.origin + if isVerticalTyping { + finalOrigin = NSPoint( + x: lineHeightRect.origin.x + lineHeightRect.size.width + 4.0, y: lineHeightRect.origin.y - 4.0 + ) + ctlInputMethod.tooltipController.direction = .vertical + } else { + ctlInputMethod.tooltipController.direction = .horizontal + } + ctlInputMethod.tooltipController.show(tooltip: tooltip, at: finalOrigin) } func show(candidateWindowWith state: InputStateProtocol) { diff --git a/Source/Modules/UIModules/TooltipUI/TooltipController.swift b/Source/Modules/UIModules/TooltipUI/TooltipController.swift index 16898b9b..cc8c300c 100644 --- a/Source/Modules/UIModules/TooltipUI/TooltipController.swift +++ b/Source/Modules/UIModules/TooltipUI/TooltipController.swift @@ -20,6 +20,11 @@ public class TooltipController: NSWindowController { case prompt } + public enum displayDirection { + case horizontal + case vertical + } + private var backgroundColor = NSColor.windowBackgroundColor private var textColor = NSColor.windowBackgroundColor private var messageTextField: NSTextField @@ -30,6 +35,8 @@ public class TooltipController: NSWindowController { } } + public var direction: displayDirection = .horizontal + public init() { let contentRect = NSRect(x: 128.0, y: 128.0, width: 300.0, height: 20.0) let styleMask: NSWindow.StyleMask = [.borderless, .nonactivatingPanel] @@ -157,6 +164,7 @@ public class TooltipController: NSWindowController { var rect = attrString.boundingRect( with: NSSize(width: 1600.0, height: 1600.0), options: .usesLineFragmentOrigin ) + rect.size.width += 10 messageTextField.frame = rect window?.setFrame(rect, display: true)