CtlCandidateTDK // Auto-adjust window height.

This commit is contained in:
ShikiSuen 2022-09-29 13:31:39 +08:00
parent 1be59aa364
commit d531f04fa9
2 changed files with 19 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import Shared
/// ///
public class CandidatePool { public class CandidatePool {
public let blankCell = CandidateCellData(key: " ", displayedText: " ", isSelected: false)
public var currentRowNumber = 0 public var currentRowNumber = 0
public var maximumLinesPerPage = 3 public var maximumLinesPerPage = 3
public private(set) var selectionKeys: String public private(set) var selectionKeys: String
@ -20,7 +21,6 @@ public class CandidatePool {
public private(set) var candidateRows: [[CandidateCellData]] = [] public private(set) var candidateRows: [[CandidateCellData]] = []
public var isVerticalLayout: Bool { maxColumnCapacity == 1 } public var isVerticalLayout: Bool { maxColumnCapacity == 1 }
public var maxColumnWidth: Int { Int(Double(maxColumnCapacity + 3) * 2) * Int(ceil(CandidateCellData.unifiedSize)) } 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 { public var maxWindowWidth: Double {
ceil(Double(maxColumnCapacity + 3) * 2.7 * ceil(CandidateCellData.unifiedSize) * 1.2) ceil(Double(maxColumnCapacity + 3) * 2.7 * ceil(CandidateCellData.unifiedSize) * 1.2)
} }
@ -29,6 +29,8 @@ public class CandidatePool {
currentRowNumber..<min(candidateRows.count, currentRowNumber + maximumLinesPerPage) currentRowNumber..<min(candidateRows.count, currentRowNumber + maximumLinesPerPage)
} }
public var rangeForLastPageBlanked: Range<Int> { 0..<(maximumLinesPerPage - rangeForCurrentPage.count) }
public enum VerticalDirection { public enum VerticalDirection {
case up case up
case down case down

View File

@ -68,9 +68,24 @@ public struct VwrCandidateTDK: View {
).id(columnIndex) ).id(columnIndex)
Divider() 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()) .background(Color(nsColor: NSColor.controlBackgroundColor).ignoresSafeArea())
HStack(alignment: .bottom) { HStack(alignment: .bottom) {
Text(hint).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1) Text(hint).font(.system(size: max(CandidateCellData.unifiedSize * 0.7, 11), weight: .bold)).lineLimit(1)