Voltaire // Beep when recycling pages (each round), etc.

This commit is contained in:
ShikiSuen 2022-05-28 21:58:06 +08:00
parent 03151d4d47
commit a6ddfd500b
2 changed files with 20 additions and 16 deletions

View File

@ -248,7 +248,7 @@ public class ctlCandidateHorizontal: ctlCandidate {
private var candidateView: HorizontalCandidateView private var candidateView: HorizontalCandidateView
private var prevPageButton: NSButton private var prevPageButton: NSButton
private var nextPageButton: NSButton private var nextPageButton: NSButton
private var currentPage: UInt = 0 private var currentPageIndex: UInt = 0
public init() { public init() {
var contentRect = NSRect(x: 128.0, y: 128.0, width: 0.0, height: 0.0) var contentRect = NSRect(x: 128.0, y: 128.0, width: 0.0, height: 0.0)
@ -325,14 +325,15 @@ public class ctlCandidateHorizontal: ctlCandidate {
override public func reloadData() { override public func reloadData() {
candidateView.highlightedIndex = 0 candidateView.highlightedIndex = 0
currentPage = 0 currentPageIndex = 0
layoutCandidateView() layoutCandidateView()
} }
override public func showNextPage() -> Bool { override public func showNextPage() -> Bool {
guard delegate != nil else { return false } guard delegate != nil else { return false }
if pageCount == 1 { return highlightNextCandidate() } if pageCount == 1 { return highlightNextCandidate() }
currentPage = (currentPage + 1 >= pageCount) ? 0 : currentPage + 1 if currentPageIndex + 1 >= pageCount { clsSFX.beep() }
currentPageIndex = (currentPageIndex + 1 >= pageCount) ? 0 : currentPageIndex + 1
candidateView.highlightedIndex = 0 candidateView.highlightedIndex = 0
layoutCandidateView() layoutCandidateView()
return true return true
@ -341,7 +342,8 @@ public class ctlCandidateHorizontal: ctlCandidate {
override public func showPreviousPage() -> Bool { override public func showPreviousPage() -> Bool {
guard delegate != nil else { return false } guard delegate != nil else { return false }
if pageCount == 1 { return highlightPreviousCandidate() } if pageCount == 1 { return highlightPreviousCandidate() }
currentPage = (currentPage == 0) ? pageCount - 1 : currentPage - 1 if currentPageIndex == 0 { clsSFX.beep() }
currentPageIndex = (currentPageIndex == 0) ? pageCount - 1 : currentPageIndex - 1
candidateView.highlightedIndex = 0 candidateView.highlightedIndex = 0
layoutCandidateView() layoutCandidateView()
return true return true
@ -368,13 +370,13 @@ public class ctlCandidateHorizontal: ctlCandidate {
return UInt.max return UInt.max
} }
let result = currentPage * UInt(keyLabels.count) + index let result = currentPageIndex * UInt(keyLabels.count) + index
return result < delegate.candidateCountForController(self) ? result : UInt.max return result < delegate.candidateCountForController(self) ? result : UInt.max
} }
override public var selectedCandidateIndex: UInt { override public var selectedCandidateIndex: UInt {
get { get {
currentPage * UInt(keyLabels.count) + candidateView.highlightedIndex currentPageIndex * UInt(keyLabels.count) + candidateView.highlightedIndex
} }
set { set {
guard let delegate = delegate else { guard let delegate = delegate else {
@ -382,7 +384,7 @@ public class ctlCandidateHorizontal: ctlCandidate {
} }
let keyLabelCount = UInt(keyLabels.count) let keyLabelCount = UInt(keyLabels.count)
if newValue < delegate.candidateCountForController(self) { if newValue < delegate.candidateCountForController(self) {
currentPage = newValue / keyLabelCount currentPageIndex = newValue / keyLabelCount
candidateView.highlightedIndex = newValue % keyLabelCount candidateView.highlightedIndex = newValue % keyLabelCount
layoutCandidateView() layoutCandidateView()
} }
@ -410,7 +412,7 @@ extension ctlCandidateHorizontal {
let count = delegate.candidateCountForController(self) let count = delegate.candidateCountForController(self)
let keyLabelCount = UInt(keyLabels.count) let keyLabelCount = UInt(keyLabels.count)
let begin = currentPage * keyLabelCount let begin = currentPageIndex * keyLabelCount
for index in begin..<min(begin + keyLabelCount, count) { for index in begin..<min(begin + keyLabelCount, count) {
let candidate = delegate.ctlCandidate(self, candidateAtIndex: index) let candidate = delegate.ctlCandidate(self, candidateAtIndex: index)
candidates.append(candidate) candidates.append(candidate)

View File

@ -252,7 +252,7 @@ public class ctlCandidateVertical: ctlCandidate {
private var candidateView: VerticalCandidateView private var candidateView: VerticalCandidateView
private var prevPageButton: NSButton private var prevPageButton: NSButton
private var nextPageButton: NSButton private var nextPageButton: NSButton
private var currentPage: UInt = 0 private var currentPageIndex: UInt = 0
public init() { public init() {
var contentRect = NSRect(x: 128.0, y: 128.0, width: 0.0, height: 0.0) var contentRect = NSRect(x: 128.0, y: 128.0, width: 0.0, height: 0.0)
@ -329,14 +329,15 @@ public class ctlCandidateVertical: ctlCandidate {
override public func reloadData() { override public func reloadData() {
candidateView.highlightedIndex = 0 candidateView.highlightedIndex = 0
currentPage = 0 currentPageIndex = 0
layoutCandidateView() layoutCandidateView()
} }
override public func showNextPage() -> Bool { override public func showNextPage() -> Bool {
guard delegate != nil else { return false } guard delegate != nil else { return false }
if pageCount == 1 { return highlightNextCandidate() } if pageCount == 1 { return highlightNextCandidate() }
currentPage = (currentPage + 1 >= pageCount) ? 0 : currentPage + 1 if currentPageIndex + 1 >= pageCount { clsSFX.beep() }
currentPageIndex = (currentPageIndex + 1 >= pageCount) ? 0 : currentPageIndex + 1
candidateView.highlightedIndex = 0 candidateView.highlightedIndex = 0
layoutCandidateView() layoutCandidateView()
return true return true
@ -345,7 +346,8 @@ public class ctlCandidateVertical: ctlCandidate {
override public func showPreviousPage() -> Bool { override public func showPreviousPage() -> Bool {
guard delegate != nil else { return false } guard delegate != nil else { return false }
if pageCount == 1 { return highlightPreviousCandidate() } if pageCount == 1 { return highlightPreviousCandidate() }
currentPage = (currentPage == 0) ? pageCount - 1 : currentPage - 1 if currentPageIndex == 0 { clsSFX.beep() }
currentPageIndex = (currentPageIndex == 0) ? pageCount - 1 : currentPageIndex - 1
candidateView.highlightedIndex = 0 candidateView.highlightedIndex = 0
layoutCandidateView() layoutCandidateView()
return true return true
@ -372,13 +374,13 @@ public class ctlCandidateVertical: ctlCandidate {
return UInt.max return UInt.max
} }
let result = currentPage * UInt(keyLabels.count) + index let result = currentPageIndex * UInt(keyLabels.count) + index
return result < delegate.candidateCountForController(self) ? result : UInt.max return result < delegate.candidateCountForController(self) ? result : UInt.max
} }
override public var selectedCandidateIndex: UInt { override public var selectedCandidateIndex: UInt {
get { get {
currentPage * UInt(keyLabels.count) + candidateView.highlightedIndex currentPageIndex * UInt(keyLabels.count) + candidateView.highlightedIndex
} }
set { set {
guard let delegate = delegate else { guard let delegate = delegate else {
@ -386,7 +388,7 @@ public class ctlCandidateVertical: ctlCandidate {
} }
let keyLabelCount = UInt(keyLabels.count) let keyLabelCount = UInt(keyLabels.count)
if newValue < delegate.candidateCountForController(self) { if newValue < delegate.candidateCountForController(self) {
currentPage = newValue / keyLabelCount currentPageIndex = newValue / keyLabelCount
candidateView.highlightedIndex = newValue % keyLabelCount candidateView.highlightedIndex = newValue % keyLabelCount
layoutCandidateView() layoutCandidateView()
} }
@ -414,7 +416,7 @@ extension ctlCandidateVertical {
let count = delegate.candidateCountForController(self) let count = delegate.candidateCountForController(self)
let keyLabelCount = UInt(keyLabels.count) let keyLabelCount = UInt(keyLabels.count)
let begin = currentPage * keyLabelCount let begin = currentPageIndex * keyLabelCount
for index in begin..<min(begin + keyLabelCount, count) { for index in begin..<min(begin + keyLabelCount, count) {
let candidate = delegate.ctlCandidate(self, candidateAtIndex: index) let candidate = delegate.ctlCandidate(self, candidateAtIndex: index)
candidates.append(candidate) candidates.append(candidate)