KMHomePopViewController.swift 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. //
  2. // KMHomePopViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2022/10/17.
  6. //
  7. import Cocoa
  8. typealias popCellViewDownCallback = (_ downEntered: Bool, _ count: String) -> Void
  9. typealias popCellViewWillShow = (_ cellView: KMBox, _ index: Int) -> Void
  10. @objcMembers class KMHomePopViewController: NSViewController {
  11. @IBOutlet weak var customBox: NSBox!
  12. @IBOutlet weak var customBoxWidthLayoutConstraint: NSLayoutConstraint!
  13. @IBOutlet weak var customBoxHeightLayoutConstraint: NSLayoutConstraint!
  14. var downCallback: popCellViewDownCallback?
  15. var viewWillShow: popCellViewWillShow?
  16. var popCellViewDownString: String?
  17. var popCellCount: Int?
  18. var dataArr: [String]?
  19. var KMHorizontalLine: String = "KMHorizontalLine"
  20. var enterFillColor : NSColor = KMDesignToken.shared.fill(withToken: "dropdown.m.bg.hov")
  21. var textColor : NSColor = .black // 背景颜色
  22. var background : NSColor = .white // 背景颜色
  23. var background_hov : NSColor = .clear // 背景颜色
  24. var background_sel : NSColor = .clear // 背景颜色
  25. var background_disabled : NSColor = .clear // 背景颜色
  26. var cornerRadius : Float = 0.0 // 边框圆角
  27. var cornerRadius_hov : Float = 0.0 // 边框圆角
  28. var cornerRadius_sel : Float = 0.0 // 边框圆角
  29. var cornerRadius_disabled : Float = 0.0 // 边框圆角
  30. var lineHeight : CGFloat = 20.0 // 默认 内容行高
  31. var lineHeight_hov : CGFloat = 20.0 // 默认 内容行高
  32. var lineHeight_sel : CGFloat = 20.0 // 默认 内容行高
  33. var lineHeight_disabled : CGFloat = 20.0 // 默认 内容行高
  34. var font : NSFont = NSFont.systemFont(ofSize: 14.0) // 内容字体
  35. var font_hov : NSFont = NSFont.systemFont(ofSize: 14.0) // 内容字体
  36. var font_sel : NSFont = NSFont.systemFont(ofSize: 14.0) // 内容字体
  37. var font_disabled : NSFont = NSFont.systemFont(ofSize: 14.0) // 内容字体
  38. var _state: KMDesignTokenState = .Norm
  39. var enabled: Bool = true // 是否可点击
  40. var canHover: Bool = true // 是否可悬浮
  41. var disItems: [String] = []
  42. var selectedItems: [String] = []
  43. var showVerticalScroller: Bool = false
  44. func initWithPopViewDataArr(_ popViewDataArr: [String]) -> Self {
  45. // self.dataArr = popViewDataArr.reverseObjectEnumerator().allObjects as NSArray
  46. self.dataArr = popViewDataArr.reversed()
  47. return self
  48. }
  49. override func viewDidLoad() {
  50. super.viewDidLoad()
  51. customBox.fillColor = background//NSColor.km_init(hex: "#FFFFFF")
  52. // self.updateUI()
  53. }
  54. override func viewDidAppear() {
  55. super.viewDidAppear()
  56. self.updateUI()
  57. }
  58. // MARK: Private
  59. func updateUI() {
  60. customBox.fillColor = background
  61. var widthMax: Float = 0;
  62. let subViews: [NSView] = self.customBox.contentView!.subviews
  63. for subView in subViews {
  64. subView.removeFromSuperview()
  65. }
  66. for string in self.dataArr ?? [] {
  67. if !(string as AnyObject).isEqual(to: KMHorizontalLine) {
  68. let width = self.cellContentAdaptiveWidth(string)
  69. if widthMax < width {
  70. widthMax = width
  71. }
  72. }
  73. }
  74. var formTopFloat: Float = 4.0
  75. // for i in (0..<dataArr!.count).reversed() {
  76. for string in dataArr?.reversed() ?? [] {
  77. if (string as AnyObject).isEqual(to: KMHorizontalLine) {
  78. self.createHonrizontalLineWithFrame(CGRect(x: 12.0, y: CGFloat(formTopFloat), width: CGFloat(widthMax)+23, height: 11))
  79. formTopFloat += 11
  80. } else {
  81. popCellViewDownString = string
  82. // self.createPopViewCellLabelWithFrame(CGRect(x: 4.0, y: CGFloat(formTopFloat), width: CGFloat(widthMax)+47, height: 32), stringValue: string)
  83. createPopViewCellLabelWithFrame(formTopFloat, stringValue: string)
  84. formTopFloat += 32;
  85. }
  86. }
  87. customBoxWidthLayoutConstraint.constant = CGFloat(widthMax+47)
  88. customBoxHeightLayoutConstraint.constant = CGFloat(formTopFloat+4.0)
  89. }
  90. func createHonrizontalLineWithFrame(_ frame: CGRect) {
  91. let box: NSBox = NSBox.init(frame: frame)
  92. box.boxType = .custom
  93. box.borderWidth = 0.0
  94. box.contentViewMargins = NSMakeSize(0, 0)
  95. customBox.contentView?.addSubview(box)
  96. box.mas_makeConstraints { (make) in
  97. make?.leading.equalTo()(frame.origin.x)
  98. make?.trailing.equalTo()(-frame.origin.x)
  99. make?.height.equalTo()(frame.size.height)
  100. make?.top.equalTo()(customBox.mas_top)?.offset()(CGFloat(frame.origin.y))
  101. }
  102. let lineBox = NSBox.init(frame: CGRect(x: 0, y: 6, width: frame.width, height: 1))
  103. lineBox.boxType = .separator
  104. box.addSubview(lineBox)
  105. }
  106. // func createPopViewCellLabelWithFrame(_ frame: CGRect, stringValue: String) {
  107. // let box: KMBox = KMBox(frame: frame)
  108. // box.boxType = .custom
  109. // box.borderWidth = 0.0
  110. // box.contentViewMargins = NSMakeSize(0, 0)
  111. // customBox.contentView?.addSubview(box)
  112. //
  113. // let boxLabel: NSTextField = NSTextField.init()
  114. // boxLabel.isEditable = false
  115. // boxLabel.isBordered = false
  116. // boxLabel.stringValue = stringValue
  117. // boxLabel.font = NSFont.systemFont(ofSize: 14.0)
  118. // boxLabel.translatesAutoresizingMaskIntoConstraints = false
  119. // boxLabel.backgroundColor = NSColor.clear
  120. // boxLabel.textColor = NSColor.labelColor
  121. // box.contentView?.addSubview(boxLabel)
  122. //
  123. // box.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-21-[boxLabel]-21-|", metrics: nil, views:["boxLabel": boxLabel]))
  124. // box.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-1-[boxLabel]-1-|", metrics: nil, views:["boxLabel": boxLabel]))
  125. //
  126. // box.contentView?.addConstraint(NSLayoutConstraint(item: boxLabel, attribute:.centerY , relatedBy: .equal, toItem: box.contentView, attribute: .centerY, multiplier: 1, constant: 0))
  127. // box.moveCallback = {(mouseEntered: Bool, mouseBox: KMBox) -> Void in
  128. // if mouseEntered {
  129. // if #available(macOS 10.14, *) {
  130. // box.fillColor = NSColor.controlAccentColor
  131. // boxLabel.textColor = NSColor.white
  132. // } else {
  133. // box.fillColor = NSColor.init(red: 71/255.0, green: 126/255.0, blue: 222/255.0, alpha: 1.0)
  134. // boxLabel.textColor = NSColor.white
  135. // }
  136. // } else {
  137. // box.fillColor = NSColor.clear
  138. // boxLabel.textColor = NSColor.labelColor
  139. // }
  140. // }
  141. // box.downCallback = {(downEntered: Bool, mouseBox: KMBox) -> Void in
  142. // if downEntered {
  143. // if let callback = self.downCallback {
  144. // callback(true, stringValue)
  145. // }
  146. // }
  147. // }
  148. // }
  149. func createPopViewCellLabelWithFrame(_ mas_top: Float, stringValue: String) {
  150. var isDisabled = false
  151. if disItems.contains(stringValue) {
  152. isDisabled = true
  153. }
  154. var isSelected = false
  155. if (isDisabled == false && self.selectedItems.contains(stringValue)) {
  156. isSelected = true
  157. }
  158. let box: KMBox = KMBox(frame: NSZeroRect)
  159. box.boxType = .custom
  160. box.borderWidth = 0.0
  161. box.contentViewMargins = NSMakeSize(0, 0)
  162. box.cornerRadius = 4.0
  163. customBox.contentView?.addSubview(box)
  164. box.mas_makeConstraints { (make) in
  165. make?.leading.equalTo()(4.0)
  166. make?.trailing.equalTo()(-4.0)
  167. make?.height.equalTo()(32.0)
  168. make?.top.equalTo()(customBox.mas_top)?.offset()(CGFloat(mas_top))
  169. }
  170. // let dropdownVC = KMDesignDropdown.init(nibName: "KMDesignDropdown", bundle: nil)
  171. // box.contentView = dropdownVC.view
  172. // dropdownVC.dropdown(bg: "dropdown.m.bg.norm", text: "dropdown.m.mac-text.def")
  173. // dropdownVC.dropdown(bg: "dropdown.m.bg.hov", text: "dropdown.m.mac-text.def", state: .Hov)
  174. // dropdownVC.dropdown(bg: "dropdown.m.bg.sel", text: "dropdown.m.mac-text.sel", state: .Sel)
  175. // dropdownVC.dropdown(bg: "dropdown.m.bg.dis", text: "dropdown.m.mac-text.dis", state: .Disabled)
  176. // dropdownVC.stringValue = str
  177. let boxLabel: NSTextField = NSTextField.init()
  178. boxLabel.isEditable = false
  179. boxLabel.isBordered = false
  180. boxLabel.stringValue = stringValue
  181. boxLabel.font = NSFont.systemFont(ofSize: 14.0)
  182. boxLabel.translatesAutoresizingMaskIntoConstraints = false
  183. boxLabel.backgroundColor = NSColor.clear
  184. boxLabel.textColor = textColor//NSColor.km_init(hex: "#252629")
  185. box.contentView?.addSubview(boxLabel)
  186. boxLabel.mas_makeConstraints { (make) in
  187. make?.centerY.equalTo()(0.0)
  188. make?.leading.equalTo()(8.0)
  189. }
  190. let textTypography = KMDesignToken.shared.typography(withToken: "dropdown.m.mac-text.def")
  191. var fontFamily: String = textTypography.fontFamily
  192. let fontWeight: String = textTypography.fontWeight
  193. if fontFamily.contains(" ") {
  194. fontFamily = fontFamily.replacingOccurrences(of: " ", with: "")
  195. }
  196. if fontWeight != "" {
  197. fontFamily = String(format: "%@-%@", fontFamily, fontWeight)
  198. }
  199. boxLabel.font = NSFont(name: fontFamily, size: textTypography.fontSize.stringToCGFloat()) ?? NSFont.systemFont(ofSize: textTypography.fontSize.stringToCGFloat())
  200. let paragraphStyle = NSMutableParagraphStyle()
  201. paragraphStyle.lineSpacing = textTypography.lineHeight.stringToCGFloat()
  202. boxLabel.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  203. box.moveCallback = {(mouseEntered: Bool, mouseBox: KMBox) -> Void in
  204. if !isDisabled {
  205. if isSelected { // 选中没有 hover 效果
  206. return
  207. }
  208. if mouseEntered {
  209. mouseBox.fillColor = self.enterFillColor
  210. } else {
  211. mouseBox.fillColor = NSColor.clear
  212. }
  213. }
  214. }
  215. box.downCallback = {(downEntered, mouseBox, event) -> Void in
  216. if !isDisabled {
  217. if downEntered {
  218. mouseBox.fillColor = KMDesignToken.shared.fill(withToken: "dropdown.m.bg.sel")
  219. boxLabel.textColor = KMDesignToken.shared.fill(withToken: "dropdown.m.mac-text.sel")
  220. if let callback = self.downCallback {
  221. callback(true, stringValue)
  222. }
  223. } else {
  224. mouseBox.fillColor = KMDesignToken.shared.fill(withToken: "dropdown.m.bg.norm")
  225. boxLabel.textColor = KMDesignToken.shared.fill(withToken: "dropdown.m.mac-text.def")
  226. }
  227. }
  228. }
  229. if isDisabled {
  230. box.fillColor = KMDesignToken.shared.fill(withToken: "dropdown.m.bg.dis")
  231. boxLabel.textColor = KMDesignToken.shared.fill(withToken: "dropdown.m.mac-text.dis")
  232. } else if (isSelected) {
  233. box.fillColor = KMDesignToken.shared.fill(withToken: "dropdown.m.bg.sel")
  234. boxLabel.textColor = KMDesignToken.shared.fill(withToken: "dropdown.m.mac-text.sel")
  235. }
  236. let idx = self.dataArr?.index(of: stringValue) ?? 0
  237. self.viewWillShow?(box, idx)
  238. }
  239. func cellContentAdaptiveWidth(_ content: String) -> Float {
  240. if content.isEmpty {
  241. return 0
  242. }
  243. let attributes = [NSAttributedString.Key.font : NSFont.systemFont(ofSize: 14.0)]
  244. let rect : CGRect = content.boundingRect(with: CGSize(width: 0, height: 18),options: .usesLineFragmentOrigin, attributes: attributes,context:nil)
  245. return Float(rect.size.width)
  246. }
  247. func changePopViewCellData(_ count: Int, content: String) {
  248. let boxArray: Array<NSView> = customBox.contentView!.subviews
  249. for subView in boxArray {
  250. subView.removeFromSuperview()
  251. }
  252. var dataMutableArr: [String] = Array((dataArr?.reversed())!)
  253. dataMutableArr[count] = content
  254. dataArr = Array(dataMutableArr.reversed())
  255. self.updateUI()
  256. }
  257. // MARK: - Init Views
  258. fileprivate func initBoxLabel() -> NSTextField {
  259. let label = NSTextField.init()
  260. label.isEditable = false
  261. label.isBordered = false
  262. label.font = NSFont.systemFont(ofSize: 14.0)
  263. label.translatesAutoresizingMaskIntoConstraints = false
  264. label.backgroundColor = NSColor.clear
  265. label.textColor = NSColor.km_init(hex: "#252629")
  266. return label
  267. }
  268. }
  269. class KMScrollPopViewController: KMHomePopViewController {
  270. private var scrollView = NSScrollView()
  271. private var contentView = NSView()
  272. private var currentItemPosition: NSPoint = .zero
  273. convenience init() {
  274. self.init(nibName: "KMHomePopViewController", bundle: nil)
  275. }
  276. override func viewDidLoad() {
  277. super.viewDidLoad()
  278. self.view.addSubview(self.scrollView)
  279. self.scrollView.documentView = self.contentView
  280. // self.scrollView.documentView?.backgroundColor(NSColor.km_init(hex: "#FFFFFF"))
  281. // customBox.fillColor = NSColor.km_init(hex: "#FFFFFF")
  282. self.scrollView.documentView?.backgroundColor(self.background)
  283. self.scrollView.hasVerticalScroller = self.showVerticalScroller
  284. self.scrollView.borderType = .noBorder
  285. self.scrollView.drawsBackground = false
  286. }
  287. override func viewDidAppear() {
  288. super.viewDidAppear()
  289. DispatchQueue.main.async {
  290. let contentView = self.scrollView.contentView
  291. let pageH = NSHeight(self.scrollView.bounds)
  292. // KMPrint(NSHeight(self.contentView.bounds))
  293. // KMPrint(pageH)
  294. // KMPrint(self.currentItemPosition)
  295. var numberPages: Int = 0
  296. var currentPage: Int = 0
  297. var scrollY: CGFloat = 0
  298. if (pageH > 0) {
  299. numberPages = Int(NSHeight(self.contentView.bounds) / pageH) + 1
  300. currentPage = Int((self.currentItemPosition.y + 32 + 4 * 2) / pageH)
  301. // KMPrint(numberPages)
  302. // KMPrint(currentPage)
  303. // let _currentPage = numberPages - currentPage - 1
  304. // KMPrint(_currentPage)
  305. if (currentPage == (numberPages - 1)) {
  306. scrollY = 0
  307. } else {
  308. scrollY = NSHeight(self.contentView.bounds) - pageH * CGFloat(currentPage+1)
  309. }
  310. }
  311. // KMPrint(scrollY)
  312. contentView.scroll(to: NSPoint(x: 0, y: scrollY))
  313. }
  314. }
  315. override func viewDidLayout() {
  316. super.viewDidLayout()
  317. self.scrollView.frame = NSMakeRect(0, 0, NSWidth(self.view.frame), NSHeight(self.view.window!.frame))
  318. self.contentView.frame = NSMakeRect(0, 0, NSWidth(self.customBox.frame), NSHeight(self.customBox.frame)+30)
  319. // self.contentView.frame = self.customBox.bounds
  320. }
  321. override func updateUI() {
  322. super.updateUI()
  323. customBox.fillColor = background
  324. var widthMax: Float = 0
  325. for subView in self.contentView.subviews {
  326. subView.removeFromSuperview()
  327. }
  328. for string in self.dataArr ?? [] {
  329. if ((string as AnyObject).isEqual(to: KMHorizontalLine)) {
  330. continue
  331. }
  332. let width = self.cellContentAdaptiveWidth(string)
  333. if (widthMax < width) {
  334. widthMax = width
  335. }
  336. }
  337. var formTopFloat: Float = 4.0
  338. for string in dataArr?.reversed() ?? [] {
  339. if (string as AnyObject).isEqual(to: KMHorizontalLine) {
  340. self.createHonrizontalLineWithFrame(CGRect(x: 12.0, y: CGFloat(formTopFloat), width: CGFloat(widthMax)+23, height: 11))
  341. formTopFloat += 11
  342. } else {
  343. self.popCellViewDownString = string
  344. self.createPopViewCellLabelWithFrame(formTopFloat, stringValue: string)
  345. formTopFloat += 32
  346. }
  347. }
  348. self.customBoxWidthLayoutConstraint.constant = CGFloat(widthMax+47)
  349. self.customBoxHeightLayoutConstraint.constant = CGFloat(formTopFloat+4.0)
  350. }
  351. override func createHonrizontalLineWithFrame(_ frame: CGRect) {
  352. let box: NSBox = NSBox.init(frame: frame)
  353. box.boxType = .custom
  354. box.borderWidth = 0.0
  355. box.contentViewMargins = NSMakeSize(0, 0)
  356. self.contentView.addSubview(box)
  357. let lineBox = NSBox.init(frame: CGRect(x: 0, y: 6, width: frame.width, height: 1))
  358. lineBox.boxType = .separator
  359. box.addSubview(lineBox)
  360. }
  361. override func createPopViewCellLabelWithFrame(_ mas_top: Float, stringValue: String) {
  362. var isDisabled = false
  363. if (self.disItems.contains(stringValue)) {
  364. isDisabled = true
  365. }
  366. var isSelected = false
  367. if (isDisabled == false && self.selectedItems.contains(stringValue)) {
  368. isSelected = true
  369. }
  370. if (isSelected && self.selectedItems.first == stringValue) {
  371. self.currentItemPosition = NSPoint(x: 0, y: Int(mas_top))
  372. }
  373. let box: KMBox = KMBox(frame: NSZeroRect)
  374. box.boxType = .custom
  375. box.borderWidth = 0.0
  376. box.contentViewMargins = NSMakeSize(0, 0)
  377. box.cornerRadius = 4.0
  378. self.contentView.addSubview(box)
  379. box.mas_makeConstraints { (make) in
  380. make?.leading.equalTo()(4.0)
  381. make?.trailing.equalTo()(-4.0)
  382. make?.height.equalTo()(32.0)
  383. make?.top.equalTo()(self.customBox.mas_top)?.offset()(CGFloat(mas_top))
  384. }
  385. let boxLabel = self.initBoxLabel()
  386. boxLabel.stringValue = stringValue
  387. box.contentView?.addSubview(boxLabel)
  388. boxLabel.mas_makeConstraints { (make) in
  389. make?.centerY.equalTo()(0.0)
  390. make?.leading.equalTo()(8.0)
  391. make?.trailing.mas_equalTo()(0)
  392. }
  393. let textTypography = KMDesignToken.shared.typography(withToken: "dropdown.m.mac-text.def")
  394. var fontFamily: String = textTypography.fontFamily
  395. let fontWeight: String = textTypography.fontWeight
  396. if (fontFamily.contains(" ")) {
  397. fontFamily = fontFamily.replacingOccurrences(of: " ", with: "")
  398. }
  399. if (fontWeight != "") {
  400. fontFamily = String(format: "%@-%@", fontFamily, fontWeight)
  401. }
  402. if NSFont(name: stringValue, size: 12) != nil {
  403. fontFamily = stringValue
  404. } else {
  405. debugPrint("不支持字体" + stringValue)
  406. }
  407. if stringValue == "Al Tarikh" ||
  408. stringValue == "Corsiva Hebrew" ||
  409. stringValue == "DIN Condensed" ||
  410. stringValue == "Damascus" {
  411. // boxLabel.font = NSFont.systemFont(ofSize: 14)
  412. // boxLabel.stringValue = stringValue
  413. boxLabel.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.font : NSFont.systemFont(ofSize: 14)])
  414. } else {
  415. boxLabel.font = NSFont(name: fontFamily, size: textTypography.fontSize.stringToCGFloat()) ?? NSFont.systemFont(ofSize: textTypography.fontSize.stringToCGFloat())
  416. let paragraphStyle = NSMutableParagraphStyle()
  417. paragraphStyle.lineSpacing = textTypography.lineHeight.stringToCGFloat()
  418. boxLabel.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  419. }
  420. if (isDisabled) {
  421. box.fillColor = KMDesignToken.shared.fill(withToken: "dropdown.m.bg.dis")
  422. boxLabel.textColor = KMDesignToken.shared.fill(withToken: "dropdown.m.mac-text.dis")
  423. } else if (isSelected) {
  424. box.fillColor = KMDesignToken.shared.fill(withToken: "dropdown.m.bg.sel")
  425. boxLabel.textColor = KMDesignToken.shared.fill(withToken: "dropdown.m.mac-text.sel")
  426. } else {
  427. boxLabel.textColor = self.textColor
  428. }
  429. box.moveCallback = { mouseEntered, mouseBox in
  430. if (isDisabled) {
  431. return
  432. }
  433. if (isSelected) { // 选中没有 hover 效果
  434. return
  435. }
  436. // if (mouseEntered) {
  437. // mouseBox.fillColor = KMDesignToken.shared.fill(withToken: "dropdown.m.bg.hov")
  438. // } else {
  439. // mouseBox.fillColor = NSColor.clear
  440. // }
  441. if mouseEntered {
  442. mouseBox.fillColor = self.enterFillColor
  443. } else {
  444. mouseBox.fillColor = NSColor.clear
  445. }
  446. }
  447. box.downCallback = { [unowned self] downEntered, mouseBox, _ in
  448. if (isDisabled) {
  449. return
  450. }
  451. if (downEntered) {
  452. mouseBox.fillColor = KMDesignToken.shared.fill(withToken: "dropdown.m.bg.sel")
  453. boxLabel.textColor = KMDesignToken.shared.fill(withToken: "dropdown.m.mac-text.sel")
  454. guard let callback = self.downCallback else {
  455. return
  456. }
  457. callback(true, stringValue)
  458. } else {
  459. mouseBox.fillColor = KMDesignToken.shared.fill(withToken: "dropdown.m.bg.norm")
  460. boxLabel.textColor = KMDesignToken.shared.fill(withToken: "dropdown.m.mac-text.def")
  461. }
  462. }
  463. let idx = self.dataArr?.index(of: stringValue) ?? 0
  464. self.viewWillShow?(box, idx)
  465. }
  466. }