KMComboBox.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // KMComboBox.swift
  3. // PDF Master
  4. //
  5. // Created by wanjun on 2022/11/29.
  6. //
  7. import Cocoa
  8. enum KMComboBoxType : Int {
  9. case none = 0
  10. }
  11. class KMComboBox: NSComboBox {
  12. var comboxRect: CGRect = CGRect(x: 0, y: 0, width: 0, height: 0)
  13. var _type: KMComboBoxType = .none
  14. override func draw(_ dirtyRect: NSRect) {
  15. super.draw(dirtyRect)
  16. switch type {
  17. case .none:
  18. var p = comboxRect.origin
  19. p.x += comboxRect.width - 20
  20. p.y += (comboxRect.height - 16) / 2
  21. NSColor.clear.setFill()
  22. NSRect(x: p.x, y: 0, width: 16.0, height: comboxRect.height).fill()
  23. let image = NSImage(named: "KMImageNameUXIconBtnArrowDown")
  24. var rect = NSRect.zero
  25. rect.size = CGSize(width: 16.0, height: 16.0)
  26. image!.draw(in: NSRect(x: p.x, y: p.y, width: 16.0, height: 16.0), from: rect, operation: .sourceOver, fraction: 1.0, respectFlipped: true, hints: nil)
  27. default:
  28. break
  29. }
  30. }
  31. var type: KMComboBoxType {
  32. get {
  33. return _type
  34. }
  35. set {
  36. _type = newValue
  37. switch newValue {
  38. case .none:
  39. self.wantsLayer = true
  40. self.layer?.cornerRadius = 1.0
  41. self.layer?.borderWidth = 0.5
  42. self.layer?.borderColor = .black
  43. self.backgroundColor = .white
  44. self.isButtonBordered = false
  45. default:
  46. break
  47. }
  48. }
  49. }
  50. }