|
@@ -17,7 +17,6 @@ import AppKit
|
|
|
public class ComponentCPosition: ComponentBaseXibView {
|
|
|
|
|
|
@IBOutlet var contendBox: NSBox!
|
|
|
- @IBOutlet var itemBox: NSBox!
|
|
|
|
|
|
// MARK: Private Property
|
|
|
private var _properties : ComponentCPositionProperty = ComponentCPositionProperty()
|
|
@@ -44,7 +43,7 @@ public class ComponentCPosition: ComponentBaseXibView {
|
|
|
var lineYValue: CGFloat = 0
|
|
|
var lineXValue: CGFloat = 0
|
|
|
if rows > 1 {
|
|
|
- for row in 1...rows-1 {
|
|
|
+ for _ in 1...rows-1 {
|
|
|
lineYValue += lineWidth
|
|
|
lineYValue += rowHeight
|
|
|
|
|
@@ -63,7 +62,7 @@ public class ComponentCPosition: ComponentBaseXibView {
|
|
|
}
|
|
|
|
|
|
if columns > 1 {
|
|
|
- for column in 1...columns-1 {
|
|
|
+ for _ in 1...columns-1 {
|
|
|
lineXValue += lineWidth
|
|
|
lineXValue += columnWidth
|
|
|
|
|
@@ -99,11 +98,7 @@ public class ComponentCPosition: ComponentBaseXibView {
|
|
|
|
|
|
public override func awakeFromNib() {
|
|
|
super.awakeFromNib()
|
|
|
-
|
|
|
- contendBox.fillColor = NSColor.clear
|
|
|
-
|
|
|
- itemBox.borderWidth = 0
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// MARK: - Set & Get
|
|
@@ -116,38 +111,57 @@ public class ComponentCPosition: ComponentBaseXibView {
|
|
|
|
|
|
ComponentLibrary.shared.configCPositionComponent(properties: _properties)
|
|
|
|
|
|
- reloadData()
|
|
|
-
|
|
|
+ resetData()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//MARK: - SetupUI
|
|
|
func setupUI() {
|
|
|
+
|
|
|
+ self.wantsLayer = true
|
|
|
+ layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorFill-nor").cgColor
|
|
|
+ layer?.borderWidth = properties.propertyInfo.borderWidth
|
|
|
+ layer?.cornerRadius = properties.propertyInfo.cornerRadius
|
|
|
+ layer?.borderColor = properties.propertyInfo.borderColor_nor.cgColor
|
|
|
|
|
|
- contendBox.borderWidth = properties.propertyInfo.borderWidth
|
|
|
- contendBox.cornerRadius = properties.propertyInfo.cornerRadius
|
|
|
- contendBox.borderColor = properties.propertyInfo.borderColor_nor
|
|
|
-
|
|
|
- itemBox.fillColor = properties.propertyInfo.itemFillColor
|
|
|
-
|
|
|
- if properties.selColumn >= 0 && properties.selRow >= 0 {
|
|
|
- var itemRect = itemBox.frame
|
|
|
- itemRect.origin.x = CGFloat(properties.selColumn) * itemWidth + CGFloat(properties.selColumn)
|
|
|
- itemRect.origin.y = CGFloat(properties.selRow) * itemHeight + CGFloat(properties.selRow)
|
|
|
- itemRect.size.width = itemWidth
|
|
|
- itemRect.size.height = itemHeight
|
|
|
- itemBox.frame = itemRect
|
|
|
- } else {
|
|
|
- itemBox.frame = CGRectZero
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- public func reloadData() {
|
|
|
+ func resetData() {
|
|
|
let rows = properties.rowCount
|
|
|
let columns = properties.columnCount
|
|
|
|
|
|
- itemHeight = (bounds.size.height-CGFloat(rows)-1)/CGFloat(rows)
|
|
|
- itemWidth = (bounds.size.width-CGFloat(columns)-1)/CGFloat(columns)
|
|
|
+ itemHeight = (bounds.size.height-CGFloat(rows)+1)/CGFloat(rows)
|
|
|
+ itemWidth = (bounds.size.width-CGFloat(columns)+1)/CGFloat(columns)
|
|
|
+
|
|
|
+ if let subviews = contendBox.contentView?.subviews {
|
|
|
+ for view in subviews {
|
|
|
+ if view is ComponentCPositionItem {
|
|
|
+ view.removeFromSuperview()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for row in 0...properties.rowCount-1 {
|
|
|
+ var xValue: CGFloat = 1
|
|
|
+ for column in 0...properties.columnCount-1 {
|
|
|
+ var yValue: CGFloat = 1
|
|
|
+
|
|
|
+ let item = ComponentCPositionItem()
|
|
|
+ item.frame = CGRectMake(xValue + CGFloat(column)*itemWidth, CGFloat(row)*itemHeight + yValue, itemWidth, itemHeight)
|
|
|
+ item.row = row
|
|
|
+ item.column = column
|
|
|
+ item.state = .normal
|
|
|
+ item.infoString = ""
|
|
|
+ item.isDisabled = properties.isDisabled
|
|
|
+ item.delegate = self
|
|
|
+ item.autoresizingMask = [.maxXMargin, .maxYMargin]
|
|
|
+
|
|
|
+ contendBox.contentView?.addSubview(item)
|
|
|
+
|
|
|
+ xValue += 1
|
|
|
+ yValue += 1
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
display()
|
|
|
|
|
@@ -155,6 +169,39 @@ public class ComponentCPosition: ComponentBaseXibView {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public func reloadData() {
|
|
|
+ if let subviews = contendBox.contentView?.subviews {
|
|
|
+ for view in subviews {
|
|
|
+ if view is ComponentCPositionItem {
|
|
|
+ let item = view as! ComponentCPositionItem
|
|
|
+ if item.row == properties.selRow && item.column == properties.selColumn {
|
|
|
+ item.state = .pressed
|
|
|
+ } else {
|
|
|
+ item.state = .normal
|
|
|
+ }
|
|
|
+ item.reloadData()
|
|
|
+
|
|
|
+ item.refresh()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public func setString(_ string: String, to row: Int, _ column: Int) {
|
|
|
+ if let subviews = contendBox.contentView?.subviews {
|
|
|
+ for view in subviews {
|
|
|
+ if view is ComponentCPositionItem {
|
|
|
+ let item = view as! ComponentCPositionItem
|
|
|
+
|
|
|
+ if item.row == row && item.column == column {
|
|
|
+ item.infoString = string
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//MARK: - MouseEvent
|
|
|
public override func mouseEntered(with event: NSEvent) {
|
|
|
super.mouseEntered(with: event)
|
|
@@ -173,18 +220,7 @@ public class ComponentCPosition: ComponentBaseXibView {
|
|
|
|
|
|
public override func mouseDown(with event: NSEvent) {
|
|
|
super.mouseDown(with: event)
|
|
|
-
|
|
|
- if properties.isDisabled == false {
|
|
|
- let point = convert(event.locationInWindow, from: nil)
|
|
|
-
|
|
|
- let widthCount = floor(point.x / itemWidth)
|
|
|
- let heightCount = floor(point.y / itemHeight)
|
|
|
-
|
|
|
- properties.selRow = Int(heightCount)
|
|
|
- properties.selColumn = Int(widthCount)
|
|
|
-
|
|
|
- setupUI()
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public override func mouseUp(with event: NSEvent) {
|
|
@@ -196,3 +232,26 @@ public class ComponentCPosition: ComponentBaseXibView {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+extension ComponentCPosition: ComponentCPositionItemDelegate {
|
|
|
+ public func componentCPositionItemDidChoose(_ view: ComponentCPositionItem) {
|
|
|
+
|
|
|
+ if let subviews = contendBox.contentView?.subviews {
|
|
|
+ for subview in subviews {
|
|
|
+ if subview is ComponentCPositionItem {
|
|
|
+ let item = subview as! ComponentCPositionItem
|
|
|
+ if item != view {
|
|
|
+ item.state = .normal
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if properties.isDisabled == false {
|
|
|
+ properties.selRow = view.row
|
|
|
+ properties.selColumn = view.column
|
|
|
+
|
|
|
+ delegate?.componentCPositionDidChoose?(self, properties.selRow, properties.selColumn)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|