TDKCandidates // Fix calculation mistakes in horizontal layout.

This commit is contained in:
ShikiSuen 2023-02-06 17:25:27 +08:00
parent aa99475645
commit ad1a96160b
3 changed files with 8 additions and 15 deletions

View File

@ -31,10 +31,9 @@ public struct CandidatePool {
// MARK: - // MARK: -
public var maxRowWidth: Int { Int(Double(maxRowCapacity + 3) * 2) * Int(ceil(CandidateCellData.unifiedSize)) } public var maxRowWidth: Int { Int(ceil((Double(maxRowCapacity + 3) * 2 - 0.5) * CandidateCellData.unifiedSize)) }
public var maxWindowWidth: Double { public var maxWindowWidth: Double {
let testCell = CandidateCellData(key: "XX", displayedText: "XX", isSelected: false) Double(maxRowCapacity) * (blankCell.minWidthToDrawInSwiftUI + ceil(CandidateCellData.unifiedSize * 0.5))
return Double(maxRowCapacity) * (testCell.minWidthToDrawInSwiftUI + ceil(CandidateCellData.unifiedSize * 0.5))
} }
public var currentLineNumber: Int { public var currentLineNumber: Int {

View File

@ -66,10 +66,7 @@ public struct VwrCandidateHorizontal: View {
ForEach(Array(thePool.candidateLines[rowIndex]), id: \.self) { currentCandidate in ForEach(Array(thePool.candidateLines[rowIndex]), id: \.self) { currentCandidate in
currentCandidate.attributedStringForSwiftUI.fixedSize() currentCandidate.attributedStringForSwiftUI.fixedSize()
.contentShape(Rectangle()) .contentShape(Rectangle())
.frame( .frame(alignment: .topLeading)
maxWidth: .infinity,
alignment: .topLeading
)
.onTapGesture { didSelectCandidateAt(currentCandidate.index) } .onTapGesture { didSelectCandidateAt(currentCandidate.index) }
.contextMenu { .contextMenu {
if controller?.delegate?.isCandidateContextMenuEnabled ?? false { if controller?.delegate?.isCandidateContextMenuEnabled ?? false {
@ -91,7 +88,7 @@ public struct VwrCandidateHorizontal: View {
} }
} }
} }
Spacer(minLength: Double.infinity) Spacer()
}.frame( }.frame(
minWidth: 0, minWidth: 0,
maxWidth: .infinity, maxWidth: .infinity,
@ -104,7 +101,7 @@ public struct VwrCandidateHorizontal: View {
HStack(spacing: 0) { HStack(spacing: 0) {
thePool.blankCell.attributedStringForSwiftUI thePool.blankCell.attributedStringForSwiftUI
.contentShape(Rectangle()) .contentShape(Rectangle())
.frame(maxWidth: .infinity, alignment: .topLeading) .frame(alignment: .topLeading)
Spacer() Spacer()
}.frame( }.frame(
minWidth: 0, minWidth: 0,

View File

@ -67,10 +67,7 @@ public struct VwrCandidateHorizontalBackports: View {
ForEach(Array(thePool.candidateLines[rowIndex]), id: \.self) { currentCandidate in ForEach(Array(thePool.candidateLines[rowIndex]), id: \.self) { currentCandidate in
currentCandidate.attributedStringForSwiftUIBackports.fixedSize() currentCandidate.attributedStringForSwiftUIBackports.fixedSize()
.contentShape(Rectangle()) .contentShape(Rectangle())
.frame( .frame(alignment: .topLeading)
maxWidth: .infinity,
alignment: .topLeading
)
.onTapGesture { didSelectCandidateAt(currentCandidate.index) } .onTapGesture { didSelectCandidateAt(currentCandidate.index) }
.contextMenu { .contextMenu {
if controller?.delegate?.isCandidateContextMenuEnabled ?? false { if controller?.delegate?.isCandidateContextMenuEnabled ?? false {
@ -92,7 +89,7 @@ public struct VwrCandidateHorizontalBackports: View {
} }
} }
} }
Spacer(minLength: Double.infinity) Spacer()
}.frame( }.frame(
minWidth: 0, minWidth: 0,
maxWidth: .infinity, maxWidth: .infinity,
@ -105,7 +102,7 @@ public struct VwrCandidateHorizontalBackports: View {
HStack(spacing: 0) { HStack(spacing: 0) {
thePool.blankCell.attributedStringForSwiftUIBackports thePool.blankCell.attributedStringForSwiftUIBackports
.contentShape(Rectangle()) .contentShape(Rectangle())
.frame(maxWidth: .infinity, alignment: .topLeading) .frame(alignment: .topLeading)
Spacer() Spacer()
}.frame( }.frame(
minWidth: 0, minWidth: 0,