CtlCandidateTDK // Limit rows per page to 3.
This commit is contained in:
parent
cef1a2a3f5
commit
1be59aa364
|
@ -9,7 +9,7 @@ TDK 選字窗以純 SwiftUI 構築,用以取代此前自上游繼承來的 Vol
|
|||
然而,TDK 選字窗目前有下述侷限:
|
||||
|
||||
- 因 SwiftUI 自身特性所導致的嚴重的效能問題。基本上來講,如果您經常使用全字庫模式的話,請在偏好設定內啟用效能更高的 IMK 選字窗。
|
||||
- 同樣出於上述原因,為了讓田所選字窗至少處於可在生產力環境下正常使用的狀態,就犧牲了捲動檢視的功能。也就是說,每次只顯示六行,但顯示內容則隨著使用者的游標操作而更新。
|
||||
- 同樣出於上述原因,為了讓田所選字窗至少處於可在生產力環境下正常使用的狀態,就犧牲了捲動檢視的功能。也就是說,每次只顯示三行,但顯示內容則隨著使用者的游標操作而更新。
|
||||
- TDK 選字窗目前僅完成了橫版矩陣陳列模式的實作,且尚未引入對縱排選字窗陳列佈局的支援。
|
||||
|
||||
因為這些問題恐怕需要很久才能全部解決,所以威注音會在這段時間內推薦使用者們優先使用 IMK 選字窗。
|
||||
|
|
|
@ -10,21 +10,24 @@ import Cocoa
|
|||
import Shared
|
||||
|
||||
/// 候選字窗會用到的資料池單位。
|
||||
public struct CandidatePool {
|
||||
public class CandidatePool {
|
||||
public var currentRowNumber = 0
|
||||
public var maximumLinesPerPage = 3
|
||||
public private(set) var selectionKeys: String
|
||||
public private(set) var highlightedIndex: Int = 0
|
||||
public private(set) var maxColumnCapacity: Int = 6
|
||||
public private(set) var candidateDataAll: [CandidateCellData] = []
|
||||
public private(set) var candidateRows: [[CandidateCellData]] = []
|
||||
public var maxWindowHeight: Double { ceil(maxWindowWidth * 0.4) }
|
||||
public var isVerticalLayout: Bool { maxColumnCapacity == 1 }
|
||||
public var maxColumnWidth: Int { Int(Double(maxColumnCapacity + 3) * 2) * Int(ceil(CandidateCellData.unifiedSize)) }
|
||||
public var maxWindowHeight: Double { ceil(maxWindowWidth * 0.4 / 2) }
|
||||
public var maxWindowWidth: Double {
|
||||
ceil(Double(maxColumnCapacity + 3) * 2.7 * ceil(CandidateCellData.unifiedSize) * 1.2)
|
||||
}
|
||||
|
||||
public var rangeForCurrentPage: Range<Int> { currentRowNumber..<min(candidateRows.count, currentRowNumber + 6) }
|
||||
public var rangeForCurrentPage: Range<Int> {
|
||||
currentRowNumber..<min(candidateRows.count, currentRowNumber + maximumLinesPerPage)
|
||||
}
|
||||
|
||||
public enum VerticalDirection {
|
||||
case up
|
||||
|
@ -56,7 +59,7 @@ public struct CandidatePool {
|
|||
candidateRows.append(currentColumn)
|
||||
}
|
||||
|
||||
public mutating func selectNewNeighborRow(direction: VerticalDirection) {
|
||||
public func selectNewNeighborRow(direction: VerticalDirection) {
|
||||
let currentSubIndex = candidateDataAll[highlightedIndex].subIndex
|
||||
var result = currentSubIndex
|
||||
switch direction {
|
||||
|
@ -94,7 +97,7 @@ public struct CandidatePool {
|
|||
}
|
||||
}
|
||||
|
||||
public mutating func highlight(at indexSpecified: Int) {
|
||||
public func highlight(at indexSpecified: Int) {
|
||||
var indexSpecified = indexSpecified
|
||||
highlightedIndex = indexSpecified
|
||||
if !(0..<candidateDataAll.count).contains(highlightedIndex) {
|
||||
|
|
|
@ -65,7 +65,7 @@ public class CtlCandidateTDK: CtlCandidate {
|
|||
}
|
||||
|
||||
@discardableResult override public func showNextPage() -> Bool {
|
||||
for _ in 0..<6 {
|
||||
for _ in 0..<thePool.maximumLinesPerPage {
|
||||
thePool.selectNewNeighborRow(direction: .down)
|
||||
}
|
||||
updateDisplay()
|
||||
|
@ -73,7 +73,7 @@ public class CtlCandidateTDK: CtlCandidate {
|
|||
}
|
||||
|
||||
@discardableResult override public func showPreviousPage() -> Bool {
|
||||
for _ in 0..<6 {
|
||||
for _ in 0..<thePool.maximumLinesPerPage {
|
||||
thePool.selectNewNeighborRow(direction: .up)
|
||||
}
|
||||
updateDisplay()
|
||||
|
|
|
@ -21,7 +21,7 @@ struct CandidatePoolViewUI_Previews: PreviewProvider {
|
|||
"吹", "大", "地", "草", "枝", "擺",
|
||||
]
|
||||
static var thePool: CandidatePool {
|
||||
var result = CandidatePool(candidates: testCandidates, columnCapacity: 6)
|
||||
let result = CandidatePool(candidates: testCandidates, columnCapacity: 6)
|
||||
// 下一行待解決:無論這裡怎麼指定高亮選中項是哪一筆,其所在行都得被卷動到使用者眼前。
|
||||
result.highlight(at: 14)
|
||||
return result
|
||||
|
|
Loading…
Reference in New Issue