123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- //
- // ProgressVC.swift
- // KMComponentLibrary
- //
- // Created by Niehaoyu on 2024/9/6.
- //
- import Cocoa
- import KMComponentLibrary
- class ProgressVC: NSViewController {
- @IBOutlet weak var progressCircle: ComponentProgressCircle!
- @IBOutlet weak var circleSizeBox: NSComboBox!
- @IBOutlet weak var circleTypeBox: NSComboBox!
- @IBOutlet weak var itemWidthConst: NSLayoutConstraint!
- @IBOutlet weak var itemHeightConst: NSLayoutConstraint!
-
- @IBOutlet weak var progressLine: ComponentProgressLine!
- @IBOutlet weak var lineTypeBox: NSComboBox!
-
- @IBOutlet weak var progressPopup: ComponentProgressPopup!
-
- var progressTimer: Timer?
-
-
- var progressPopupWC: ComponentProgressWindowController = ComponentProgressWindowController.windowController()
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- self.circleSizeBox.selectItem(at: 0)
- self.circleTypeBox.selectItem(at: 0)
- self.lineTypeBox.selectItem(at: 0)
-
- self.reloadData()
-
- }
-
- func reloadData() {
-
- var size: ComponentSize = .m
- if self.circleSizeBox.indexOfSelectedItem == 1 {
- size = .s
- }
-
- var circleType: componentProgressSubType = .circle_Waiting
- if self.circleTypeBox.indexOfSelectedItem == 0 {
-
- } else if self.circleTypeBox.indexOfSelectedItem == 1 {
- circleType = .circle_ProgressPercent
- } else if self.circleTypeBox.indexOfSelectedItem == 2 {
- circleType = .circle_ErrorPercent
- } else if self.circleTypeBox.indexOfSelectedItem == 3 {
- circleType = .circle_ProgressNoPercent
- } else if self.circleTypeBox.indexOfSelectedItem == 4 {
- circleType = .circle_ErrorNoPercent
- } else if self.circleTypeBox.indexOfSelectedItem == 5 {
- circleType = .circle_Success
- }
-
- //progressItem
- let properties: ComponentProgressProperty = ComponentProgressProperty.init(size: size, progressType: .circle, subType: circleType, progress: 0)
- self.progressCircle.properties = properties
- itemWidthConst.constant = properties.propertyInfo.viewWidth
- itemHeightConst.constant = properties.propertyInfo.viewHeight
-
- if (progressTimer != nil) {
- progressTimer?.invalidate()
- progressTimer = nil
- }
-
- if circleType == .circle_ProgressPercent ||
- circleType == .circle_ErrorPercent {
- self.progressTimer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(progressTimerAction), userInfo: nil, repeats: true)
- }
-
- //Progress Line
- var lineType: componentProgressSubType = .line_Progressing
- var lineProgress: CGFloat = 0
- if self.lineTypeBox.indexOfSelectedItem == 0 {
-
- } else if self.lineTypeBox.indexOfSelectedItem == 1 {
- lineType = .line_Error
- lineProgress = 1
- } else if self.lineTypeBox.indexOfSelectedItem == 2 {
- lineType = .line_Success
- lineProgress = 1
- }
-
- let lineProperties: ComponentProgressProperty = ComponentProgressProperty.init(size: size, progressType: .line, subType: lineType, progress: lineProgress)
- self.progressLine.properties = lineProperties
- if lineType == .line_Progressing {
- self.progressTimer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(progressTimerAction), userInfo: nil, repeats: true)
- }
-
- //Progress PopupLine
- let popUpProperties: ComponentProgressProperty = ComponentProgressProperty.init(size: size, progressType: .popup, subType: .popup_Line, progress: 0, titleString: "Progressing")
- self.progressPopup.properties = popUpProperties
-
- //Progress Popup
- let popUpProgressProperties: ComponentProgressProperty = ComponentProgressProperty.init(size: size, progressType: .popup, subType: .popup_Circle, progress: 0, cancelString: "Cancel")
- self.progressPopupWC.properties = popUpProgressProperties
- }
-
- @IBAction func boxAction(_ sender: Any) {
- self.reloadData()
- }
-
- @IBAction func showProgressPopup(_ sender: Any) {
- progressPopupWC.showWindow(nil)
- }
-
- @objc func progressTimerAction() {
-
- if self.progressCircle.properties.progressSubType == .circle_ProgressPercent ||
- self.progressCircle.properties.progressSubType == .circle_ErrorPercent {
-
- self.progressCircle.properties.progress += 0.01
- if self.progressCircle.properties.progress >= 1 {
- self.progressCircle.properties.progress = 0
- }
- self.progressCircle.reloadData()
-
- }
-
- if self.progressLine.properties.progressSubType == .line_Progressing {
- self.progressLine.properties.progress += 0.01
- if self.progressLine.properties.progress >= 1 {
- self.progressLine.properties.progress = 0
- }
- self.progressLine.reloadData()
-
- }
-
- self.progressPopup.properties.progress += 0.01
- if self.progressPopup.properties.progress >= 1 {
- self.progressPopup.properties.progress = 0
- }
- self.progressPopup.reloadData()
-
- self.progressPopupWC.properties.progress += 0.01
- if self.progressPopupWC.properties.progress >= 1 {
- self.progressPopupWC.properties.progress = 0
- }
- self.progressPopupWC.reloadData()
-
- }
-
- }
|