// // KMNPopDetailsViewController.swift // PDF Reader Pro // // Created by 丁林圭 on 2024/12/6. // import Cocoa import KMComponentLibrary typealias FontChangeAlighCallback = (_ alight:NSTextAlignment) -> () typealias ObjectChangeAlighCallback = (_ alight:ObjectAlignType) -> () class KMNPopDetailsViewController: KMNBaseViewController { public var detailPopType:DetailPopType = .detailNone { didSet { switch detailPopType { case .freeTextAlight : alightRightConstraint.constant = 4 alightJustifiedButton.isHidden = true justifiedButton.isHidden = true fontAlightView.layoutSubtreeIfNeeded() operationWidthConstraint.constant = fontAlightView.bounds.width operationHeightConstraint.constant = fontAlightView.bounds.height self.view.layoutSubtreeIfNeeded() contentBox.contentView = fontAlightView break case .contentEditAlight: alightRightConstraint.constant = 44 alightJustifiedButton.isHidden = false justifiedButton.isHidden = false fontAlightView.layoutSubtreeIfNeeded() operationWidthConstraint.constant = fontAlightView.bounds.width operationHeightConstraint.constant = fontAlightView.bounds.height self.view.layoutSubtreeIfNeeded() contentBox.contentView = fontAlightView break case .doubleObjectAlight: objectRightConstraint.constant = 4 objectAlightView.layoutSubtreeIfNeeded() objectAverageHorButton.isHidden = true objectAverageVerButton.isHidden = true averageHorButton.isHidden = true averageVerButton.isHidden = true operationWidthConstraint.constant = objectAlightView.bounds.width operationHeightConstraint.constant = objectAlightView.bounds.height self.view.layoutSubtreeIfNeeded() contentBox.contentView = objectAlightView break case .freeTextDoubleAlight: objectRightConstraint.constant = 4 objectAlightView.layoutSubtreeIfNeeded() objectAverageHorButton.isHidden = true objectAverageVerButton.isHidden = true averageHorButton.isHidden = true averageVerButton.isHidden = true operationWidthConstraint.constant = objectAlightView.bounds.width operationHeightConstraint.constant = objectAlightView.bounds.height self.view.layoutSubtreeIfNeeded() contentBox.contentView = objectAlightView break case .multpleObjectAlight: objectRightConstraint.constant = 80 objectAlightView.layoutSubtreeIfNeeded() objectAverageHorButton.isHidden = false objectAverageVerButton.isHidden = false averageHorButton.isHidden = false averageVerButton.isHidden = false operationWidthConstraint.constant = objectAlightView.bounds.width operationHeightConstraint.constant = objectAlightView.bounds.height self.view.layoutSubtreeIfNeeded() contentBox.contentView = objectAlightView break case .freeTextMultpleAlight: objectRightConstraint.constant = 80 objectAlightView.layoutSubtreeIfNeeded() objectAverageHorButton.isHidden = false objectAverageVerButton.isHidden = false averageHorButton.isHidden = false averageVerButton.isHidden = false operationWidthConstraint.constant = objectAlightView.bounds.width operationHeightConstraint.constant = objectAlightView.bounds.height self.view.layoutSubtreeIfNeeded() contentBox.contentView = objectAlightView break case .detailNone: break } } } public var fontAlight:NSTextAlignment = .left { didSet { if alightRightButton.properties.state == .pressed { alightRightButton.properties.state = .normal alightRightButton.reloadData() } if alightCenteButton.properties.state == .pressed { alightCenteButton.properties.state = .normal alightCenteButton.reloadData() } if alightJustifiedButton.properties.state == .pressed { alightJustifiedButton.properties.state = .normal alightJustifiedButton.reloadData() } if alightLeftButton.properties.state == .pressed { alightLeftButton.properties.state = .normal alightLeftButton.reloadData() } if fontAlight == .left { alightLeftButton.properties.state = .pressed alightLeftButton.reloadData() } else if fontAlight == .right { alightRightButton.properties.state = .pressed alightRightButton.reloadData() } else if fontAlight == .center { alightCenteButton.properties.state = .pressed alightCenteButton.reloadData() } else if fontAlight == .justified { alightJustifiedButton.properties.state = .pressed alightJustifiedButton.reloadData() } } } public var objectAlignType:ObjectAlignType = .alightLeft { didSet { if objectAlightLeftButton.properties.state == .pressed { objectAlightLeftButton.properties.state = .normal objectAlightLeftButton.reloadData() } if objectAlightRightButton.properties.state == .pressed { objectAlightRightButton.properties.state = .normal objectAlightRightButton.reloadData() } if objectAlightTopButton.properties.state == .pressed { objectAlightTopButton.properties.state = .normal objectAlightTopButton.reloadData() } if objectAlightHorButton.properties.state == .pressed { objectAlightHorButton.properties.state = .normal objectAlightHorButton.reloadData() } if objectAlightBottomButton.properties.state == .pressed { objectAlightBottomButton.properties.state = .normal objectAlightBottomButton.reloadData() } if objectAverageVerButton.properties.state == .pressed { objectAverageVerButton.properties.state = .normal objectAverageVerButton.reloadData() } if objectAverageHorButton.properties.state == .pressed { objectAverageHorButton.properties.state = .normal objectAverageHorButton.reloadData() } if objectAlightVerButton.properties.state == .pressed { objectAlightVerButton.properties.state = .normal objectAlightVerButton.reloadData() } var button:ComponentButton? = nil switch objectAlignType { case .alightLeft : button = objectAlightLeftButton break case .alightRight: button = objectAlightRightButton break case .alightTop: button = objectAlightTopButton break case .alightVer: button = objectAlightVerButton break case .alightHor: button = objectAlightHorButton break case .alightBottom: button = objectAlightBottomButton break case .averageVer: button = objectAverageVerButton break case .averageHor: button = objectAverageHorButton break case .alightNone: break } button?.properties.state = .pressed button?.reloadData() } } var fontChangeAlighCallback: FontChangeAlighCallback? var objectChangeAlighCallback: ObjectChangeAlighCallback? @IBOutlet weak var contentBox: NSBox! @IBOutlet weak var operationWidthConstraint: NSLayoutConstraint! @IBOutlet weak var operationHeightConstraint: NSLayoutConstraint! @IBOutlet var fontAlightView: NSView! @IBOutlet var alightLeftButton: ComponentButton! @IBOutlet var alightRightButton: ComponentButton! @IBOutlet var alightCenteButton: ComponentButton! @IBOutlet var alightJustifiedButton: ComponentButton! @IBOutlet var justifiedButton: NSButton! @IBOutlet weak var alightRightConstraint: NSLayoutConstraint! @IBOutlet var objectAlightView: NSView! @IBOutlet var objectAlightLeftButton: ComponentButton! @IBOutlet var objectAlightRightButton: ComponentButton! @IBOutlet var objectAlightTopButton: ComponentButton! @IBOutlet var objectAlightVerButton: ComponentButton! @IBOutlet var objectAlightHorButton: ComponentButton! @IBOutlet var objectAlightBottomButton: ComponentButton! @IBOutlet var objectAverageVerButton: ComponentButton! @IBOutlet var objectAverageHorButton: ComponentButton! @IBOutlet var averageVerButton: NSButton! @IBOutlet var averageHorButton: NSButton! @IBOutlet weak var objectRightConstraint: NSLayoutConstraint! override func viewDidLoad() { super.viewDidLoad() } override func initContentView() { super.initContentView() alightLeftButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameListViewPopAlightLeft")) alightRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameListViewPopAlightRight")) alightCenteButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameListViewPopAlightCenter")) alightJustifiedButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameListViewPopAlightJus")) objectAlightLeftButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameObjectPopAlightLeft")) objectAlightRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameObjectPopAlightRight")) objectAlightTopButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameObjectPopAlightTop")) objectAlightVerButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameObjectPopAlightVer")) objectAlightHorButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameObjectPopAlightHor")) objectAlightBottomButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameObjectPopAlightBottom")) objectAverageVerButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameObjecAlignAverageVer")) objectAverageHorButton.properties = ComponentButtonProperty(type: .text_gray, size: .s, state: .normal, onlyIcon: true, icon:NSImage(named: "KMNImageNameObjecAlignAverageHor")) } override func updateUIThemeColor() { super.updateUIThemeColor() contentBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/popup") contentBox.borderColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/3-default") } override func updateUILanguage() { super.updateUILanguage() } //MARK: - Action @IBAction func alightLeftButtonClicked(_ sender: NSButton) { fontAlight = .left fontChangeAlighCallback?(fontAlight) } @IBAction func alightRightButtonClicked(_ sender: NSButton) { fontAlight = .right fontChangeAlighCallback?(fontAlight) } @IBAction func alightCenterButtonClicked(_ sender: NSButton) { fontAlight = .center fontChangeAlighCallback?(fontAlight) } @IBAction func alightJustButtonClicked(_ sender: NSButton) { fontAlight = .justified fontChangeAlighCallback?(fontAlight) } @IBAction func objectAlightLeftClick(_ sender: NSButton) { objectAlignType = .alightLeft objectChangeAlighCallback?(objectAlignType) } @IBAction func objectAlightRightClick(_ sender: NSButton) { objectAlignType = .alightRight objectChangeAlighCallback?(objectAlignType) } @IBAction func objectAlightTopClick(_ sender: NSButton) { objectAlignType = .alightTop objectChangeAlighCallback?(objectAlignType) } @IBAction func objectAlightVerClick(_ sender: NSButton) { objectAlignType = .alightVer objectChangeAlighCallback?(objectAlignType) } @IBAction func objectAlightHorClick(_ sender: NSButton) { objectAlignType = .alightHor objectChangeAlighCallback?(objectAlignType) } @IBAction func objectAlightBottomClicked(_ sender: NSButton) { objectAlignType = .alightBottom objectChangeAlighCallback?(objectAlignType) } @IBAction func objectAverageVerClicked(_ sender: NSButton) { objectAlignType = .averageVer objectChangeAlighCallback?(objectAlignType) } @IBAction func objectAverageHorClicked(_ sender: NSButton) { objectAlignType = .averageHor objectChangeAlighCallback?(objectAlignType) } }