TDKCandidates // Only show 1 column for vertical typing.

This commit is contained in:
ShikiSuen 2022-10-08 23:36:53 +08:00
parent ab959a5c12
commit 4edbe4d85c
3 changed files with 21 additions and 32 deletions

View File

@ -116,7 +116,11 @@ public class CandidatePool {
/// - columnCapacity: (, ) /// - columnCapacity: (, )
/// - selectionKeys: /// - selectionKeys:
/// - locale: zh-Hanszh-Hant /// - locale: zh-Hanszh-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-Hanszh-Hant /// - locale: zh-Hanszh-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) }

View File

@ -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:

View File

@ -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 {