Voltaire // Simplify the conditioning used for page looping.

This commit is contained in:
ShikiSuen 2022-02-23 20:44:43 +08:00
parent 6c72e6416a
commit 958757624b
2 changed files with 12 additions and 56 deletions

View File

@ -255,40 +255,18 @@ public class HorizontalCandidateController: CandidateController {
} }
public override func showNextPage() -> Bool { public override func showNextPage() -> Bool {
guard delegate != nil else { guard delegate != nil else {return false}
return false if pageCount == 1 {return highlightNextCandidate()}
} currentPage = (currentPage + 1 >= pageCount) ? 0 : currentPage + 1
if pageCount == 1 {
return highlightNextCandidate()
}
if currentPage + 1 >= pageCount {
currentPage = 0
} else {
currentPage += 1
}
candidateView.highlightedIndex = 0 candidateView.highlightedIndex = 0
layoutCandidateView() layoutCandidateView()
return true return true
} }
public override func showPreviousPage() -> Bool { public override func showPreviousPage() -> Bool {
guard delegate != nil else { guard delegate != nil else {return false}
return false if pageCount == 1 {return highlightPreviousCandidate()}
} currentPage = (currentPage == 0) ? pageCount - 1 : currentPage - 1
if pageCount == 1 {
return highlightPreviousCandidate()
}
if currentPage == 0 {
currentPage = pageCount - 1
} else {
currentPage -= 1
}
candidateView.highlightedIndex = 0 candidateView.highlightedIndex = 0
layoutCandidateView() layoutCandidateView()
return true return true

View File

@ -261,40 +261,18 @@ public class VerticalCandidateController: CandidateController {
} }
public override func showNextPage() -> Bool { public override func showNextPage() -> Bool {
guard delegate != nil else { guard delegate != nil else {return false}
return false if pageCount == 1 {return highlightNextCandidate()}
} currentPage = (currentPage + 1 >= pageCount) ? 0 : currentPage + 1
if pageCount == 1 {
return highlightNextCandidate()
}
if currentPage + 1 >= pageCount {
currentPage = 0
} else {
currentPage += 1
}
candidateView.highlightedIndex = 0 candidateView.highlightedIndex = 0
layoutCandidateView() layoutCandidateView()
return true return true
} }
public override func showPreviousPage() -> Bool { public override func showPreviousPage() -> Bool {
guard delegate != nil else { guard delegate != nil else {return false}
return false if pageCount == 1 {return highlightPreviousCandidate()}
} currentPage = (currentPage == 0) ? pageCount - 1 : currentPage - 1
if pageCount == 1 {
return highlightPreviousCandidate()
}
if currentPage == 0 {
currentPage = pageCount - 1
} else {
currentPage -= 1
}
candidateView.highlightedIndex = 0 candidateView.highlightedIndex = 0
layoutCandidateView() layoutCandidateView()
return true return true