2424import Cocoa
2525
2626private protocol HorizontalCandidateViewDelegate : AnyObject {
27- func view( _ view: HorizontalCandidateView , didRequestExplanationFor candidate: String , reading: String ) -> String ?
27+ func view(
28+ _ view: HorizontalCandidateView , didRequestExplanationFor candidate: String , reading: String
29+ ) -> String ?
2830}
2931
3032private class HorizontalCandidateView : NSView {
@@ -38,9 +40,10 @@ private class HorizontalCandidateView: NSView {
3840 let reading : String ?
3941 let rect : NSRect
4042
41- init ( owner: HorizontalCandidateView , index: UInt ,
42- candidate: String , reading: String ? , rect: NSRect )
43- {
43+ init (
44+ owner: HorizontalCandidateView , index: UInt ,
45+ candidate: String , reading: String ? , rect: NSRect
46+ ) {
4447 self . owner = owner
4548 self . index = index
4649 self . candidate = candidate
@@ -132,14 +135,17 @@ private class HorizontalCandidateView: NSView {
132135 return result
133136 }
134137
135- func set( keyLabels labels: [ String ] , displayedCandidates candidates: [ ( candidate: String , reading: String ? ) ] ) {
138+ func set(
139+ keyLabels labels: [ String ] ,
140+ displayedCandidates candidates: [ ( candidate: String , reading: String ? ) ]
141+ ) {
136142 let count = min ( labels. count, candidates. count)
137- keyLabels = Array ( labels [ 0 ..< count] )
138- displayedCandidates = Array ( candidates [ 0 ..< count] )
143+ keyLabels = Array ( labels [ 0 ..< count] )
144+ displayedCandidates = Array ( candidates [ 0 ..< count] )
139145
140146 var newWidths = [ CGFloat] ( )
141147 let baseSize = NSSize ( width: 10240.0 , height: 10240.0 )
142- for index in 0 ..< count {
148+ for index in 0 ..< count {
143149 let labelRect = ( keyLabels [ index] as NSString ) . boundingRect (
144150 with: baseSize, options: . usesLineFragmentOrigin, attributes: keyLabelAttrDict
145151 )
@@ -222,7 +228,7 @@ private class HorizontalCandidateView: NSView {
222228 }
223229
224230 var accuWidth : CGFloat = 0
225- for index in 0 ..< elementWidths. count {
231+ for index in 0 ..< elementWidths. count {
226232 let currentWidth = elementWidths [ index]
227233 let labelRect = NSRect (
228234 x: accuWidth, y: tooltipSize. height, width: currentWidth, height: keyLabelHeight
@@ -280,7 +286,7 @@ private class HorizontalCandidateView: NSView {
280286 return nil
281287 }
282288 var accuWidth : CGFloat = 0.0
283- for index in 0 ..< elementWidths. count {
289+ for index in 0 ..< elementWidths. count {
284290 let currentWidth = elementWidths [ index]
285291
286292 if location. x >= accuWidth, location. x <= accuWidth + currentWidth {
@@ -330,12 +336,13 @@ private class HorizontalCandidateView: NSView {
330336 fileprivate func buildAccessibilityChildren( ) {
331337 func accessibilityFrameForCandidate( at index: Int ) -> NSRect {
332338 var accuWidth : CGFloat = 0
333- for i in 0 ..< index {
339+ for i in 0 ..< index {
334340 accuWidth += elementWidths [ i] + 1.0
335341 }
336342 let width = elementWidths [ index]
337343 let height = keyLabelHeight + candidateTextHeight + 1.0
338- let rectInView = NSRect ( x: accuWidth, y: tooltipSize. height, width: width, height: height)
344+ let rectInView = NSRect (
345+ x: accuWidth, y: tooltipSize. height, width: width, height: height)
339346 return rectInView
340347 }
341348
@@ -554,7 +561,9 @@ public class HorizontalCandidateController: CandidateController {
554561}
555562
556563extension HorizontalCandidateController : HorizontalCandidateViewDelegate {
557- fileprivate func view( _ view: HorizontalCandidateView , didRequestExplanationFor candidate: String , reading: String ) -> String ? {
564+ fileprivate func view(
565+ _ view: HorizontalCandidateView , didRequestExplanationFor candidate: String , reading: String
566+ ) -> String ? {
558567 delegate? . candidateController ( self , requestExplanationFor: candidate, reading: reading)
559568 }
560569}
@@ -580,12 +589,13 @@ extension HorizontalCandidateController {
580589 let keyLabelCount = UInt ( keyLabels. count)
581590
582591 let begin = currentPage * keyLabelCount
583- for index in begin ..< min ( begin + keyLabelCount, count) {
592+ for index in begin..< min ( begin + keyLabelCount, count) {
584593 let candidate = delegate. candidateController ( self , candidateAtIndex: index)
585594 let reading = delegate. candidateController ( self , readingAtIndex: index)
586595 candidates. append ( ( candidate, reading) )
587596 }
588- candidateView. set ( keyLabels: keyLabels. map { $0. displayedText } , displayedCandidates: candidates)
597+ candidateView. set (
598+ keyLabels: keyLabels. map { $0. displayedText } , displayedCandidates: candidates)
589599 candidateView. toolTip = tooltip
590600 var newSize = candidateView. sizeForView
591601 var frameRect = candidateView. frame
0 commit comments