1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // KMPageEditInsertDirectionItemView.swift
- // PDF Master
- //
- // Created by tangchao on 2023/1/11.
- //
- import Cocoa
- class KMPageEditInsertDirectionItemView: KMPageEditBaseItemView {
- private lazy var horRadio: NSButton = {
- let button = NSButton(radioButtonWithTitle: NSLocalizedString("Horizontal page", comment: ""), target: self, action: #selector(radioButtonAction))
- return button
- }()
- private lazy var verRadio: NSButton = {
- let button = NSButton(radioButtonWithTitle: NSLocalizedString("Vertical pages", comment: ""), target: self, action: #selector(radioButtonAction))
- return button
- }()
-
- override func initSubviews() {
- super.initSubviews()
-
- self.addSubview(self.horRadio)
- self.addSubview(self.verRadio)
-
- self.titleLabel.stringValue = NSLocalizedString("Direction", comment: "")
-
- self.horRadio.state = .off
- self.verRadio.state = .on
- }
-
- override func layout() {
- super.layout()
-
- let raidoY: CGFloat = self.titleLabel.frame.maxY+12
- let radioSize = NSSize(width: 120, height: 22)
- self.verRadio.frame = NSMakeRect(self.contentInset.left, raidoY, radioSize.width, radioSize.height)
-
- self.horRadio.frame = NSMakeRect(self.horRadio.frame.maxX,raidoY , radioSize.width, radioSize.height)
- }
-
- @objc func radioButtonAction(sender: NSButton) {
- for radio in [self.horRadio, self.verRadio] {
- if (radio.isEqual(to: sender)) {
- radio.state = .on
- } else {
- radio.state = .off
- }
- }
-
- guard let callback = self.itemClick else {
- return
- }
-
- var index: Int = 0
- if (sender == self.horRadio) {
- index = 1
- } else if (sender == self.verRadio) {
- index = 2
- }
- if (index > 0) {
- callback(index, "")
- }
- }
-
- public func switchDirection(isHor: Bool) {
- for radio in [self.horRadio, self.verRadio] {
- radio.state = .off
- }
-
- if (isHor) {
- self.horRadio.state = .on
- } else {
- self.verRadio.state = .on
- }
- }
-
- public func getDirection() -> Int {
- if (self.horRadio.state == .on) {
- return 1
- }
-
- return 0
- }
- }
|