CtlCandidateTDK // Auto-adjust window height.
This commit is contained in:
parent
1be59aa364
commit
d531f04fa9
|
@ -11,6 +11,7 @@ import Shared
|
|||
|
||||
/// 候選字窗會用到的資料池單位。
|
||||
public class CandidatePool {
|
||||
public let blankCell = CandidateCellData(key: " ", displayedText: " ", isSelected: false)
|
||||
public var currentRowNumber = 0
|
||||
public var maximumLinesPerPage = 3
|
||||
public private(set) var selectionKeys: String
|
||||
|
@ -20,7 +21,6 @@ public class CandidatePool {
|
|||
public private(set) var candidateRows: [[CandidateCellData]] = []
|
||||
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)
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ public class CandidatePool {
|
|||
currentRowNumber..<min(candidateRows.count, currentRowNumber + maximumLinesPerPage)
|
||||
}
|
||||
|
||||
public var rangeForLastPageBlanked: Range<Int> { 0..<(maximumLinesPerPage - rangeForCurrentPage.count) }
|
||||
|
||||
public enum VerticalDirection {
|
||||
case up
|
||||
case down
|
||||
|
|
|
@ -68,9 +68,24 @@ public struct VwrCandidateTDK: View {
|
|||
).id(columnIndex)
|
||||
Divider()
|
||||
}
|
||||
if thePool.maximumLinesPerPage - thePool.rangeForCurrentPage.count > 0 {
|
||||
ForEach(thePool.rangeForLastPageBlanked, id: \.self) { _ in
|
||||
HStack(spacing: 0) {
|
||||
thePool.blankCell.attributedStringForSwiftUI.fixedSize()
|
||||
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||
.contentShape(Rectangle())
|
||||
Spacer()
|
||||
}.frame(
|
||||
minWidth: 0,
|
||||
maxWidth: .infinity,
|
||||
alignment: .topLeading
|
||||
)
|
||||
Divider()
|
||||
}
|
||||
}
|
||||
.frame(minHeight: thePool.maxWindowHeight, maxHeight: thePool.maxWindowHeight).padding(5)
|
||||
}
|
||||
}
|
||||
.fixedSize(horizontal: false, vertical: true).padding(5)
|
||||
.background(Color(nsColor: NSColor.controlBackgroundColor).ignoresSafeArea())
|
||||
HStack(alignment: .bottom) {
|
||||
Text(hint).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1)
|
||||
|
|
Loading…
Reference in New Issue