123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- //
- // KMHeaderFooterMarginInfoView.swift
- // Cisdem PDFMaster
- //
- // Created by tangchao on 2022/12/27.
- //
- import Cocoa
- class KMHeaderFooterMarginInfoView: KMHeaderFooterAdjectiveInfoBaseView {
-
- var topLabel = NSTextField(labelWithString: "")
- var topStepper = KMWatermarkAdjectiveStepper()
- var bottomLabel = NSTextField(labelWithString: "")
- var bottomStepper = KMWatermarkAdjectiveStepper()
- var leftLabel = NSTextField(labelWithString: "")
- var leftStepper = KMWatermarkAdjectiveStepper()
- var rightLabel = NSTextField(labelWithString: "")
- var rightStepper = KMWatermarkAdjectiveStepper()
- override func initSubviews() {
- super.initSubviews()
-
- self.addSubview(self.topLabel)
- self.addSubview(self.topStepper)
- self.addSubview(self.bottomLabel)
- self.addSubview(self.bottomStepper)
- self.addSubview(self.leftLabel)
- self.addSubview(self.leftStepper)
- self.addSubview(self.rightLabel)
- self.addSubview(self.rightStepper)
-
- self.titleLabel.stringValue = NSLocalizedString("Margin(mm)", comment: "")
- self.topLabel.stringValue = NSLocalizedString("", comment: "")
- self.bottomLabel.stringValue = NSLocalizedString("", comment: "")
- self.leftLabel.stringValue = NSLocalizedString("", comment: "")
- self.rightLabel.stringValue = NSLocalizedString("", comment: "")
-
- for label in [self.topLabel, self.bottomLabel, self.leftLabel, self.rightLabel] {
- label.alignment = .center
- }
-
- for stepper in [self.topStepper, self.bottomStepper, self.leftStepper, self.rightStepper] {
- stepper.wantsLayer = true
- stepper.layer?.borderWidth = 1
- stepper.layer?.borderColor = NSColor.black.cgColor
- }
-
- self.topStepper.valueDidChange = {
- (value: Double) in
-
- guard let callback = self.itemClick else {
- return
- }
-
- callback(1, value)
- }
- self.bottomStepper.valueDidChange = {
- (value: Double) in
-
- guard let callback = self.itemClick else {
- return
- }
-
- callback(2, value)
- }
- self.leftStepper.valueDidChange = {
- (value: Double) in
-
- guard let callback = self.itemClick else {
- return
- }
-
- callback(3, value)
- }
- self.rightStepper.valueDidChange = {
- (value: Double) in
-
- guard let callback = self.itemClick else {
- return
- }
-
- callback(4, value)
- }
- }
-
- override func layout() {
- super.layout()
-
- let width: CGFloat = NSWidth(self.bounds)
-
- let leftMargin = self.contentInset.left
- let topY = self.titleLabel.frame.maxY + 10
-
- let stepperSize: NSSize = NSMakeSize(60, 32)
- let labelSize: NSSize = NSMakeSize(32, 20)
-
- self.topLabel.frame = NSMakeRect(leftMargin-8, topY+8, labelSize.width, labelSize.height)
- self.topStepper.frame = NSMakeRect(self.topLabel.frame.maxX, topY, stepperSize.width, stepperSize.height)
-
- let rightLabelX: CGFloat = width-self.contentInset.right-stepperSize.width-10-labelSize.width
- self.bottomLabel.frame = NSMakeRect(rightLabelX, topY+8, labelSize.width, labelSize.height)
- self.bottomStepper.frame = NSMakeRect(self.bottomLabel.frame.maxX, topY, stepperSize.width, stepperSize.height)
-
- self.leftLabel.frame = NSMakeRect(leftMargin-8, self.topStepper.frame.maxY+18, labelSize.width, labelSize.height)
- self.leftStepper.frame = NSMakeRect(self.topLabel.frame.maxX, self.topStepper.frame.maxY+18, stepperSize.width, stepperSize.height)
-
- self.rightLabel.frame = NSMakeRect(rightLabelX, self.topStepper.frame.maxY+18, labelSize.width, labelSize.height)
- self.rightStepper.frame = NSMakeRect(self.rightLabel.frame.maxX, self.topStepper.frame.maxY+18, stepperSize.width, stepperSize.height)
-
- }
-
- override var model: KMHeaderFooterAdjectiveModel {
- get {
- return super.model
- }
- set {
- super.model = newValue
-
- self.topStepper.value = Double(newValue.topMargin)
- self.bottomStepper.value = Double(newValue.bottomMargin)
- self.leftStepper.value = Double(newValue.leftMargin)
- self.rightStepper.value = Double(newValue.rightMargin)
- }
- }
-
- }
|