Voltaire // Simplify the conditioning used for page looping.

This commit is contained in:
ShikiSuen 2022-02-23 20:44:43 +08:00
parent 23792e7162
commit dab9714567
2 changed files with 12 additions and 56 deletions

View File

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

View File

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