12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- //
- // KMBatesPageInfoView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2022/12/28.
- //
- import Cocoa
- class KMBatesPageInfoView: KMHeaderFooterAdjectiveInfoBaseView {
- var leftLabel = NSTextField(labelWithString: "")
- var leftStepper = KMWatermarkAdjectiveStepper()
- private var rigthLabel = NSTextField(labelWithString: "")
- var rightComboBox = NSComboBox()
-
- override func initSubviews() {
- super.initSubviews()
-
- self.addSubview(self.leftLabel)
- self.addSubview(self.leftStepper)
- self.addSubview(self.rigthLabel)
- self.addSubview(self.rightComboBox)
-
- self.titleLabel.isHidden = true
- self.leftLabel.stringValue = NSLocalizedString("Numbers of Digits:", comment: "")
- self.rigthLabel.stringValue = NSLocalizedString("Start Page:", comment: "")
-
- self.leftStepper.wantsLayer = true
- self.leftStepper.layer?.borderWidth = 1
- self.leftStepper.layer?.borderColor = NSColor.black.cgColor
- self.leftStepper.stepper.minValue = 1
- self.leftStepper.stepper.maxValue = 99
- self.leftStepper.valueDidChange = {
- (value: Double) in
-
- guard let callback = self.itemClick else {
- return
- }
-
- callback(1, value)
- }
-
- self.rightComboBox.isEditable = false
- self.rightComboBox.delegate = self
- }
-
- override func layout() {
- super.layout()
-
- let width: CGFloat = NSWidth(self.bounds)
- let hSpace: CGFloat = 10
-
- let leftMargin = self.contentInset.left
- let labelWidth: CGFloat = (width-leftMargin*2-hSpace)*0.5
- let labelHeight: CGFloat = 16
- self.leftLabel.frame = NSMakeRect(leftMargin, 0, labelWidth, labelHeight)
- self.rigthLabel.frame = NSMakeRect(self.rigthLabel.frame.maxX+hSpace, 0, labelWidth, labelHeight)
-
- let comboBoxY: CGFloat = self.leftLabel.frame.maxY+6
- let comboBoxSize: NSSize = NSMakeSize(labelWidth, 22)
- self.leftStepper.frame = NSMakeRect(leftMargin, comboBoxY, comboBoxSize.width, 30)
- self.rightComboBox.frame = NSMakeRect(self.leftStepper.frame.maxX+hSpace, comboBoxY, comboBoxSize.width, comboBoxSize.height)
- }
-
- override var model: KMHeaderFooterAdjectiveModel {
- get {
- super.model
- }
- set {
- super.model = newValue
- }
- }
- }
- extension KMBatesPageInfoView: NSComboBoxDelegate {
- func comboBoxSelectionDidChange(_ notification: Notification) {
- if (self.rightComboBox.isEqual(to: notification.object)) {
- guard let callback = self.itemClick else {
- return
- }
-
- var index: Int = self.rightComboBox.indexOfSelectedItem
- if (index < 0) {
- index = 0
- }
-
- callback(2, index)
- }
- }
- }
|