From d73a5497c748b2eeb96cc33020cd913c3f252c48 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Wed, 23 Feb 2022 20:44:43 +0800 Subject: [PATCH] Voltaire // Simplify the conditioning used for page looping. --- .../HorizontalCandidateController.swift | 34 ++++--------------- .../VerticalCandidateController.swift | 34 ++++--------------- 2 files changed, 12 insertions(+), 56 deletions(-) diff --git a/Source/UI/CandidateUI/HorizontalCandidateController.swift b/Source/UI/CandidateUI/HorizontalCandidateController.swift index 35e8e6e8..dfe54f82 100644 --- a/Source/UI/CandidateUI/HorizontalCandidateController.swift +++ b/Source/UI/CandidateUI/HorizontalCandidateController.swift @@ -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 diff --git a/Source/UI/CandidateUI/VerticalCandidateController.swift b/Source/UI/CandidateUI/VerticalCandidateController.swift index 4cae2144..762d178c 100644 --- a/Source/UI/CandidateUI/VerticalCandidateController.swift +++ b/Source/UI/CandidateUI/VerticalCandidateController.swift @@ -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