TDKCandidates // Only show 1 column for vertical typing.
This commit is contained in:
parent
ab959a5c12
commit
4edbe4d85c
|
@ -116,7 +116,11 @@ public class CandidatePool {
|
||||||
/// - columnCapacity: (第一縱列的最大候選字詞數量, 陣列畫面展開之後的每一縱列的最大候選字詞數量)。
|
/// - columnCapacity: (第一縱列的最大候選字詞數量, 陣列畫面展開之後的每一縱列的最大候選字詞數量)。
|
||||||
/// - selectionKeys: 選字鍵。
|
/// - selectionKeys: 選字鍵。
|
||||||
/// - locale: 區域編碼。例:「zh-Hans」或「zh-Hant」。
|
/// - locale: 區域編碼。例:「zh-Hans」或「zh-Hant」。
|
||||||
public init(candidates: [String], columnCapacity: Int, selectionKeys: String = "123456789", locale: String = "") {
|
public init(
|
||||||
|
candidates: [String], columnCapacity: Int, columns: Int = 3, selectionKeys: String = "123456789",
|
||||||
|
locale: String = ""
|
||||||
|
) {
|
||||||
|
maxColumnsPerPage = max(1, columns)
|
||||||
maxColumnCapacity = max(1, columnCapacity)
|
maxColumnCapacity = max(1, columnCapacity)
|
||||||
self.selectionKeys = selectionKeys
|
self.selectionKeys = selectionKeys
|
||||||
candidateDataAll = candidates.map { .init(key: "0", displayedText: $0) }
|
candidateDataAll = candidates.map { .init(key: "0", displayedText: $0) }
|
||||||
|
@ -143,7 +147,10 @@ public class CandidatePool {
|
||||||
/// - rowCapacity: (第一橫行的最大候選字詞數量, 陣列畫面展開之後的每一橫行的最大候選字詞數量)。
|
/// - rowCapacity: (第一橫行的最大候選字詞數量, 陣列畫面展開之後的每一橫行的最大候選字詞數量)。
|
||||||
/// - selectionKeys: 選字鍵。
|
/// - selectionKeys: 選字鍵。
|
||||||
/// - locale: 區域編碼。例:「zh-Hans」或「zh-Hant」。
|
/// - locale: 區域編碼。例:「zh-Hans」或「zh-Hant」。
|
||||||
public init(candidates: [String], rowCapacity: Int, selectionKeys: String = "123456789", locale: String = "") {
|
public init(
|
||||||
|
candidates: [String], rowCapacity: Int, rows: Int = 3, selectionKeys: String = "123456789", locale: String = ""
|
||||||
|
) {
|
||||||
|
maxRowsPerPage = max(1, rows)
|
||||||
maxRowCapacity = max(1, rowCapacity)
|
maxRowCapacity = max(1, rowCapacity)
|
||||||
self.selectionKeys = selectionKeys
|
self.selectionKeys = selectionKeys
|
||||||
candidateDataAll = candidates.map { .init(key: "0", displayedText: $0) }
|
candidateDataAll = candidates.map { .init(key: "0", displayedText: $0) }
|
||||||
|
|
|
@ -15,6 +15,7 @@ import SwiftUI
|
||||||
public class CtlCandidateTDK: CtlCandidate {
|
public class CtlCandidateTDK: CtlCandidate {
|
||||||
public var thePoolHorizontal: CandidatePool = .init(candidates: [], rowCapacity: 6)
|
public var thePoolHorizontal: CandidatePool = .init(candidates: [], rowCapacity: 6)
|
||||||
public var thePoolVertical: CandidatePool = .init(candidates: [], columnCapacity: 6)
|
public var thePoolVertical: CandidatePool = .init(candidates: [], columnCapacity: 6)
|
||||||
|
public var maxLinesPerPage: Int = 0
|
||||||
|
|
||||||
@available(macOS 12, *)
|
@available(macOS 12, *)
|
||||||
public var theViewHorizontal: VwrCandidateHorizontal {
|
public var theViewHorizontal: VwrCandidateHorizontal {
|
||||||
|
@ -87,13 +88,13 @@ public class CtlCandidateTDK: CtlCandidate {
|
||||||
case .horizontal:
|
case .horizontal:
|
||||||
thePoolHorizontal = .init(
|
thePoolHorizontal = .init(
|
||||||
candidates: delegate.candidatePairs(conv: true).map(\.1), rowCapacity: 6,
|
candidates: delegate.candidatePairs(conv: true).map(\.1), rowCapacity: 6,
|
||||||
selectionKeys: delegate.selectionKeys, locale: locale
|
rows: maxLinesPerPage, selectionKeys: delegate.selectionKeys, locale: locale
|
||||||
)
|
)
|
||||||
thePoolHorizontal.highlight(at: 0)
|
thePoolHorizontal.highlight(at: 0)
|
||||||
case .vertical:
|
case .vertical:
|
||||||
thePoolVertical = .init(
|
thePoolVertical = .init(
|
||||||
candidates: delegate.candidatePairs(conv: true).map(\.1), columnCapacity: 6,
|
candidates: delegate.candidatePairs(conv: true).map(\.1), columnCapacity: 6,
|
||||||
selectionKeys: delegate.selectionKeys, locale: locale
|
columns: maxLinesPerPage, selectionKeys: delegate.selectionKeys, locale: locale
|
||||||
)
|
)
|
||||||
thePoolVertical.highlight(at: 0)
|
thePoolVertical.highlight(at: 0)
|
||||||
@unknown default:
|
@unknown default:
|
||||||
|
|
|
@ -71,35 +71,12 @@ extension SessionCtl {
|
||||||
|
|
||||||
func showCandidates() {
|
func showCandidates() {
|
||||||
guard let client = client() else { return }
|
guard let client = client() else { return }
|
||||||
var isCandidateWindowVertical: Bool {
|
state.isVerticalCandidateWindow = (isVerticalTyping || !PrefMgr.shared.useHorizontalCandidateList)
|
||||||
// var candidates: [(String, String)] = .init()
|
|
||||||
// if state.isCandidateContainer { candidates = state.candidates }
|
|
||||||
if isVerticalTyping { return true }
|
|
||||||
// 接下來的判斷並非適用於 IMK 選字窗,所以先插入排除語句。
|
|
||||||
// guard Self.ctlCandidateCurrent is CtlCandidateUniversal else { return false }
|
|
||||||
// 以上是通用情形。接下來決定橫排輸入時是否使用縱排選字窗。
|
|
||||||
// 因為在拿候選字陣列時已經排序過了,所以這裡不用再多排序。
|
|
||||||
// 測量每頁顯示候選字的累計總長度。如果太長的話就強制使用縱排候選字窗。
|
|
||||||
// 範例:「屬實牛逼」(會有一大串各種各樣的「鼠食牛Beer」的 emoji)。
|
|
||||||
// let maxCandidatesPerPage = PrefMgr.shared.candidateKeys.count
|
|
||||||
// let firstPageCandidates = candidates[0..<min(maxCandidatesPerPage, candidates.count)].map(\.1)
|
|
||||||
// return firstPageCandidates.joined().count > Int(round(Double(maxCandidatesPerPage) * 1.8))
|
|
||||||
// 上面這句如果是 true 的話,就會是縱排;反之則為橫排。
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
state.isVerticalCandidateWindow = (isCandidateWindowVertical || !PrefMgr.shared.useHorizontalCandidateList)
|
|
||||||
|
|
||||||
|
/// 無論是田所選字窗還是 IMK 選字窗,在這裡都有必要重新初期化。
|
||||||
Self.ctlCandidateCurrent.delegate = nil
|
Self.ctlCandidateCurrent.delegate = nil
|
||||||
|
|
||||||
/// 下面這一段本可直接指定 currentLayout,但這樣的話翻頁按鈕位置無法精準地重新繪製。
|
|
||||||
/// 所以只能重新初期化。壞處就是得在 ctlCandidate() 當中與 SymbolTable 控制有關的地方
|
|
||||||
/// 新增一個空狀態請求、防止縱排與橫排選字窗同時出現。
|
|
||||||
/// layoutCandidateView 在這裡無法起到糾正作用。
|
|
||||||
/// 該問題徹底解決的價值並不大,直接等到 macOS 10.x 全線淘汰之後用 SwiftUI 重寫選字窗吧。
|
|
||||||
|
|
||||||
let candidateLayout: NSUserInterfaceLayoutOrientation =
|
let candidateLayout: NSUserInterfaceLayoutOrientation =
|
||||||
((isCandidateWindowVertical || !PrefMgr.shared.useHorizontalCandidateList)
|
((isVerticalTyping || !PrefMgr.shared.useHorizontalCandidateList)
|
||||||
? .vertical
|
? .vertical
|
||||||
: .horizontal)
|
: .horizontal)
|
||||||
|
|
||||||
|
@ -107,6 +84,9 @@ extension SessionCtl {
|
||||||
Self.ctlCandidateCurrent =
|
Self.ctlCandidateCurrent =
|
||||||
PrefMgr.shared.useIMKCandidateWindow
|
PrefMgr.shared.useIMKCandidateWindow
|
||||||
? CtlCandidateIMK(candidateLayout) : CtlCandidateTDK(candidateLayout)
|
? CtlCandidateIMK(candidateLayout) : CtlCandidateTDK(candidateLayout)
|
||||||
|
if let candidateTDK = Self.ctlCandidateCurrent as? CtlCandidateTDK {
|
||||||
|
candidateTDK.maxLinesPerPage = isVerticalTyping ? 1 : 3
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Self.ctlCandidateCurrent = CtlCandidateIMK(candidateLayout)
|
Self.ctlCandidateCurrent = CtlCandidateIMK(candidateLayout)
|
||||||
}
|
}
|
||||||
|
@ -116,7 +96,8 @@ extension SessionCtl {
|
||||||
)
|
)
|
||||||
|
|
||||||
if state.type == .ofAssociates {
|
if state.type == .ofAssociates {
|
||||||
Self.ctlCandidateCurrent.tooltip = NSLocalizedString("Hold ⇧ to choose associates.", comment: "")
|
Self.ctlCandidateCurrent.tooltip =
|
||||||
|
isVerticalTyping ? "⇧" : NSLocalizedString("Hold ⇧ to choose associates.", comment: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
Self.ctlCandidateCurrent.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier
|
Self.ctlCandidateCurrent.useLangIdentifier = PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier
|
||||||
|
@ -141,7 +122,7 @@ extension SessionCtl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Self.ctlCandidateCurrent.delegate = self
|
Self.ctlCandidateCurrent.delegate = self // 會自動觸發田所選字窗的資料重載。
|
||||||
Self.ctlCandidateCurrent.visible = true
|
Self.ctlCandidateCurrent.visible = true
|
||||||
|
|
||||||
if isVerticalTyping {
|
if isVerticalTyping {
|
||||||
|
|
Loading…
Reference in New Issue